Quantcast
Channel: Windows PowerShell forum
Viewing all 21975 articles
Browse latest View live

Cannot convert 'System.Object[]' to the type 'System.Nullable'1[System.Boolean\' required by parameter 'Enabled'

$
0
0

Hi all, extremely new to powershell. I am getting the error "Cannot convert 'System.Object[]' to the type 'System.Nullable'1[System.Boolean\' required by parameter 'Enabled'" when I call a function.

Function Disable-InactiveComputer { $iComputers = Get-ADComputer -Filter {(LastLogonDate -le $disableD) -and (PasswordLastSet -le $disableD)} -SearchBase $desktopOU -Properties * | ?{$_.LastLogonDate -ne $null} $filePath2 = Get-Date -uformat ($folderPath + "Computer_Account_Disabled_on_%d%m%Y.csv") if ($iComputers){ Foreach($iComputer in $iComputers){ Set-ADComputer -Enabled $false, -Description "Auto Disabled on $(Get-Date -format 'D')" ` | Move-ADObject -TargetPath $disabledOU -PassThru ` $cpt = Get-ADComputer $($iComputer.Name) -properties * | Sort-Object LastLogonDate -descending $props = @{ ‘ComputerName’=$cpt.Name; ‘Description’=$cpt.Description; ‘OSVersion’=$cpt.OperatingSystem; ‘SPVersion’=$cpt.OperatingSystemServicePack; ‘LastLogonDate’=$cpt.LastLogonDate} $obj = New-Object -TypeName PSObject -Property $props $tobj += $obj } $tobj | Select-Object ComputerName, Description, OSVersion, SPVersion, LastLogonDate | Sort-Object Name | Export-Csv $filePath2 -NoTypeInformation } }

The variables are:

$folderPath = "$env:WINDIR\Temp\"
$idays = 360
$ddays = 720
$disableD = (Get-Date).AddDays(-($idays))
$deleteD = (Get-Date).AddDays(-($ddays))
$desktopOU = "OU=DistinguishedName,DC=test,DC=com"
$disabledOU = "OU=DistinghuishedName,DC=test,DC=com"
$tobj = @()

The .csv file gets created with the correct file name, in the correct location, but the computer object doesn't get disabled, does not set the description, and it does not get moved to $disableDOU

I'd very much appreciate any assistance, thank you.



Plase help to check script Power Shell for check status Replication Domain

$
0
0

I Need

1. Run script by Schedule Task daily

2. Automatic Send mail to My group

3.Need to report follow with my image  

I need to use power shell can run check status replication between DC with additional and has automate send email to my group IT

Resource :
Windows 2008 =DC
windows 2008= Additional DC
windows2003= Additional DC e-mail server = smtp port:2525


I follow step this link http://technodrone.blogspot.com/2010...atus-with.html

$from = "Replication Status<Domain@mail.com>"
$to = "User Group<Domain@mail.com>"
#Collect the replication info

#Check the Replication with Repadmin
$workfile =C:\rep\repadmin.exe /showrepl * /errorsonly >csv

$results = ConvertFrom-Csv -InputObject $workfile | where {$_.'Number of Failures' -ge 1}
$strOutFile = "C:\rep\Check-Replication.htm"

#Here you set the tolerance level for the report
$results = $workfile | where {$_.'Number of Failures' -gt 1 }

if ($results -ne $null ) {
$results = $results | select "Source DC", "Naming Context", "Destination DC" ,"Number of Failures", "Last Failure Time", "Last Success Time", "Last Failure Status" | ConvertTo-Html
} else {
$results = "There were no Replication Errors"
}
#Send-MailMessage -From $from -To $to -Subject "Daily Forest Replication Status" -SmtpServer "smtp.domain.com" -BodyAsHtml ($results | Out-String)

$filedate = get-date
$filedate = $filedate.ToString()

$results = "" + $filedate + "" + $results + ""
$results | Out-File $strOutFile 

Run a form in multiple copies

$
0
0
I created a form by using powershell script. Is it possible to run it in multiple copies at the same time? Thanks.

Build numbers for powershell.exe vs. PowerShell version

$
0
0

Hi!

I'm looking for information about powershell.exe file build number or version than can allow mi determine installed PowerShell version on remote hosts.

Currently I must determine installed version on a lot of servers that I can only get information about files versions. It is in the secure envinroment that some ports are filtered. On server is installed Windows Server 2003 (R2) or Windows Sever 2008 R2 - some have PowerShell installed but not all.

Thank you in advance.


Wojciech Sciesinski

Office Web App > Calendar > Limit 5 calendar

$
0
0

Hello,

I have 7trucks.
A schedulefor each truckinOfficeWeb App.
I want to displaymy 7calendarssimultaneouslyinOWA.
But there isa limitto display only 5calendars.
How toskip thislimit?

Do you know ofapowershellsolution?

Thanks,

nico


Message du forum Microsoft

Implicit Remoting Questions

$
0
0

I've been reading up about implicit remoting, and have followed through some of the guides for using this. I've still got some things im not sure about though.

How do i ensure that i am not prompted for credentials when i later want to use exported commands?  I've exported commands from a session that i started with credssp and credential parameters, but still get prompted.  I want to use these commands in a script

Also, how do i use exported commands against more than one server?  e.g. I export a single servers sharepoint powershell commands.  I have multiple sharepoint servers that i would want to manage implicitly. 

cheers,

Tim











Help with error: Unexpected token in expression or statement

$
0
0

Hi,

For days the following line in my code worked, with all variables containing valid data.  Im just concatenting variables:

$strADMTIncludeFile1 = $strADMTIncludeFile$strDateTime$strTxtFileXtension

Now I get the following error.  Any ideas as to why?

Unexpected token 'strDateTime' in expression or statement.
At C:\MigrateSIDHistory.ps1:74 char:55
+ $strADMTIncludeFile1 = $strADMTIncludeFile$strDateTime <<<< $strTxtFileXtension
    + CategoryInfo          : ParserError: (strDateTime:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

Thanks in advance.


MTV99

Inventory computer

$
0
0

Hello,

I have a scriptthat canmake an inventory ofcomputers and put in excel,onnec vl370no problemeverything worksonlenovo,if I want to knowthe typeof processor and thehard disk capacity:

Get-WmiObject: Request not valid At line: 1 char: 5+ Gwmi <<<< Win32_Processor 300-01     + CategoryInfo: InvalidOperation: (:) [Get-WmiObject], ManagementException     + FullyQualifiedErrorId: GetWMIManagementException, Microsoft.PowerShell.Commands.GetWmiObjectCommand

Same error from win32_logicaldisk


Powershell invoked from c# is not listing all the files

$
0
0

Hi,

I'm trying to use lpr.exe which is available under %systemroot%.

I manually launch powershell  and cd to %systemroot% --> ls lp* --> it will list all the lpr.exe and associated files.

But, when I launch powershell through c# Process.Start --> a new powershell windows gets opened--> Cd to %systemroot% --> ls lp* -- its not listing the lpr.exe.

Please let me know If any one has come across this.

Thanks in advance

Powershell v2.0: run a Script to create AD-Users with elevated permissions

$
0
0

Hi,

i've written a script to create AD-Users (bulk import form csv), now I want to provide this script to our 1st lvl support, so they can use it.

Due to the fact that 1st has no permissions to manage the AD, I want to integrate "run as" into the script. How can I do this?

And How can I encrypt this, so that no one can see the code?

I would be great to get something that works like an *.exe file.

Kind Regards


..next time we eat bacon

Testing Web Services + XML

$
0
0

Hello,

Beginer in powershell.. I'm just trying to send a XML parameter to a web service and getting an error...

Is it possible ??

Script:

#Web Service
$Uri = "http://siteweb/webservice.svc?WSDL"

#Path Xml
$XmlPath = "C:\xml\test2.xml"

#Xml parameters
$Xml = new-object System.Xml.XmlDocument
$Xml = [xml](get-content C:\xml\test2.xml)

#Web Service
$WebService = New-WebServiceProxy -Uri $Uri
$Response = $WebService.GetTopOrderedProducts($Xml)
$Response

Error :

Cannot convert argument "request", with value: "System.Xml.XmlDocument", for "GetTopOrderedProducts" to type 
"Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1ices_MarketingService_svc_WSDL.GetTopOrderedProductsRequest": "Cannot convert the 
"System.Xml.XmlDocument" value of type "System.Xml.XmlDocument" to type 
"Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1ices_MarketingService_svc_WSDL.GetTopOrderedProductsRequest"."
At D:\Exploit\WebServices\test.ps1:14 char:1
+ $Response = $WebService.GetTopOrderedProducts($Xml)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

If anyone can help me... thank you !!

Jeremy


Get-WinEvent with non-administrative user

$
0
0

he idea here is to give a group of users in a help desk situation the ability to use a powershell script to quickly find out the source of account lockouts. The script is working wonderfully as myself, but a non-privileged user cannot run it.

I've provided access to the "Event Log Readers" group and confirmed a test user can remotely view the event log with eventvwr, but the following command still will not run successfully

Any thoughts?

Get-WinEvent -ComputerName dc01 -FilterHashtable @{logname='security'; id=4771} -ErrorAction Stop

The error is "Get-WinEvent: Could not retrieve information about the Security log. Error: attempted to perform an unauthorized operation."

Again, I can run this exact same command with an elevated account and it works, so I know it is permissions. The problem is finding which.

I've confirmed that logging into the server with the test account and running the command directly on the server still doesn't work--same error.

Environment Variable

$
0
0

I'm trying to solve another problem related to login scripts in DC, using a .vbs program but i'm stuch in another problem that is:

Code:

Set objShell = wscript.createobject("wscript.shell")

objShell.Run("here it call another .vbs that set some VOLATILE variables and needs to be VOLATILE")

objShell.Run("here I call my exe that needs the variables that was set by the previous command")

problem: when I call me exe it didn't "see" the variables, but if I run the .vbs by the second time it works because now it sees the variables. Already put a stop between objShell.Run to check if the problem was the time and wait 1 minute and didn't works.

Invoking Powershell modules on remote clients via package/command line

$
0
0

Hello Everyone -

I have two modules(functions) that i've written and tested successfully locally in my environment that give me Uninstall and Repair functionality on whatever the string contains. Both .psm1's are delivered via a SCCM pkg that lands both into folders in the Modules directory. My issue is I can't seem to invoke this in a deployment scenario...as i'd like to deliver the "Invoke-command" using SCCM's command line to simply say...

Invoke-Command -scriptblock { Do-This "<string>" }

The above command works fine locally when...(exePol is set to Bypass).
1.)Modules have respective folders living in WindowsPowershell\Modules directory named xxxx.psm1
2.)Import-Module -name <path\name of module>
3.)Verify Modules are loaded(moduleType is script)

