Hi
Any idea why I am getting the following error?
$vh01='hostname'
$vh01moref=$vh01 | % {get-view $_.Id}
The string "hostname" is not a MoRef that Get-View expects on the ID parameter.
In fact a [string] object has no Id property.
You can do
Get-VMHost -Name hostname | %{Get-View -Id $_.Id}
The object returned by Get-VMHost has an Id property that can be used by Get-View
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Here is the script I use
$vh01=$hostname6
$vh01moref=$vh01 | % {get-view $_.Id}
$vh01morefconfig=$vh01moref.configmanager
$vh01netsys=$vh01morefconfig.networksystem
$vh01netsysmoref=get-view $vh01netsys
foreach ($vh01vsw0 in $vh01netsysmoref.NetworkConfig.Vswitch){
$swspec= $vh01vsw0.Spec
$swspec.policy.security.allowPromiscuous=$false
$swspec.policy.security.forgedTransmits=$true
$swspec.policy.security.macChanges=$false
$vh01netsysmoref.UpdateVirtualSwitch($vh01vsw0.name,$swspec)
}
Try it like this
$vh01Name = $hostname6 $vh01 = Get-VMHost -Name $hostname6 $vh01morefconfig = $vh01.ExtensionData.configmanager $vh01netsys = $vh01morefconfig.networksystem
$vh01netsysmoref = get-view $vh01netsys foreach ($vh01vsw0 in $vh01netsysmoref.NetworkConfig.Vswitch){ $swspec = $vh01vsw0.Spec
$swspec.policy.security.allowPromiscuous=$false
$swspec.policy.security.forgedTransmits=$true
$swspec.policy.security.macChanges=$false
$vh01netsysmoref.UpdateVirtualSwitch($vh01vsw0.name,$swspec) }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi
I dont understand why you need to do
get-vmhost -name vmhostname | % { get-view -id $_.id}
and just
get-vmhost -name vmhostname | get-view
why are you using the $_.id