VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

finding_list ofavailablevms_in totalvms_in_vcenter_powercli

Hi Luc,

can you please check why folowing code is not working .i am thinking to get found vms in $found.but its not happening for some reasons.

$strings=Import-Csv -Path 'C:\Users\administrator\desktop\add_srm1.csv'

$found=@()

$vms_prod_vcenter=(get-vm).name

foreach($vm in $strings)

{

$v= get-vm -name $vm.vmname

$v.name

if($vms_prod_vcenter -contains $v.name)

{

write-host "vm found" $v.name

$v.name += $found

}

}

$found

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I suspect the assignment to $foudn must be the other way round.

$strings=Import-Csv -Path 'C:\Users\administrator\desktop\add_srm1.csv'

$found = @()

$vms_prod_vcenter = (Get-VM).name

foreach ($vm in $strings)

{

   $v = Get-VM -Name $vm.vmname

   $v.name

   if ($vms_prod_vcenter -contains $v.name)

   {

   write-host "vm found" $v.name

   $found += $v.name

   }

}

$found


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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

I suspect the assignment to $foudn must be the other way round.

$strings=Import-Csv -Path 'C:\Users\administrator\desktop\add_srm1.csv'

$found = @()

$vms_prod_vcenter = (Get-VM).name

foreach ($vm in $strings)

{

   $v = Get-VM -Name $vm.vmname

   $v.name

   if ($vms_prod_vcenter -contains $v.name)

   {

   write-host "vm found" $v.name

   $found += $v.name

   }

}

$found


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

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

Thanks Luc.my mistake...

Reply
0 Kudos