PowerCLI

 View Only
  • 1.  PowerCLI to change VLANs for VMs

    Posted Apr 11, 2013 05:57 PM

    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



  • 2.  RE: PowerCLI to change VLANs for VMs

    Posted Apr 12, 2013 12:31 AM

    Change

      

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

    To

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



  • 3.  RE: PowerCLI to change VLANs for VMs
    Best Answer

    Posted Apr 12, 2013 12:33 AM

    Discussion moved from Automation Tools to VMware vSphere™ PowerCLI



  • 4.  RE: PowerCLI to change VLANs for VMs

    Posted Apr 12, 2013 02:21 PM

    This worked perfectly.

    Thank You.

    Boston Tech Guy