# encoding: ascii
# api: powershell
# title: Set vSphere CDP LinkDisc
# description: A script to set the CDP settings for vsphere. Note that LLDP is an option in vSphere, but it doesn’t work. Here’s hoping for the future!
# version: 0.1
# type: function
# license: CC0
# function: set-vSwitchLinkDiscovery
# x-poshcode-id: 1583
# x-archived: 2010-01-22T06:04:52
#
#
function set-vSwitchLinkDiscovery {
    Param (
        #Switch to enable vSwitch Discovery On
         [Parameter(Mandatory=$true,ValueFromPipeline=$true)]$vSwitchName
        #Host on which the vSwitch Resides
        ,[Parameter(Mandatory=$true,HelpMessage="")][string]$VMBackupDestination,
    ) #Param

	#Variables
	$vSwitchName = "vSwitch0"
	$linkProtocol = "cdp"
	$linkOperation = "both"
	$VMHost = "myhost"

	#Get the specification for the vSwitch
	$networkview = (get-vmhostnetwork -vmhost $VMHost | get-view)
	$vSwitchSpec = ($networkView.NetworkConfig.vSwitch | Where {$_.Name -eq $vSwitchName}).Spec

	#Set Protocol Type and Operation
	$vSwitchSpec.Bridge.LinkDiscoveryProtocolConfig.protocol = $linkProtocol	$vSwitchSpec.Bridge.LinkDiscoveryProtocolConfig.operation = $linkOperation

	#Commit Changes
	$networkview.updateVirtualSwitch($vSwitchName,$vSwitchSpec)
}
