{"id":372,"date":"2016-08-16T06:51:31","date_gmt":"2016-08-16T06:51:31","guid":{"rendered":"http:\/\/vblog.hochsticher.de\/?p=372"},"modified":"2016-08-16T16:08:06","modified_gmt":"2016-08-16T16:08:06","slug":"add-vlan-in-ucs-with-powershell","status":"publish","type":"post","link":"https:\/\/vblog.hochsticher.de\/?p=372","title":{"rendered":"Add VLAN in UCS with PowerShell"},"content":{"rendered":"<p>Mostly I created VLANs in UCS with the GUI, but how do we do this in PowerShell?<\/p>\n<p><!--more--><\/p>\n<p>When I have to create a lot of new VLANs, I\u00a0want to do this in CLI\u00a0\ud83d\ude0e<\/p>\n<p>The weird thing when starting with Cisco PowerShell Module is that you have to insert your credentials on nearly every command.<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true \">#Load Cisco UCS PS Module\r\nImport-Module CiscoUcsPS\r\n\r\n#Creds\r\n$ucsUserName = \"myuser\"\r\n$ucsPassword = \"myp@ssword\"\r\n$ucsSysName1 = \"my-ucs-manager\"\r\n\r\n# The UCSM connection requires a PSCredential to login, so we must convert our plain text password to make an object\r\n$ucsPassword = ConvertTo-SecureString -String $ucsPassword -AsPlainText -Force\r\n$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $ucsUserName, $ucsPassword\r\n\r\n########################\r\n# Authenticate to UCSM #\r\n########################\r\n$handle1 = Connect-Ucs $ucsSysName1 -NotDefault -Credential $cred\r\n\r\n#Define Variables\r\n$vlanid = 229\r\n$vlname = \"229-MyNewVlan\"\r\n$vlangroup = \"ESX-DMZ\"\r\n$macpool = \"My-MAC-Pool\"\r\n$qpol = \"ESX-Gold\"\r\n$vnictmpdmzA = \"DMZ-Data-FabA\"\r\n$vnictmpdmzB = \"DMZ-Data-FabB\"\r\n\r\n\r\n\r\n\r\n\r\n#Create VLAN Global\r\n$handle1 = Connect-Ucs $ucsSysName1 -NotDefault -Credential $cred\r\nGet-UcsLanCloud | Add-UcsVlan -CompressionType \"included\" -DefaultNet \"no\" -Id $vlanid -McastPolicyName \"\" -Name $vlname -PolicyOwner \"local\" -PubNwName \"\" -Sharing \"none\"\r\n\r\n\r\n#Add VLAN to Group\r\nStart-UcsTransaction  -Ucs $handle1\r\n$mo = Get-UcsLanCloud -Ucs $handle1 | Add-UcsFabricNetGroup -ModifyPresent  -Descr \"\" -NativeNet \"\" -PolicyOwner \"local\" -Type \"mgmt\" -Name $vlangroup\r\n$mo_1 = $mo | Add-UcsFabricPooledVlan -ModifyPresent -Name $vlname\r\nComplete-UcsTransaction -Ucs $handle1\r\n\r\n\r\n#Add to Template FAB A\r\nStart-UcsTransaction -Ucs $handle1\r\n$mo = Get-UcsOrg -Ucs $handle1 -Level root  | Add-UcsVnicTemplate -ModifyPresent  -Descr \"\" -IdentPoolName $macpool -Mtu 1500 -NwCtrlPolicyName \"Enable-CDP\" -PinToGroupName \"\" -PolicyOwner \"local\" -QosPolicyName $qpol -StatsPolicyName \"default\" -SwitchId \"A\" -TemplType \"updating-template\" -Name $vnictmpdmzA -XtraProperty @{CdnSource=\"vnic-name\"; RedundancyPairType=\"none\"; PeerRedundancyTemplName=\"\"; AdminCdnName=\"\"; }\r\n$mo_1 = $mo | Add-UcsVnicInterface -ModifyPresent -DefaultNet \"no\" -Name $vlname\r\nComplete-UcsTransaction\r\n\r\n#Add to Template FAB B\r\nStart-UcsTransaction -Ucs $handle1\r\n$mo = Get-UcsOrg -Ucs $handle1 -Level root  | Add-UcsVnicTemplate -ModifyPresent  -Descr \"\" -IdentPoolName $macpool -Mtu 1500 -NwCtrlPolicyName \"Enable-CDP\" -PinToGroupName \"\" -PolicyOwner \"local\" -QosPolicyName $qpol -StatsPolicyName \"default\" -SwitchId \"B\" -TemplType \"updating-template\" -Name $vnictmpdmzB -XtraProperty @{CdnSource=\"vnic-name\"; RedundancyPairType=\"none\"; PeerRedundancyTemplName=\"\"; AdminCdnName=\"\"; }\r\n$mo_1 = $mo | Add-UcsVnicInterface -ModifyPresent -DefaultNet \"no\" -Name $vlname\r\nComplete-UcsTransaction -Ucs $handle1\r\n<\/pre>\n<p>Please, check out and write a comment!<\/p>\n<p style=\"text-align: left;\"><em>Scared? Try first in a emulator\u00a0to\u00a0feel\u00a0more confident.<\/em><\/p>\n<p style=\"text-align: left;\"><a href=\"https:\/\/communities.cisco.com\/docs\/DOC-37827\" target=\"_blank\">Link: Cisco UCS Platform Emulator<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mostly I created VLANs in UCS with the GUI, but how do we do this in PowerShell?<\/p>\n","protected":false},"author":1,"featured_media":242,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-372","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cisco-ucs","category-powercli"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=\/wp\/v2\/posts\/372","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=372"}],"version-history":[{"count":11,"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=\/wp\/v2\/posts\/372\/revisions"}],"predecessor-version":[{"id":374,"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=\/wp\/v2\/posts\/372\/revisions\/374"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=\/wp\/v2\/media\/242"}],"wp:attachment":[{"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}