Hi,
Please help me how to input the names of the VMs from the list rather than creating a txt file ?
Please help!!!
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
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
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 {
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
Thanks you very much...that worked