But when fabricating the folders\files above with SCCM, and running the Invoke-Command(in many different ways remotely), i recieve the cmdlet, program doesn't exist and has no idea what i'm talking about. Folders\Files for .psm1's are present and do show when running Get-Module -Listavailable locally on targeted clients.

Maybe this is related to the Import-Module command and the context i'm trying to delivery it in?
I've tried multiple scenario's of...

A.) Psexec that launches powershell, followed by the Import-Module -name <path\name of module>
B.) .Bat file that launches powershell with the same Import-Module syntax
C.) PS1 that includes the same Import-Module line.
D.) Just straight from the command line of the Pkg/Program.

Has anyone tried this? Is there a better method when trying to deliver invoke-command on a module/function to a client via SCCM? 

TIA 

Get-ADuser and formatting results

$
0
0

What Im looking to do is to output all of my AD Users, including all of their properties, and then output that to a tabular format. The issue I am having is that some of the fields, like MemberOf, dont come through. My script looks like the following:

Get-ADuser -Filter * -Properties * | Export-CSV C:\Temp\MyFile.csv

This is almost what I want, but I just need for all of the properties to be expanded. Some end in "..." meaning there is more to be shown, and others such as "MemberOf" show "Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" instead of showing the actual groups.

Thanks in advance for any help!


