VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Unable to get output from multiple servers

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

That worked. but I would like to know, if anyway that I can provide input in one line as below ?

"MySQL01", "MYSQL02"

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Not with Read-Host


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

oh ok...Thank you LucD for the confirmation.

0 Kudos