VMware Cloud Community
BostonTechGuy
Enthusiast
Enthusiast
Jump to solution

PowerCLI to change VLANs for VMs

I am working on a script to change a couple of hundred VMs to a different VLAN.

The script is working in test EXCEPT, I am being prompt to confirm the change.  I have never been prompted before to confirm the change. One of the options is YES TO ALL however I want my script not to prompt at all, just make the change. 

Script:

# VCenter you are connecting too
$vcserver = "MyVcenter.somewhere.local"
Connect-VIServer $vcserver
# Loop to make changes to Network Adapter from List of Servers that needs to be changed
$serverlist = Get-Content "C:\Scripts\vlan_Test\vms.txt"
ForEach ($server in $serverlist)
{
$NIC = Get-NetworkAdapter -VM $server
Set-NetworkAdapter -NetworkAdapter $NIC -NetworkName "MyNewVLan 1234"
}

FYI: I am using PowerGUI to edit my PowerCLI scripts.

Thanks,

Boston Tech Guy

0 Kudos
1 Solution

Accepted Solutions
chriswahl
Virtuoso
Virtuoso
Jump to solution

Discussion moved from Automation Tools to VMware vSphere™ PowerCLI

VCDX #104 (DCV, NV) ஃ WahlNetwork.com ஃ @ChrisWahl ஃ Author, Networking for VMware Administrators

View solution in original post

0 Kudos
3 Replies
chriswahl
Virtuoso
Virtuoso
Jump to solution

Change

   Untitled - PowerGUI Script Editor

Set-NetworkAdapter -NetworkAdapter $NIC -NetworkName "MyNewVLan 1234"

To

Set-NetworkAdapter -NetworkAdapter $NIC -NetworkName "MyNewVLan 1234" -Confirm:$false

VCDX #104 (DCV, NV) ஃ WahlNetwork.com ஃ @ChrisWahl ஃ Author, Networking for VMware Administrators
0 Kudos
chriswahl
Virtuoso
Virtuoso
Jump to solution

Discussion moved from Automation Tools to VMware vSphere™ PowerCLI

VCDX #104 (DCV, NV) ஃ WahlNetwork.com ஃ @ChrisWahl ஃ Author, Networking for VMware Administrators
0 Kudos
BostonTechGuy
Enthusiast
Enthusiast
Jump to solution

This worked perfectly.

Thank You.

Boston Tech Guy

0 Kudos