VMware Cloud Community
stumper
Contributor
Contributor

Having trouble with get-vdportgroup cmdlet

Hello, all.

I'm updating a script that sets a newly provisioned VM's network adapter based on the requester's vlan selection. Nothing complicated, just a few lines:

$myPG = Get-VDPortgroup -Name $vlan

"$myPG - value for myPG variable" | Out-File ("$NVM_logs" + "$newVMName" + "_logs.txt") -Append

$myNA = Get-VM -Name $newVMName | Get-NetworkAdapter -Name "Network Adapter 1"

"$myNA - value for myNA variable" | Out-File ("$NVM_logs" + "$newVMName" + "_logs.txt") -Append

Set-NetworkAdapter -NetworkAdapter $myNA -Portgroup $myPG -Confirm:$false

I'm using the Out-File bits to see what values are being captured for the $myPG and $myNA variables. $myNA works just fine, but the $myPG value is not being set. I had a feeling that the get-VDPortgroup command wasn't being recognized, so I added this:

import-module -Name vmware.vimautomation.vds

at the top of the script. But I'm still getting the same results. When I run the command manually (both the import-module and the lines above) in a PowerCLI window, it works as expected: both variables are defined and the set-networkadapter cmdlet configures the network adapter.

So my question to you all: what am I missing that will allow me to use the get-vdportgroup cmdlet? I'm running PS3, PowerCLI 6 on W2K8R2, and connecting to a vCenter Server running 5.5 with a vDS also running as 5.5.

Thanks in advance!

mike

Tags (2)
0 Kudos
2 Replies
LucD
Leadership
Leadership

Perhaps you could add the following lines to the script to help determine what might be wrong.

Get-Module -Name VMware* | Select Name

Get-Command -Name Get-VDPortgroup -Module VMware.VimAutomation.Vds


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

stumper
Contributor
Contributor

This put me on the right track. Thank you!

The resolution was to log into the script host using the service account that runs our scripting. When I launched a PowerShell window under that account, I got an error that said the vmware.vimautomation.vds module could not be found. (I had created a profile.ps1 to load the vds module for all users.) I re-ran the PowerCLI 6 installer, elected to repair the installation, and now the cmdlets are working as expected.

mike

0 Kudos