VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

get-content without text file

Hi,

Please help me how to input the names of the VMs from the list rather than creating a txt file ?

Please help!!!

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You will have to set up you loop like this

$servs = @'

VMName

VM1

VM2

VM3

'@

ForEach ($serv in (ConvertFrom-Csv -InputObject $servs).VMName){

# Your code

}


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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Have you looked at using a here-string?

$data = @'

VMName

VM1

VM2

VM3

'@

ConvertFrom-Csv -InputObject $data


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

I am getting the below 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:\myreports\Disk_Info\8_Get_VM_Disk_Info_2.0.ps1:41 char:11

+ $output = Invoke-Command -ComputerName $serv -Credential $Creds1 -ScriptBlock {G ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (System.String[]:String[]) [Invoke-Command], ArgumentException

    + FullyQualifiedErrorId : PSSessionInvalidComputerName,Microsoft.PowerShell.Commands.InvokeCommandCommand

$servs = @'

VMName

VM1

VM2

VM3

'@

ConvertFrom-Csv -InputObject $servs

ForEach ($serv in $servs)

{

$WPassword = "password"

$pass = ConvertTo-SecureString -AsPlainText $WPassword -Force

$Creds1 = New-Object System.Management.Automation.PSCredential (".\admin", $pass)

$output = Invoke-Command -ComputerName $serv -Credential $Creds1 -ScriptBlock {Get-WmiObject Win32_DiskDrive | ForEach-Object {

  $disk = $_

  $partitions = "ASSOCIATORS OF " +

                "{Win32_DiskDrive.DeviceID='$($disk.DeviceID)'} " +

                "WHERE AssocClass = Win32_DiskDriveToDiskPartition"

  Get-WmiObject -Query $partitions | ForEach-Object {

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You will have to set up you loop like this

$servs = @'

VMName

VM1

VM2

VM3

'@

ForEach ($serv in (ConvertFrom-Csv -InputObject $servs).VMName){

# Your code

}


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thanks you very much...that worked Smiley Happy

Reply
0 Kudos