Hi Luc,
can you check folowingscript orange part .
1:i need to exclude one vm in $vms and store in $vms_supported can we use exclude switch
2:i need to rename distributed portgroups by replacing abc by xyz is this correct what i mentioned in second orange part.
$source_side=read-host "specify cluster"
$cluster_source=get-cluster $source_side
$vms=get-vm -Location $cluster_source
$vms_supported=.....
foreach($vm in $vms_supported)
{
$vm.name
}
$des_cluster=get-cluster -name cluster2
$grb_distributedswitch=Get-VirtualSwitch -Distributed -Datacenter dc2
$port_groups_grbs=Get-VirtualPortGroup -Distributed -VirtualSwitch $dc2_distributedswitch
$pgdc2=$port_groups_dc2|select name
foreach($pg in $pgdc2)
{
$new_name=$pg.replace("abc","xyz")
Set-VirtualPortGroup -VirtualPortGroup $pg -name $new_name -WhatIf
}
I assume these 2 questions are not related?
1) If I understand the question correctly, you want to exclude 1 specific VM froma list of VMs?
Then you could do
$cluster_source = Get-Cluster -Name $source_side
$vms = Get-VM -Location $cluster_source
$vms_supported = $vms | where {$_.Name -ne 'VM-to-be-excluded'}
foreach ($vm in $vms_supported) {
$vm.name
}
2) I would use the VDS cmdlets
Like this
$grb_distributedswitch = Get-Datacenter -Name dc2 | Get-VDSwitch
$port_groups_grbs = Get-VDPortgroup -VDSwitch $grb_distributedswitch
foreach ($pg in $port_groups_grbs)
{
$new_name = $pg.Name.replace("abc", "xyz")
Set-VDPortgroup -VDPortgroup $pg -Name $new_name -WhatIf
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I assume these 2 questions are not related?
1) If I understand the question correctly, you want to exclude 1 specific VM froma list of VMs?
Then you could do
$cluster_source = Get-Cluster -Name $source_side
$vms = Get-VM -Location $cluster_source
$vms_supported = $vms | where {$_.Name -ne 'VM-to-be-excluded'}
foreach ($vm in $vms_supported) {
$vm.name
}
2) I would use the VDS cmdlets
Like this
$grb_distributedswitch = Get-Datacenter -Name dc2 | Get-VDSwitch
$port_groups_grbs = Get-VDPortgroup -VDSwitch $grb_distributedswitch
foreach ($pg in $port_groups_grbs)
{
$new_name = $pg.Name.replace("abc", "xyz")
Set-VDPortgroup -VDPortgroup $pg -Name $new_name -WhatIf
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
tx iam checking this
dont we need paramter -VirtualPortGroup to specify the old port groupname.
Set-VDPortgroup -Name $new_name -WhatIf
Indeed, corrected the code above.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
tx Luc.
if you can also suggest some simple powercli way to add .vmx file to inventory .
The New-VM cmdlet with the VMFilePath parameter.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference