If you create a file called vmhosts.csv that has the following structure:
Name
ESX1.yourdomain.com
ESX2.yourdomain.com
then you can use the following PowerCLI code as a wrapper around your code:
Import-Csv-Pathvmhosts.csv |ForEach-Object { $VMHost=Get-VMHost$_ $VMHostView=$VMHost.ExtensionData $NetworkSystem=$VMHostView.Configmanager.NetworkSystem $VirtualNicManager=$VMHostView.Configmanager.VirtualNicManager $IscsiManager=$VMHostView.Configmanager.IscsiManager # Your code comes here!}
At each place where in your code is used something like:
$_this=Get-View-Id'IscsiManager-iscsiManager-360'$_this.QueryPnicStatus("vmnic1")
you need to replace the MoRef with the corresponding variable:
$_this=Get-View-Id$IscsiManager$_this.QueryPnicStatus("vmnic1")
Replace 'IscsiManager-iscsiManager-360' with $IscsiManager, 'HostVirtualNicManager-virtualNicManager-360' with $VirtualNicManager and 'HostNetworkSystem-networkSystem-360' with $NetworkSystem.