LucD
Leadership
Leadership

You can find the host a VM is on like this

$hostname = Get-VM -Name $vmName | Get-VMHost | Select -ExpandProperty Name

You can now test on te hostname

if($hostname -like "*1$"){

   $dsname = "datastore1"

}

elseif($hostname -like "*2$"){

   $dsname = "datastore2"

}

There are of course many other ways to accomplish the same, but this is in my opinion one of the most simple ones.


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

Reply
0 Kudos