Hi,
I am unable to get the output from multiple servers as I am getting the below error
I am providing the input as below
"MySQL01", "MYSQL02"
#$serv = Read-Host "Enter Windows HostName :"
$serv | %{
$output = Invoke-Command -ComputerName $serv -Credential $Creds1 -ScriptBlock {get-disk | sort Number | Select @{n="Host"; e={$env:computername}}, Number, FriendlyName, @{n="Size"; e={[math]::Round($_.Size/1GB,2)}}, SerialNumber, OperationalStatus | Format-Table -AutoSize}
}
$reportlocation = "D:\Disk_Info.txt"
$output | Out-File $reportlocation
$output
Error
Invoke-Command : One or more computer names are not valid. If you are trying to pass a URI, use the -ConnectionUri parameter, or pass URI objects instead of strings.
At D:\Raw_DiskInfo1.ps1:28 char:11
+ $output = Invoke-Command -ComputerName $serv -Credential $Creds1 -Scr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (System.String[]:String[]) [Invoke-Command], ArgumentException
+ FullyQualifiedErrorId : PSSessionInvalidComputerName,Microsoft.PowerShell.Commands.InvokeCommandCommand
Out-File : Illegal characters in path.
At D:\DiskInfo1.ps1:33 char:11
+ $output | Out-File $reportlocation
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (:) [Out-File], ArgumentException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand
What do you have in $serv?
The Read-Host is commented out, are you in fact using that?
If yes, then $serv will contain a single String, not an array of Strings.
You would need to place the Read-Host in a loop to fill up an array.
Something like this
$serv = @()
do{
$input = Read-Host -Prompt "Enter names, stop by entering a blank line"
if($input -ne ''){
$serv += $input
}
}
until($input -eq '')
$serv
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What do you have in $serv?
The Read-Host is commented out, are you in fact using that?
If yes, then $serv will contain a single String, not an array of Strings.
You would need to place the Read-Host in a loop to fill up an array.
Something like this
$serv = @()
do{
$input = Read-Host -Prompt "Enter names, stop by entering a blank line"
if($input -ne ''){
$serv += $input
}
}
until($input -eq '')
$serv
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
That worked. but I would like to know, if anyway that I can provide input in one line as below ?
"MySQL01", "MYSQL02"
Not with Read-Host
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
oh ok...Thank you LucD for the confirmation.