Hello Luc,
could you check following code .this is to disable vmotion traffic on mangement port (vmk0) .
this works fine but i wanted to develop using get-view .in your last post yu mentioned
we can view esxi using -property name,config.network.vnic
however issues i am getting is i dont see any nested properties corresponding to managementtrafficenabled and vmotionenabled
also we need to find method corresponding to Set-VMHostNetworkAdapter -VMotionEnabled $false.
i have been checking hostvirtualnic object in api documentation but did not find anything or iam not able to understand .need you help if following code can be converted using get-view way.
$vmhosts=get-vmhost -location $cluster
foreach($hos in $vmhosts)
{
$vmkernel=Get-VMHostNetworkAdapter -VMKernel -VMHost $hos|Where-Object{$_.managementtrafficenabled -eq $true -and $_.vmotionenabled -eq $true}
$vmkernel|select @{N='esxi name';E={$hos.name}},@{N='vmkernel port';E={$_.name}}
if ($vmkernel -eq $null)
{
Write-Output "nothing to remediate for traffic separation"
}
else
{
$rem1=read-host " do yu want to remediate traffic separation"
}
if($rem1 -eq "yes")
{
write-output "remediating traffic separation"
$vmkernel|Set-VMHostNetworkAdapter -VMotionEnabled $false -confirm:$false
}
}
In any case, you can do something like this
$tgtVNic = 'vmk0'
foreach($cluster in Get-View -ViewType ClusterComputeresource -Property Name)
{
foreach($esx in Get-View -ViewType HostSystem -Property Name,ConfigManager.VirtualNicManager -SearchRoot $cluster.Moref)
{
$vnicMgr = Get-View -Id $esx.ConfigManager.VirtualNicManager
$vmotionvnic = $vnicMgr.QueryNetConfig([vmware.vim.HostVirtualNicManagerNicType]::vmotion)
$key = $vmotionvnic.CandidateVnic | where{$_.Device -eq $tgtVNic} | select -ExpandProperty Key
if($key -and $vmotionvnic.SelectedVnic -contains $key){
$vNicMgr.DeselectVnicForNicType([vmware.vim.HostVirtualNicManagerNicType]::vmotion,$tgtVNic)
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not sure why you would want to change a VMkernel setting through API?
That, as you showed, can perfectly be done with the PowerCLI cmdlet.
Remember that the API (through Get-View and ExtensionData) should be used for speed in bigger environments, and to get access to properties and methods that are not available through a PowerCLI cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
In any case, you can do something like this
$tgtVNic = 'vmk0'
foreach($cluster in Get-View -ViewType ClusterComputeresource -Property Name)
{
foreach($esx in Get-View -ViewType HostSystem -Property Name,ConfigManager.VirtualNicManager -SearchRoot $cluster.Moref)
{
$vnicMgr = Get-View -Id $esx.ConfigManager.VirtualNicManager
$vmotionvnic = $vnicMgr.QueryNetConfig([vmware.vim.HostVirtualNicManagerNicType]::vmotion)
$key = $vmotionvnic.CandidateVnic | where{$_.Device -eq $tgtVNic} | select -ExpandProperty Key
if($key -and $vmotionvnic.SelectedVnic -contains $key){
$vNicMgr.DeselectVnicForNicType([vmware.vim.HostVirtualNicManagerNicType]::vmotion,$tgtVNic)
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
iunderstand,yes it can be done with powercli commands.
however this is one of the remediation porttionwhich i want to merge with previous code that was developed using get-view .
this will be consistent and some of the previus defined variables (which were defined using get-view) can be utilized.
also i want to learn also how to use api documentation quicky
.can you suggest any brief documnetto understand this.
I'm afraid there is no documentation to help you use the API Reference.
That is a document that you need to get into, meaning use it to get the hang of it.
There is a SDK chapter in the PowerCLI Reference book, where I give an example, but that is definitely not a full fledged learning guide.
Does the script work for you?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
this is lightning fast even for small environemt.that works fine but not easy to understand comapred to what basic i created using simple powercli commands .
thanks for your help.
just though of asking while wrting this type of code are you reffering api documentation or yu able to find it quickly only in powercli.
There is a lot of experience and looking at other people's scripts involved to get comfortable with the API.
One other source, although not light reading, that might help is the Programming Guide.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference