Automation

 View Only

About enabling CDP with powershell

  • 1.  About enabling CDP with powershell

    Posted Nov 24, 2009 10:26 PM

    About enabling CDP whut powershell i wrote a script any comment or feedback welcome

    1. To use only to 3.5 and up version of ESX

    $VMHosts = Get-VMHost | Sort-Object Name

    $User = "root"

    $Pswd = "rootpassword"

    $plink = "YOUR PLINK LOCATION \plink.exe"

    1. You can download plink.exe from following URL

    2. http://the.earth.li/~sgtatham/putty/latest/x86/plink.exe

    $plinkoptions = "-pw $Pswd"

    1. Uncomment for get certificate from ESX hosts

    #ForEach ($VMHost in $VMHosts)

    #{

    1. $autentication = "echo Y | $plink -l root -pw $Pswd $($VMHost.Name) exit"

    # Invoke-Expression -Command $autentication

    #}

    ForEach ($VMHost in $VMHosts)

    {

    Get-VirtualSwitch -VMHost $VMHost | Foreach {

    $msg = ""

    $cmd = 'esxcfg-vswitch -B both '

    $remoteCommand = '"' + $cmd + $_.name + '"'

    $command = $plink + " " + $plinkoptions + " " + $User + "@" + $VMHost.Name + " " + $remoteCommand

    $msg = Invoke-Expression -command $command -ErrorAction SilentlyContinue -Verbose

    }

    }

    Obviusly only fot ESX 3.5 and higher