Jarrod Sturdivant jarrod.sturdivant@hotmail.com


Remove whitespace from AD user name to fix IOS7 reboot issue

$
0
0

We opened a case with Apple premier support regarding an issue where IOS7 devices would reboot for no apparent reason.  After sending them logs they determined it was because of  an extra space in the display name of any user that was in a meeting. Here is there official statement:  "After isolating the cause down to that particular user, I was then able to create a single occurrence event including only that user and my test account and confirmed by removing and re-adding that user that the issue only occurred when he was present on the event. The only issue that I see with the user information is that there is a space between "Mark" and the second comma in the name passed to the device by Exchange. Most likely, this is causing issues when the device is attempting to use the name to generate a short name to display in the Attendee list. Since the short name is new to iOS 7, that would explain why the issue did not start until iOS 7 was released."

This was the display name causing the issue:  

Smith, Mark , M.D.  <-- notice the space between the second comma

Can someone help me with a script to identify (and fix it possible) all of these users with this extra whitespace in their name?  We have over 30,000 AD accounts so Im sure there are many like this.

Any help is greatly appreciated.


Rich

Modify alias output to remove part of name

$
0
0

I'd like to have assistance with removing characters from an alias when calling the alias to create a file.

Alias: $URL_FILE = C:\Directory\Output

