Hello, as per title I'm trying to achieve the result with this but it won't work:
$netinfo = Get-VDSwitch MydVS | Get-VirtualPortGroup | ?{$_.Name -cnotmatch ".*VDs*." -and $_.Name -notmatch ".*dvuplink*." } |
Select Name,@{N="VLANId";E={$_.Extensiondata.Config.DefaultPortCOnfig.Vlan.VlanId}}
foreach($pgname in $netinfo.Name){
foreach($pgvlanid in $netinfo.vlanID){
$pref = "VLAN"
$newname = $pref + "_" + $pgvlanid + "_" + $pgname
Get-VirtualPortGroup -Name $pgname | Set-VirtualPortGroup -Name $newname
}
}
I can´t manage to fix the problem on line 15 at the pipeline. It seems the Set cmdlet does not accept the $pgname input. Any hint?
Seems there might be an issue with passing a vdPortgroup over the pipeline.
Try like this.
Note that I used a different property to obtain the VLANid
foreach($pg in (Get-VDSwitch MydVS | Get-VDPortgroup |?{$_.Name -cnotmatch ".*VDs*." -and $_.Name -notmatch ".*dvuplink*." })){
Set-VDPortGroup -VDPortgroup $pg -Name "VLAN_$($pg.Extensiondata.Config.DefaultPortCOnfig.Vlan.VlanId)_$($pg.Name)" -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The Select-Object cmdlet produces output for the console, not really useful when manipulating data.
You can try like this (which uses the pipeline instead of a ForEach construct)
Get-VDSwitch MydVS | Get-VirtualPortGroup | ?{$_.Name -cnotmatch ".*VDs*." -and $_.Name -notmatch ".*dvuplink*." } |
Set-VirtualPortGroup -Name "VLAN_$($_.Extensiondata.Config.DefaultPortCOnfig.Vlan.VlanId)_$($_.Name)" -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc, but I get same error:
Set-VirtualPortGroup : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
At C:\Users\xxxxxx\Documents\powerCLI\tested\network\renameVDSpgWithVlanID.ps1:2 char:1
+ Set-VirtualPortGroup -Name "VLAN_$($_.Extensiondata.Config.DefaultPor ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (VMWARE_PORTGROUP_233:PSObject) [Set-VirtualPortGroup], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetVirtualPortGroup
Can you show the complete content of renameVDSpgWithVlanID.ps1
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
it's exactly your script:
Get-VDSwitch mydvswitch | Get-VirtualPortGroup | ?{$_.Name -cnotmatch ".*VDs*." -and $_.Name -notmatch ".*dvuplink*." } |
Set-VirtualPortGroup -Name "VLAN_$($_.Extensiondata.Config.DefaultPortCOnfig.Vlan.VlanId)_$($_.Name)" -Confirm:$false
obviously I omitted the real name of the dvswitch. Output of
Get-VDSwitch mydvswitch | Get-VirtualPortGroup | ?{$_.Name -cnotmatch ".*VDs*." -and $_.Name -notmatch ".*dvuplink*." }
is
Name Key VLanId PortBinding NumPorts
---- --- ------ ----------- --------
qqqqqqqqqqqqqqqqq dvportgroup-3157 Static 128
yyyyyyyyyyyyyyyyy dvportgroup-3156 Static 128
ttttttttttttttttttttttttttttttttt dvportgroup-5960 Static 128
xxxxxxxxxxxxxxxxxxxxxxxx dvportgroup-3158 Static 128
real names omitted
My bad, didn't use the VDS flavour for the PortGroup cmdlets.
Try like this
Get-VDSwitch MydVS | Get-VDPortgroup |
?{$_.Name -cnotmatch ".*VDs*." -and $_.Name -notmatch ".*dvuplink*." } |
Set-VDPortGroup -Name "VLAN_$($_.Extensiondata.Config.DefaultPortCOnfig.Vlan.VlanId)_$($_.Name)" -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
also the way to retrieve the vlan ID had to change:
Get-VDSwitch ICC-GVA-MNGMT | Get-VDPortgroup | ?{$_.Name -cnotmatch ".*VDs*." -and $_.Name -notmatch ".*dvuplink*." } |
Set-VDPortgroup -Name "VLAN_$($_.vlanconfiguration.vlanID)_$($_.Name)" -Confirm:$false
however it behaves in a weird way. It renames only one vlan with VLAN_ only without the rest of its name and for all other portgroups it throws an error like this:
Set-VDPortgroup : 12/19/2017 12:04:03 PM Set-VDPortgroup The operation for the entity "xxxxxxxxx" failed with the following message: "The name 'VLAN__' already exists."
At C:\Users\cavallo\Documents\VI-Tools\powerCLI\tested\network\renameVDSpgWithVlanID.ps1:2 char:1
+ Set-VDPortgroup -Name "VLAN_$($_.vlanconfiguration.vlanID)_$($_.Name) ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-VDPortgroup], DuplicateName
+ FullyQualifiedErrorId : Client20_TaskServiceImpl_CheckServerSideTaskUpdates_OperationFailed,VMware.VimAutomation.Vds.Commands.Cmdlets.SetVDPortgroup
Seems there might be an issue with passing a vdPortgroup over the pipeline.
Try like this.
Note that I used a different property to obtain the VLANid
foreach($pg in (Get-VDSwitch MydVS | Get-VDPortgroup |?{$_.Name -cnotmatch ".*VDs*." -and $_.Name -notmatch ".*dvuplink*." })){
Set-VDPortGroup -VDPortgroup $pg -Name "VLAN_$($pg.Extensiondata.Config.DefaultPortCOnfig.Vlan.VlanId)_$($pg.Name)" -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc, it had exactly the same behaviour as before but after the error messages the foreach did the job. Thanks in the meantime! I'll keep it like that for now...