Hi,
is it possible to set the the CDP-Settings on an ESXi5.1 on multiple Hosts via PowerCLI ?
And if so....how?
Thanks in advance!!
Chakoe
I guess (wildguess) that your vSwitches are called vSwitch. Typo? Case sensitive?
Im using this script of Lucd. Running against more vCenters (more ESX hosts)
Assuming CDP discovery is allowed on netwerk level.
$LogTimeStamp = (Get-Date).ToString("dd-MM-yyyy_HH_mm")
$vCenters= @("YourVCenter1","YourVCenter1","YourVCenter3")
Foreach ($VC in $vCenters) {
$currDir = Split-path -parent $MyInvocation.MyCommand.Definition
$outputFile = $currDir + "\CDP_" + $LogTimeStamp + "_Port_inventory.csv"
if (Test-Path $outputFile)
{
Remove-Item $outputFile
}
$cvc=Connect-Viserver -Server $VC -ErrorAction SilentlyContinue
if($cvc.IsConnected)
{
# Start collecting the data
$VMhostsColl = @(Get-VMHost) | Sort-Object Name
$i=0
$b=0
$b = $VMhostsColl.Count
$Report=@()
$vmhosts = Get-VMHost | Sort Name | Where-Object {$_.State -eq "Connected"} | Get-View
foreach ($vmhost in $vmhosts){
$i++
write-progress "Please wait....CDP inventory in progress..." "VMhost ($i of $b) " 1 -perc (($i / $b)*100)
$ESXHost = $vmhost.Name
$networkSystem = Get-view $vmhost.ConfigManager.NetworkSystem
foreach($pnic in $networkSystem.NetworkConfig.Pnic){
$pnicInfo = $networkSystem.QueryNetworkHint($pnic.Device)
foreach($Hint in $pnicInfo){
$Details = "" | select-Object vCenter,Cluster,Host, PNic, Speed, MAC, DeviceID, PortID, VLAN, Observed
$Details.vCenter=$vmhost.Client.ServiceUrl.Split('/')[2].replace(":443","")
$Details.Cluster = &{
$parentx = Get-View $vmhost.parent
while ($parentx -isnot [VMware.Vim.ClusterComputeResource] -and $parentx.Parent){
$parentx = Get-View $parent.Parent
}
if($parentx -is [VMware.Vim.ClusterComputeResource]){
$parentx.Name
}
}
$Details.Host = $vmhost.Name
$Details.PNic = $Hint.Device
$Details.DeviceID = $Hint.connectedSwitchPort.DevId
$Details.PortID = $Hint.connectedSwitchPort.PortId
$record = 0
Do{
If ($Hint.Device -eq $vmhost.Config.Network.Pnic[$record].Device){
$Details.Speed = $vmhost.Config.Network.Pnic[$record].LinkSpeed.SpeedMb
$Details.MAC = $vmhost.Config.Network.Pnic[$record].Mac
}
$record ++
} Until ($record -eq ($vmhost.Config.Network.Pnic.Length))
foreach ($obs in $Hint.Subnet){
$Details.Observed += $obs.IpSubnet + " "
Foreach ($VLAN in $obs.VlanId){
If ($VLAN -eq $null){}
Else{
$strVLAN = $VLAN.ToString()
$Details.VLAN += $strVLAN + " "
}
}
}
$Details
$Report+=$Details
}
}
}
$report | Sort-Object vCenter -Descending | Export-Csv -NoTypeInformation -Path $outputFile
Hi,
thank you, but this looks like the script is only READING the settings, right?
Is there a way to SET CDP-Parameters?
hm....points into the right direction, but i don´t know how to use this function...
My hope was, that there is a simple way like:
$hosts = Get-VMHost host61* | Sort-Object $_.Name | Select -ExpandProperty Name
foreach ( $singleesx in $hosts ) {
$esxcli = Get-EsxCli -VMHost $singleesx
$esxcli.network.vswitch.standard.set("both","1500","vswitch0")
$esxcli.network.vswitch.standard.set("both","1500","vswitch1")
$esxcli.network.vswitch.standard.set("both","1500","vswitch2")
$esxcli.network.vswitch.standard.set("both","9000","vStorage")
}
But this ony results in:
Message: vswitch0 is not a valid name for a virtual switch;
InnerText: vswitch0 is not a valid name for a virtual switchEsxCLI.CLIFault.summary
Bei C:\Users\j131670\AppData\Local\Temp\ddf3418c-79b0-4c6f-b6bb-3a69d6856a8d.ps1:5 Zeichen:37
+ $esxcli.network.vswitch.standard.set <<<< ("both","1500","vswitch0")
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodInvocationException
But in fact, all these Switches exist on these Hosts...
I guess (wildguess) that your vSwitches are called vSwitch. Typo? Case sensitive?
Perhaps completely beside the point, but I have seen other issues with Get-EsxCli when the regional setting was not US English.
From the error message it looks as if you have the regional settings configured for German.
Can you try the same thing but with US English ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
typo! 😞
$hosts = Get-View -ViewType HostSystem | Sort-Object Name | Select -ExpandProperty Name
#$hosts = Get-VMHost * | Sort-Object $_.Name | Select -ExpandProperty Name
foreach ( $singleesx in $hosts ) {
Write-Host "Processing Host" $singleesx "...."
$esxcli = Get-EsxCli -VMHost $singleesx
$esxcli.network.vswitch.standard.set("both","1500","vSwitch0")
$esxcli.network.vswitch.standard.set("both","1500","vSwitch1")
$esxcli.network.vswitch.standard.set("both","1500","vSwitch2")
$esxcli.network.vswitch.standard.set("both","9000","vStorage")
}
works fine for me!
Thanks!