Alias: $URL = http://sitename.com

Script collects some data that is being piped into a file;
previous collection | Add-Content $URL_FILE-$URL

The script  errors when attempting to create the file since the name would contain "http://". I would like to know how I can create the file, while calling $URL, but with removing the "http://" portion of the $URL alias.

Thank you in advance.




PowerShell Newbie Help - Hiding an error message

$
0
0

Hi Guys

Hope you can help! I am not great with PowerShell just yet, getting to grips slowly but am stuck on something simple, even after some searching.

So I have a script something like this;

$taskcheck = schtasks /tn "Scheduled Task"
IF($taskcheck)
{
Write-Host "Already Exists!"
}
Else
{
Write-Host "Doesn't Exist, Creating"
}

So if the task name does exist, it works great. However, when the task doesn't exist, it throws this messy looking error in red font - how can I hide this and just show my message "Doesn't Exist, Creating"

Returning -ErrorVariable defined in remote session invoked with invoke-command

$
0
0

Hi fellow PowerShellers,

I'm trying to find a solution on how to get error variables defined in remote sessions, back to the local session. Let's say I do:

Invoke-command -ComputerName testServer -Scriptblock {

Get-process -Name svchost -errorvariable cmdExecutionStatus

}

I would like to send the cmdExecutionStatus variable back to the local session. I have tried various stuff like:

- assigning the entire invoke-command to a variable, but that of course only gives me the objects returned from the cmdlet inside the scriptblock, in a deserialized form

- setting $lastexitcode = cmdExecutionStatus and then calling the remote server again to assign a new variable to $lastExitCode

- searched the interwebs in general, this page is great btw - http://powershell.com/cs/media/p/7257.aspx :-D

// Do anyone know how, or if it is possible at all, to get an errorvariable defined in a remote session, back to the local session?

Thank you in advance.


Red Baron

Azure Service Status Check and Alert

$
0
0

Hi,

 I would like to have a script regularly check for a service running within Azure and if for some reason that service is down, alert the specified admins accordingly. I understand how to get the status of any given service, however, I am not sure how to script something that looks for a specific result.

Here is the command I am utilizing to get the information I want:

<<<<<< <<

Get-AzureDeployment -ServiceName ubunu


*
*

Status                    : Running

>>>>>>>>

Status is what i need to look at. I have no idea how to script something that looks for that specific result and then does something. I am thinking an "If, Then"  statement, but what commands would look for the result?

Also if there is a suggestion on a different way to go about getting a service status please let me know.

Thanks!

Viewing all 21975 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>