Hi,
I'm trying to connect to a host (not a vCenter), list the VMs, select the ones in two different networks, then apply two Advanced Settings to the VM.
So far I have this:
$vms = Get-VM
Connect-VIServer $esxi -User $user -Password $pass
foreach ($vm in $vms) {
if (Get-NetworkAdapter -vm $vm.name |?{$_.NetworkName -eq "VLAN70"}) {
New-AdvancedSetting $vm -Name isolation.tools.copy.disable -Value false -Confirm:$false -Force:$true
New-AdvancedSetting $vm -Name isolation.tools.paste.disable -Value false -Confirm:$false -Force:$true
}
}
Disconnect-VIServer $esxi -Confirm:$false
First, how to I add a second network to check - so "VLAN70" or "VLAN80"?
Second, is there a smarter way of writing this script? I'm early doors with PowerCLI, but even I think my grandma could write a better version....
Any advice would be greatly appreciated,
-virtualhobbit
I see, then you could do something like this
$tgtVLAN = 'VLAN80','VLAN80','VLAN90'
Connect-VIServer $esxi -User $user -Password $pass
Get-VM |
where{(Get-NetworkAdapter -VM $_ | %{$tgtVLAN -contains $_.NetworkName}) -contains $true} | %{
New-AdvancedSetting $_ -Name isolation.tools.copy.disable -Value false -Confirm:$false -Force:$true
New-AdvancedSetting $_ -Name isolation.tools.paste.disable -Value false -Confirm:$false -Force:$true
}
Disconnect-VIServer $esxi -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
Connect-VIServer $esxi -User $user -Password $pass
Get-VM |
where{Get-NetworkAdapter -Name 'VLAN70' -vm $_} | %{
New-AdvancedSetting $_ -Name isolation.tools.copy.disable -Value false -Confirm:$false -Force:$true
New-AdvancedSetting $_ -Name isolation.tools.paste.disable -Value false -Confirm:$false -Force:$true
New-NetworkAdapter -VM $_ -NetworkName 'VLAN80' -Confirm:$false
}
Disconnect-VIServer $esxi -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
Thanks... that's great!
What I actually meant was, how to check for multiple networks?
ie. If a member or VLAN70 or VLAN80 or VLAN90 etc.
-virtualhobbit
I see, then you could do something like this
$tgtVLAN = 'VLAN80','VLAN80','VLAN90'
Connect-VIServer $esxi -User $user -Password $pass
Get-VM |
where{(Get-NetworkAdapter -VM $_ | %{$tgtVLAN -contains $_.NetworkName}) -contains $true} | %{
New-AdvancedSetting $_ -Name isolation.tools.copy.disable -Value false -Confirm:$false -Force:$true
New-AdvancedSetting $_ -Name isolation.tools.paste.disable -Value false -Confirm:$false -Force:$true
}
Disconnect-VIServer $esxi -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hey LucD,
Brilliant! Thank you 🙂
-virtualhobbit