├── Examples ├── 02-demo1.ps1 ├── 02-demo2.ps1 ├── 02-demo3.ps1 ├── 02-demo4.ps1 ├── 02-demo5.ps1 ├── 02-demo6.ps1 ├── CAPTURE-switch-cmd-list.csv ├── CAPTURE-switch-list.csv ├── CAPTURE-switch.ps1 ├── CFG-add-vlans.ps1 ├── CFG-delete-vlans.ps1 ├── CSV-LANSW-list.csv ├── CSV-VLAN-list.csv ├── HTTP server │ ├── HTTP-web-srv.ps1 │ └── HTTP-web-test.ps1 ├── PING-test-list.csv ├── PING-test-list.ps1 ├── PING-test-single.ps1 ├── SAN │ ├── MDS-devalias-srv.ps1 │ ├── MDS-zoning-PURE-2FC-A.ps1 │ ├── MDS-zoning-PURE-2FC-B.ps1 │ ├── MDS-zoning-VNX-4FC-A.ps1 │ ├── MDS-zoning-VNX-4FC-B.ps1 │ ├── wwpnUCS-A.csv │ ├── wwpnUCS-B.csv │ ├── zone-PURE-A.csv │ ├── zone-PURE-B.csv │ ├── zone-VNX-A.csv │ ├── zone-VNX-B.csv │ ├── zone-srv-A.csv │ └── zone-srv-B.csv ├── SSH-demo-run-cfg-ANY.ps1 ├── SSH-demo-run-cfg-demoN5k01.ps1 ├── SSH-demo-show-vlan-demoN5k01.ps1 ├── UCS │ ├── MACpool.csv │ ├── ORG.csv │ ├── UUIDPool.csv │ ├── VLAN-add.csv │ ├── VLAN-add2nictmpl.csv │ ├── VLAN.csv │ ├── add-MACpool.ps1 │ ├── add-ORG.ps1 │ ├── add-UUIDpool.ps1 │ ├── add-VLAN.ps1 │ ├── add-additional-VLANs.ps1 │ ├── delete-ORG.ps1 │ ├── delete-VLAN.ps1 │ ├── delete-additional-VLANs.ps1 │ └── demoConnect.ps1 ├── demoConnect.ps1 └── demoVars.psm1 ├── PSHELL profile └── Microsoft.PowerShell_profile.ps1 ├── README.md ├── SSH-Sessions ├── Renci.SshNet.dll ├── Renci.SshNet.zip ├── SSH-Sessions.psd1 ├── SSH-Sessions.psm1 ├── SSH-Sessions.zip ├── SSH-SessionsPSv3.zip └── load-SSH.ps1 └── XML ├── LAN ├── add-HSRP.xml ├── add-L3-VLAN.xml ├── add-VLAN.xml ├── delete-L3-VLAN.xml ├── delete-VLAN.xml ├── show-VLAN-ID.xml ├── show-VLAN.XML └── show-run.xml └── SAN ├── SAN-activate-zoneset.xml ├── SAN-add-device-alias.xml ├── SAN-add-zone-member.xml ├── SAN-add-zone-with-members.xml ├── SAN-add-zone.xml ├── SAN-cfg-zoneset.xml ├── SAN-commit-zone.xml ├── SAN-del-zoneset.xml └── SAN-flogi-db.xml /Examples/02-demo1.ps1: -------------------------------------------------------------------------------- 1 | $var1 = "Hello World!" 2 | 3 | $var2 = 100 4 | 5 | $csvFile1 = read-Host -Prompt "Input CSV file: " 6 | 7 | $dlgTitle = "Select CSV file" 8 | $dlgDir = "c:\Users\mrobas\Dropbox\Blogs, Presentations, Social, Marketing\2017\PowerShell for Network Engineers\Demos\" 9 | $dlgFilter = "CSV files (*.csv)|*.csv" 10 | 11 | $csvFile2 = Read-OpenFileDialog -WindowTitle $dlgTitle -InitialDirectory $dlgDir -Filter $dlgFilter 12 | if (![string]::IsNullOrEmpty($csvFile2)) 13 | { Write-Host "You've selected the file: $csvFile2" } 14 | else 15 | { "You did not select a file." } 16 | -------------------------------------------------------------------------------- /Examples/02-demo2.ps1: -------------------------------------------------------------------------------- 1 | $global:var1 = "Hello World!" 2 | 3 | $global:var2 = 100 4 | 5 | $global:csvFile1 = read-Host -Prompt "Input CSV file: " 6 | 7 | $dlgTitle = "Select CSV file" 8 | $dlgDir = "c:\Users\mrobas\Dropbox\Blogs, Presentations, Social, Marketing\2017\PowerShell for Network Engineers\Demos\" 9 | $dlgFilter = "CSV files (*.csv)|*.csv" 10 | 11 | $global:csvFile2 = Read-OpenFileDialog -WindowTitle $dlgTitle -InitialDirectory $dlgDir -Filter $dlgFilter 12 | if (![string]::IsNullOrEmpty($csvFile2)) 13 | { Write-Host "You've selected the file: $csvFile2" } 14 | else 15 | { "You did not select a file." } 16 | -------------------------------------------------------------------------------- /Examples/02-demo3.ps1: -------------------------------------------------------------------------------- 1 | $global:csv1="02-1-wrong delimiter.csv" 2 | $global:csvList1=Import-Csv $csv1 3 | -------------------------------------------------------------------------------- /Examples/02-demo4.ps1: -------------------------------------------------------------------------------- 1 | $global:csv1="02-2-proper delimiter.csv" 2 | $global:csvList1=Import-Csv $csv1 3 | -------------------------------------------------------------------------------- /Examples/02-demo5.ps1: -------------------------------------------------------------------------------- 1 | $dlgTitle = "Select CSV file" 2 | $dlgDir = "c:\Users\mrobas\Dropbox\Blogs, Presentations, Social, Marketing\2017\PowerShell for Network Engineers\Demos\" 3 | $dlgFilter = "CSV files (*.csv)|*.csv" 4 | 5 | $csvtmp = Read-OpenFileDialog -WindowTitle $dlgTitle -InitialDirectory $dlgDir -Filter $dlgFilter 6 | $global:csv25=Import-Csv $csvtmp -Delimiter ";" -verbose 7 | 8 | $csv25 -------------------------------------------------------------------------------- /Examples/02-demo6.ps1: -------------------------------------------------------------------------------- 1 | $dtstr=get-dtstr 2 | $outfile="hcInfra_ESXi-"+$dtstr+".csv" 3 | 4 | Get-VMHost -Server $vcInfra | 5 | Select @{N="ESXi";E={$_.Name}}, 6 | @{N="Connection State";E={$_.ConnectionState}} , 7 | @{N="CPU";E={$_.NumCpu}} , 8 | @{N="Memory";E={$_.MemoryTotalGB}} , 9 | @{N="Version";E={$_.Version}} | 10 | Export-Csv $outfile -Delimiter ";" -NoTypeInformation -------------------------------------------------------------------------------- /Examples/CAPTURE-switch-cmd-list.csv: -------------------------------------------------------------------------------- 1 | Cmd 2 | sh run 3 | sh ver 4 | sh int brief 5 | sh int status 6 | sh cdp neighbor 7 | sh cdp neighbor detail 8 | sh ip int brief 9 | sh ip route 10 | sh vlan -------------------------------------------------------------------------------- /Examples/CAPTURE-switch-list.csv: -------------------------------------------------------------------------------- 1 | name,mgmtIP 2 | demoN5k01,demoN5K01.flashstack.local 3 | demoN5k02,demoN5K02.flashstack.local 4 | demoLEAF11,demoLEAF11.flashstack.local 5 | demoLEAF12,demoLEAF12.flashstack.local 6 | demoSPINE11,demoSPINE11.flashstack.local 7 | demoSPINE12,demoSPINE12.flashstack.local -------------------------------------------------------------------------------- /Examples/CAPTURE-switch.ps1: -------------------------------------------------------------------------------- 1 | # switch list input file 2 | $csvListSw = "CAPTURE-switch-list.csv" 3 | 4 | # command list input file 5 | $csvListCmd = "CAPTURE-switch-cmd-list.csv" 6 | 7 | $captureDir = $workDir+"capture\" 8 | 9 | #Load Lists 10 | $csvSW=Import-Csv $csvListSw 11 | $csvCMD=Import-Csv $csvListCmd 12 | 13 | foreach($item in $csvSW) 14 | { 15 | $dtstr=get-dtstr 16 | 17 | New-SshSession -ComputerName $item.mgmtIP -username $devUsr -password $devPwd 18 | $tmpsw=$item.name 19 | echo-task "Capturing on $tmpsw" 20 | 21 | foreach($item1 in $csvCMD) 22 | { 23 | " - "+$item1.Cmd 24 | $cmd_output=Invoke-SshCommand -ComputerName $item.mgmtIP -Command $item1.cmd -Quiet 25 | 26 | $outfile=$captureDir+$item.name+"-"+$item1.cmd+" - "+$dtstr+".txt" 27 | out-file $outfile -encoding ascii 28 | $cmd_output | out-file $outfile -encoding ascii -append 29 | } 30 | Remove-SshSession -RemoveAll 31 | } -------------------------------------------------------------------------------- /Examples/CFG-add-vlans.ps1: -------------------------------------------------------------------------------- 1 | ##### 2 | # Load input files 3 | # CSV-VLANlist 4 | ##### 5 | Import-module .\demoVars.psm1 6 | $listVLAN=Import-CSV $workDir"CSV-VLAN-list.csv" 7 | $listSW=Import-CSV $workDir"CSV-LANSW-list.csv" 8 | 9 | echo-inprogress "Adding VLANs to switches" 10 | foreach($tmpsw in $listSW) 11 | { 12 | $tmpswname=$tmpsw.name 13 | echo-inprogress "Switch $tmpswname" 14 | foreach($tmpvlan in $listVLAN) 15 | { 16 | $tmpvlanname=$tmpvlan.name 17 | $funcRes=LAN-add-vlan -XMLurl $tmpsw.url -XMLcred $restCredentials -vlanname $tmpvlan.Name -vlanid $tmpvlan.VLAN 18 | switch ($funcRes) 19 | { 20 | 0 { echo-task ">> Added VLAN $tmpvlanname" } 21 | 1 { echo-infoNO ">> Skipped VLAN $tmpvlanname - already present"} 22 | 9 { echo-error ">> Error adding VLAN $tmpvlanname"} 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Examples/CFG-delete-vlans.ps1: -------------------------------------------------------------------------------- 1 | ##### 2 | # Load input files 3 | # CSV-VLANlist 4 | ##### 5 | Import-module .\demoVars.psm1 6 | $listVLAN=Import-CSV $workDir"CSV-VLAN-list.csv" 7 | $listSW=Import-CSV $workDir"CSV-LANSW-list.csv" 8 | 9 | echo-inprogress "Deleting VLANs from switches" 10 | foreach($tmpsw in $listSW) 11 | { 12 | $tmpswname=$tmpsw.name 13 | echo-inprogress "Switch $tmpswname" 14 | foreach($tmpvlan in $listVLAN) 15 | { 16 | $tmpvlanname=$tmpvlan.name 17 | $funcRes=LAN-delete-vlan -XMLurl $tmpsw.url -XMLcred $restCredentials -vlanid $tmpvlan.VLAN 18 | switch ($funcRes) 19 | { 20 | 0 { echo-task ">> Deleted VLAN $tmpvlanname" } 21 | 1 { echo-infoNO ">> Skipped VLAN $tmpvlanname - not present"} 22 | 9 { echo-error ">> Error deleting VLAN $tmpvlanname"} 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Examples/CSV-LANSW-list.csv: -------------------------------------------------------------------------------- 1 | url,name 2 | http://demoN5K01.flashstack.local:8088/ins,demoN5K01.flashstack.local 3 | http://demoN5K02.flashstack.local:8088/ins,demoN5K02.flashstack.local -------------------------------------------------------------------------------- /Examples/CSV-VLAN-list.csv: -------------------------------------------------------------------------------- 1 | Name,VLAN 2 | demo3001,3001 3 | demo3002,3002 4 | demo3003,3003 5 | demo3004,3004 -------------------------------------------------------------------------------- /Examples/HTTP server/HTTP-web-srv.ps1: -------------------------------------------------------------------------------- 1 | function Load-Packages 2 | { 3 | param ([string] $directory = 'Packages') 4 | $assemblies = Get-ChildItem $directory -Recurse -Filter '*.dll' | Select -Expand FullName 5 | foreach ($assembly in $assemblies) { [System.Reflection.Assembly]::LoadFrom($assembly) } 6 | } 7 | 8 | Load-Packages 9 | 10 | $routes = @{ 11 | "/LOOPBACK" = { return 'WEB LOOPBACK - ALIVE' } 12 | } 13 | 14 | $url = 'http://localhost:8888/' 15 | $listener = New-Object System.Net.HttpListener 16 | $listener.Prefixes.Add($url) 17 | $listener.Start() 18 | 19 | Write-Host "Listening at $url..." 20 | 21 | while ($listener.IsListening) 22 | { 23 | $context = $listener.GetContext() 24 | $requestUrl = $context.Request.Url 25 | $response = $context.Response 26 | 27 | Write-Host '' 28 | Write-Host "> $requestUrl" 29 | 30 | $localPath = $requestUrl.LocalPath 31 | $route = $routes.Get_Item($requestUrl.LocalPath) 32 | 33 | if ($route -eq $null) 34 | { 35 | $response.StatusCode = 404 36 | } 37 | else 38 | { 39 | $content = & $route 40 | $buffer = [System.Text.Encoding]::UTF8.GetBytes($content) 41 | $response.ContentLength64 = $buffer.Length 42 | $response.OutputStream.Write($buffer, 0, $buffer.Length) 43 | $response 44 | } 45 | 46 | $response.Close() 47 | 48 | $responseStatus = $response.StatusCode 49 | Write-Host "< $responseStatus" 50 | } -------------------------------------------------------------------------------- /Examples/HTTP server/HTTP-web-test.ps1: -------------------------------------------------------------------------------- 1 | ##### 2 | # 3 | # Test HTTP 4 | # Output - save result to file 5 | # 6 | ##### 7 | 8 | #$captureDir = $workDir+"http\" 9 | 10 | $dtstr=Get-Date -format "yyyMMdd-HHmmss" 11 | 12 | $dstURI = "http://demomgmt1.flashstack.local:80/LOOPBACK" 13 | $outFile = $captureDir+"WEB-TEST-"+$dtstr.ToString()+".csv" 14 | 15 | out-file $outFile -encoding ascii 16 | out-file $outFile -encoding ascii -append -InputObject "##### HTTP test result" 17 | "Year;Month;Day;Hour;Minute;Second;Msec;RTT" | out-file $outFile -encoding ascii -append 18 | 19 | while(1) 20 | { 21 | $dateNow = Get-Date 22 | $result = Measure-Command { $request = Invoke-WebRequest -Uri $dstURI } 23 | $dateNow.Year.ToString()+"."+$dateNow.Month.ToString()+"."+$dateNow.Day.ToString()+"-"+$dateNow.Hour.ToString()+":"+$dateNow.Minute.ToString()+":"+$dateNow.Second.ToString()+"::"+$dateNow.Millisecond.ToString()+" >> "+$result.TotalMilliseconds 24 | $dateNow.Year.ToString()+";"+$dateNow.Month.ToString()+";"+$dateNow.Day.ToString()+";"+$dateNow.Hour.ToString()+";"+$dateNow.Minute.ToString()+";"+$dateNow.Second.ToString()+";"+$dateNow.Millisecond.ToString()+";"+$result.TotalMilliseconds | out-file $outFile -encoding ascii -append 25 | start-sleep -seconds 5 26 | } -------------------------------------------------------------------------------- /Examples/PING-test-list.csv: -------------------------------------------------------------------------------- 1 | name,dstIP 2 | demoN5k01,demoN5K01.flashstack.local 3 | demoN5k02,demoN5K02.flashstack.local 4 | demoLEAF11,demoLEAF11.flashstack.local 5 | demoLEAF12,demoLEAF12.flashstack.local 6 | demoSPINE11,demoSPINE11.flashstack.local 7 | demoSPINE12,demoSPINE12.flashstack.local 8 | failSW,10.176.109.233 -------------------------------------------------------------------------------- /Examples/PING-test-list.ps1: -------------------------------------------------------------------------------- 1 | ##### 2 | # 3 | # Test with ping 4 | # Input file with IP destinations 5 | # Output - save result to file 6 | # 7 | ##### 8 | 9 | $captureDir = $workDir+"ping\" 10 | $dtstr=get-dtstr 11 | $csvFile = "PING-test-list.csv" 12 | $csvList=Import-Csv $csvFile 13 | 14 | # Set output file 15 | $outFile = $captureDir+"CONN-VERIFY-"+$dtstr.ToString()+".csv" 16 | 17 | # Set buffer size in bytes 18 | $bufSize = "32" 19 | 20 | 21 | # create output file 22 | out-file $outFile -encoding ascii 23 | out-file $outFile -encoding ascii -append -InputObject "##### Ping test result" 24 | "Dst Name,Dst IP,Success" | out-file $outFile -encoding ascii -append 25 | 26 | 27 | foreach($item in $csvList) 28 | { 29 | $PingRes = Test-Connection -quiet -ComputerName $item.dstIP -Count 3 -BufferSize $bufSize -ErrorAction 0 30 | if($PingRes) {$pingMsg="OK"} else {$pingMsg="FAIL"} 31 | $item.name+";"+$item.dstIP+";"+$pingMsg | out-file $outFile -encoding ascii -append 32 | 33 | $echoRes=$item.name+" - "+$pingMsg 34 | if ($PingRes) { echo-task $echoRes } else { echo-infoNO $echoRes } 35 | } -------------------------------------------------------------------------------- /Examples/PING-test-single.ps1: -------------------------------------------------------------------------------- 1 | ##### 2 | # 3 | # Test PING 4 | # Output - save result to file 5 | # 6 | ##### 7 | 8 | $captureDir = $workDir+"ping\" 9 | 10 | $dtstr=get-dtstr 11 | 12 | $dstIP = "www.cisco.com" 13 | $outFile = $captureDir+"PING-TEST-"+$dtstr.ToString()+".csv" 14 | 15 | out-file $outFile -encoding ascii 16 | "Year;Month;Day;Hour;Minute;Second;Msec;RTT" | out-file $outFile -encoding ascii -append 17 | 18 | while(1) 19 | { 20 | $dateNow = Get-Date 21 | $result = test-netconnection $dstIP 22 | $dateNow.Year.ToString()+"."+$dateNow.Month.ToString()+"."+$dateNow.Day.ToString()+"-"+$dateNow.Hour.ToString()+":"+$dateNow.Minute.ToString()+":"+$dateNow.Second.ToString()+"::"+$dateNow.Millisecond.ToString()+" >> "+$result.PingReplyDetails.RoundTripTime 23 | $dateNow.Year.ToString()+";"+$dateNow.Month.ToString()+";"+$dateNow.Day.ToString()+";"+$dateNow.Hour.ToString()+";"+$dateNow.Minute.ToString()+";"+$dateNow.Second.ToString()+";"+$dateNow.Millisecond.ToString()+";"+$result.PingReplyDetails.RoundTripTime | out-file $outFile -encoding ascii -append 24 | start-sleep -seconds 5 25 | } -------------------------------------------------------------------------------- /Examples/SAN/MDS-devalias-srv.ps1: -------------------------------------------------------------------------------- 1 | <##### 2 | # Parameters 3 | # csvList - input CSV file with list of host alias names and WWPNs 4 | # 5 | # Output 6 | # DevAlias.txt file 7 | # 8 | #####> 9 | 10 | #Get date & time 11 | $today = get-date 12 | $day = $today.Day 13 | $mth = $today.Month 14 | $year = $today.Year 15 | $hour = $today.Hour 16 | $min = $today.Minute 17 | $sec = $today.Second 18 | $date = "$year-$mth-$day-$hour$min$sec" 19 | 20 | #### Fabric A 21 | #Server PWWN list 22 | # $csvLi st = Read-Host -Prompt "PWWN list: " 23 | $csvList = "wwpnUCS-A.csv" 24 | $listCSV=Import-Csv $csvList 25 | 26 | # $outFile = Read-Host -Prompt "Output file: " 27 | $outFile = $date+"-devalias-wwpnUCS-A.txt" 28 | 29 | out-file $outFile -encoding ascii 30 | # out-file $outFile -encoding ascii -append -InputObject "! $date Device Alias Configuration" 31 | "device-alias database" | out-file $outFile -encoding ascii -append 32 | foreach($item in $listCSV) 33 | { 34 | "device-alias name "+$item.Port+" pwwn "+$item.WWPN | out-file $outFile -encoding ascii -append 35 | } 36 | "";"device-alias commit" | out-file $outFile -encoding ascii -append 37 | 38 | #### Fabric B 39 | #Server PWWN list 40 | $csvList = "wwpnUCS-B.csv" 41 | $listCSV=Import-Csv $csvList 42 | 43 | # $outFile = Read-Host -Prompt "Output file: " 44 | $outFile = $date+"-devalias-wwpnUCS-B.txt" 45 | 46 | out-file $outFile -encoding ascii 47 | # out-file $outFile -encoding ascii -append -InputObject "! $date Device Alias Configuration" 48 | "device-alias database" | out-file $outFile -encoding ascii -append 49 | foreach($item in $listCSV) 50 | { 51 | "device-alias name "+$item.Port+" pwwn "+$item.WWPN | out-file $outFile -encoding ascii -append 52 | } 53 | "";"device-alias commit" | out-file $outFile -encoding ascii -append -------------------------------------------------------------------------------- /Examples/SAN/MDS-zoning-PURE-2FC-A.ps1: -------------------------------------------------------------------------------- 1 | #### change to enter zoneset name !!!! 2 | 3 | <#### 4 | # Parameters 5 | # csvList - input CSV file with list of host alias names and WWPNs 6 | # 7 | # Output 8 | # DevAlias.txt file 9 | # 10 | #####> 11 | 12 | ###Get date & time 13 | $today = get-date 14 | $day = $today.Day 15 | $mth = $today.Month 16 | $year = $today.Year 17 | $hour = $today.Hour 18 | $min = $today.Minute 19 | $sec = $today.Second 20 | $date = "$year-$mth-$day-$hour$min$sec" 21 | 22 | ###Collect input parameters 23 | # $csvStorageList=Read-Host -Prompt "Storage list:" 24 | # $csvServerList=Read-Host -Prompt "Server HBA list:" 25 | # $fabricVSAN=Read-host -Prompt "VSAN:" 26 | # $zoneset=Read-host -Prompt "Zoneset:" 27 | # $outFile = Read-Host -Prompt "Output zone cfg file: " 28 | # $outFile2 = Read-Host -Prompt "Output zoneset cfg file: " 29 | 30 | $csvStorageList="zone-PURE-A.csv" 31 | $csvServerList="zone-srv-A.csv" 32 | 33 | $fabricVSAN="11" 34 | $zoneset="VSAN11ZONESET" 35 | $outFile = $date+"-PURE-zone-11.txt" 36 | $outFile2 = $date+"-PURE-zoneset-11.txt" 37 | 38 | 39 | ###Load lists 40 | $listStorage=Import-Csv $csvStorageList 41 | $listServer=Import-Csv $csvServerList 42 | 43 | out-file $outFile -encoding ascii 44 | 45 | out-file $outFile2 -encoding ascii 46 | "zoneset name "+$zoneset+" vsan "+$fabricVSAN.ToString() | out-file $outFile2 -encoding ascii -append 47 | 48 | ###Zones 49 | foreach($itemStorage in $listStorage) 50 | { 51 | foreach($itemServer in $listServer) 52 | { 53 | #create zone 54 | "zone name "+$itemStorage.Name+"--"+$itemServer.Name+" vsan "+$fabricVSAN.ToString() | out-file $outFile -encoding ascii -append 55 | " member device-alias "+$itemServer.DevAlias | out-file $outFile -encoding ascii -append 56 | " member device-alias "+$itemStorage.DevAlias1 | out-file $outFile -encoding ascii -append 57 | " member device-alias "+$itemStorage.DevAlias2 | out-file $outFile -encoding ascii -append 58 | "!" | out-file $outFile -encoding ascii -append 59 | 60 | #add member to zoneset 61 | " member "+$itemStorage.Name+"--"+$itemServer.Name | out-file $outFile2 -encoding ascii -append 62 | } 63 | #commit zones 64 | "zone commit vsan "+$fabricVSAN.ToString() | out-file $outFile -encoding ascii -append 65 | "!" | out-file $outFile -encoding ascii -append 66 | 67 | #commit zoneset 68 | # "zone commit vsan "+$fabricVSAN.ToString() | out-file $outFile2 -encoding ascii -append 69 | # "!" | out-file $outFile2 -encoding ascii -append 70 | } 71 | 72 | #Commit and activat zoneset 73 | "zoneset activate name "+$zoneset+" vsan "+$fabricVSAN.ToString() | out-file $outFile2 -encoding ascii -append 74 | "zone commit vsan "+$fabricVSAN.ToString() | out-file $outFile2 -encoding ascii -append -------------------------------------------------------------------------------- /Examples/SAN/MDS-zoning-PURE-2FC-B.ps1: -------------------------------------------------------------------------------- 1 | #### change to enter zoneset name !!!! 2 | 3 | <#### 4 | # Parameters 5 | # csvList - input CSV file with list of host alias names and WWPNs 6 | # 7 | # Output 8 | # DevAlias.txt file 9 | # 10 | #####> 11 | 12 | ###Get date & time 13 | $today = get-date 14 | $day = $today.Day 15 | $mth = $today.Month 16 | $year = $today.Year 17 | $hour = $today.Hour 18 | $min = $today.Minute 19 | $sec = $today.Second 20 | $date = "$year-$mth-$day-$hour$min$sec" 21 | 22 | ###Collect input parameters 23 | # $csvStorageList=Read-Host -Prompt "Storage list:" 24 | # $csvServerList=Read-Host -Prompt "Server HBA list:" 25 | # $fabricVSAN=Read-host -Prompt "VSAN:" 26 | # $zoneset=Read-host -Prompt "Zoneset:" 27 | # $outFile = Read-Host -Prompt "Output zone cfg file: " 28 | # $outFile2 = Read-Host -Prompt "Output zoneset cfg file: " 29 | 30 | $csvStorageList="zone-PURE-B.csv" 31 | $csvServerList="zone-srv-B.csv" 32 | 33 | $fabricVSAN="21" 34 | $zoneset="VSAN21ZONESET" 35 | $outFile = $date+"-PURE-zone-21.txt" 36 | $outFile2 = $date+"-PURE-zoneset-21.txt" 37 | 38 | 39 | ###Load lists 40 | $listStorage=Import-Csv $csvStorageList 41 | $listServer=Import-Csv $csvServerList 42 | 43 | 44 | out-file $outFile -encoding ascii 45 | 46 | out-file $outFile2 -encoding ascii 47 | "zoneset name "+$zoneset+" vsan "+$fabricVSAN.ToString() | out-file $outFile2 -encoding ascii -append 48 | 49 | ###Zones 50 | foreach($itemStorage in $listStorage) 51 | { 52 | foreach($itemServer in $listServer) 53 | { 54 | #create zone 55 | "zone name "+$itemStorage.Name+"--"+$itemServer.Name+" vsan "+$fabricVSAN.ToString() | out-file $outFile -encoding ascii -append 56 | " member device-alias "+$itemServer.DevAlias | out-file $outFile -encoding ascii -append 57 | " member device-alias "+$itemStorage.DevAlias1 | out-file $outFile -encoding ascii -append 58 | " member device-alias "+$itemStorage.DevAlias2 | out-file $outFile -encoding ascii -append 59 | "!" | out-file $outFile -encoding ascii -append 60 | 61 | #add member to zoneset 62 | " member "+$itemStorage.Name+"--"+$itemServer.Name | out-file $outFile2 -encoding ascii -append 63 | } 64 | #commit zones 65 | "zone commit vsan "+$fabricVSAN.ToString() | out-file $outFile -encoding ascii -append 66 | "!" | out-file $outFile -encoding ascii -append 67 | 68 | #commit zoneset 69 | # "zone commit vsan "+$fabricVSAN.ToString() | out-file $outFile2 -encoding ascii -append 70 | # "!" | out-file $outFile2 -encoding ascii -append 71 | } 72 | 73 | #Commit and activat zoneset 74 | "zoneset activate name "+$zoneset+" vsan "+$fabricVSAN.ToString() | out-file $outFile2 -encoding ascii -append 75 | "zone commit vsan "+$fabricVSAN.ToString() | out-file $outFile2 -encoding ascii -append -------------------------------------------------------------------------------- /Examples/SAN/MDS-zoning-VNX-4FC-A.ps1: -------------------------------------------------------------------------------- 1 | #### change to enter zoneset name !!!! 2 | 3 | <#### 4 | # Parameters 5 | # csvList - input CSV file with list of host alias names and WWPNs 6 | # 7 | # Output 8 | # DevAlias.txt file 9 | # 10 | #####> 11 | 12 | ###Get date & time 13 | $today = get-date 14 | $day = $today.Day 15 | $mth = $today.Month 16 | $year = $today.Year 17 | $hour = $today.Hour 18 | $min = $today.Minute 19 | $sec = $today.Second 20 | $date = "$year-$mth-$day-$hour$min$sec" 21 | 22 | ###Collect input parameters 23 | #$csvStorageList=Read-Host -Prompt "Storage list:" 24 | #$csvServerList=Read-Host -Prompt "Server HBA list:" 25 | 26 | $csvStorageList="zone-VNX-A.csv" 27 | $csvServerList="zone-srv-A.csv" 28 | 29 | $fabricVSAN="11" 30 | $zoneset="VSAN11ZONESET" 31 | $outFile = $date+"-VNX-zone-11.txt" 32 | $outFile2 = $date+"-VNX-zoneset-11.txt" 33 | 34 | ###Load lists 35 | $listStorage=Import-Csv $csvStorageList 36 | $listServer=Import-Csv $csvServerList 37 | 38 | 39 | 40 | out-file $outFile -encoding ascii 41 | 42 | out-file $outFile2 -encoding ascii 43 | "zoneset name "+$zoneset+" vsan "+$fabricVSAN.ToString() | out-file $outFile2 -encoding ascii -append 44 | 45 | ###Zones 46 | foreach($itemStorage in $listStorage) 47 | { 48 | foreach($itemServer in $listServer) 49 | { 50 | #create zone 51 | "zone name "+$itemStorage.Name+"--"+$itemServer.Name+" vsan "+$fabricVSAN.ToString() | out-file $outFile -encoding ascii -append 52 | " member device-alias "+$itemServer.DevAlias | out-file $outFile -encoding ascii -append 53 | " member device-alias "+$itemStorage.DevAlias1 | out-file $outFile -encoding ascii -append 54 | " member device-alias "+$itemStorage.DevAlias2 | out-file $outFile -encoding ascii -append 55 | " member device-alias "+$itemStorage.DevAlias3 | out-file $outFile -encoding ascii -append 56 | " member device-alias "+$itemStorage.DevAlias4 | out-file $outFile -encoding ascii -append 57 | "!" | out-file $outFile -encoding ascii -append 58 | #add member to zoneset 59 | " member "+$itemStorage.Name+"--"+$itemServer.Name | out-file $outFile2 -encoding ascii -append 60 | #commit zones 61 | "zone commit vsan "+$fabricVSAN.ToString() | out-file $outFile -encoding ascii -append 62 | "!" | out-file $outFile -encoding ascii -append 63 | } 64 | } 65 | 66 | #Commit and activat zoneset 67 | "zoneset activate name "+$zoneset+" vsan "+$fabricVSAN.ToString() | out-file $outFile2 -encoding ascii -append 68 | "zone commit vsan "+$fabricVSAN.ToString() | out-file $outFile2 -encoding ascii -append -------------------------------------------------------------------------------- /Examples/SAN/MDS-zoning-VNX-4FC-B.ps1: -------------------------------------------------------------------------------- 1 | #### change to enter zoneset name !!!! 2 | 3 | <#### 4 | # Parameters 5 | # csvList - input CSV file with list of host alias names and WWPNs 6 | # 7 | # Output 8 | # DevAlias.txt file 9 | # 10 | #####> 11 | 12 | ###Get date & time 13 | $today = get-date 14 | $day = $today.Day 15 | $mth = $today.Month 16 | $year = $today.Year 17 | $hour = $today.Hour 18 | $min = $today.Minute 19 | $sec = $today.Second 20 | $date = "$year-$mth-$day-$hour$min$sec" 21 | 22 | ###Collect input parameters 23 | #$csvStorageList=Read-Host -Prompt "Storage list:" 24 | #$csvServerList=Read-Host -Prompt "Server HBA list:" 25 | $csvStorageList="zone-VNX-B.csv" 26 | $csvServerList="zone-srv-B.csv" 27 | 28 | $fabricVSAN="21" 29 | $zoneset="VSAN21ZONESET" 30 | $outFile = $date+"-VNX-zone-21.txt" 31 | $outFile2 = $date+"-VNX-zoneset-21.txt" 32 | 33 | ###Load lists 34 | $listStorage=Import-Csv $csvStorageList 35 | $listServer=Import-Csv $csvServerList 36 | 37 | 38 | 39 | out-file $outFile -encoding ascii 40 | 41 | out-file $outFile2 -encoding ascii 42 | "zoneset name "+$zoneset+" vsan "+$fabricVSAN.ToString() | out-file $outFile2 -encoding ascii -append 43 | 44 | ###Zones 45 | foreach($itemStorage in $listStorage) 46 | { 47 | foreach($itemServer in $listServer) 48 | { 49 | #create zone 50 | "zone name "+$itemStorage.Name+"--"+$itemServer.Name+" vsan "+$fabricVSAN.ToString() | out-file $outFile -encoding ascii -append 51 | " member device-alias "+$itemServer.DevAlias | out-file $outFile -encoding ascii -append 52 | " member device-alias "+$itemStorage.DevAlias1 | out-file $outFile -encoding ascii -append 53 | " member device-alias "+$itemStorage.DevAlias2 | out-file $outFile -encoding ascii -append 54 | " member device-alias "+$itemStorage.DevAlias3 | out-file $outFile -encoding ascii -append 55 | " member device-alias "+$itemStorage.DevAlias4 | out-file $outFile -encoding ascii -append 56 | "!" | out-file $outFile -encoding ascii -append 57 | #add member to zoneset 58 | " member "+$itemStorage.Name+"--"+$itemServer.Name | out-file $outFile2 -encoding ascii -append 59 | #commit zones 60 | "zone commit vsan "+$fabricVSAN.ToString() | out-file $outFile -encoding ascii -append 61 | "!" | out-file $outFile -encoding ascii -append 62 | } 63 | } 64 | 65 | #Commit and activat zoneset 66 | "zoneset activate name "+$zoneset+" vsan "+$fabricVSAN.ToString() | out-file $outFile2 -encoding ascii -append 67 | "zone commit vsan "+$fabricVSAN.ToString() | out-file $outFile2 -encoding ascii -append -------------------------------------------------------------------------------- /Examples/SAN/wwpnUCS-A.csv: -------------------------------------------------------------------------------- 1 | WWPN,Port 2 | 20:02:21:25:b5:a0:91:01,srv1-hbaA0 3 | 20:02:21:25:b5:a1:91:01,srv1-hbaA1 4 | 20:02:21:25:b5:a0:91:02,srv2-hbaA0 5 | 20:02:21:25:b5:a1:91:02,srv2-hbaA1 6 | 20:02:22:25:b5:a0:91:01,srv3-hbaA0 7 | 20:02:22:25:b5:a1:91:01,srv3-hbaA1 8 | 20:02:22:25:b5:a0:91:02,srv4-hbaA0 9 | 20:02:22:25:b5:a1:91:02,srv4-hbaA1 10 | 20:02:23:25:b5:a0:91:01,srv5-hbaA0 11 | 20:02:23:25:b5:a1:91:01,srv5-hbaA1 12 | 20:02:23:25:b5:a0:91:02,srv6-hbaA0 13 | 20:02:23:25:b5:a1:91:02,srv6-hbaA1 14 | 20:02:24:25:b5:a0:91:01,srv7-hbaA0 15 | 20:02:24:25:b5:a1:91:01,srv7-hbaA1 16 | 20:02:24:25:b5:a0:91:02,srv8-hbaA0 17 | 20:02:24:25:b5:a1:91:02,srv8-hbaA1 18 | -------------------------------------------------------------------------------- /Examples/SAN/wwpnUCS-B.csv: -------------------------------------------------------------------------------- 1 | WWPN,Port 2 | 20:02:21:25:b5:b0:91:01,srv1-hbaB0 3 | 20:02:21:25:b5:b1:91:01,srv1-hbaB1 4 | 20:02:21:25:b5:b0:91:02,srv2-hbaB0 5 | 20:02:21:25:b5:b1:91:02,srv2-hbaB1 6 | 20:02:22:25:b5:b0:91:01,srv3-hbaB0 7 | 20:02:22:25:b5:b1:91:01,srv3-hbaB1 8 | 20:02:22:25:b5:b0:91:02,srv4-hbaB0 9 | 20:02:22:25:b5:b1:91:02,srv4-hbaB1 10 | 20:02:23:25:b5:b0:91:01,srv5-hbaB0 11 | 20:02:23:25:b5:b1:91:01,srv5-hbaB1 12 | 20:02:23:25:b5:b0:91:02,srv6-hbaB0 13 | 20:02:23:25:b5:b1:91:02,srv6-hbaB1 14 | 20:02:24:25:b5:b0:91:01,srv7-hbaB0 15 | 20:02:24:25:b5:b1:91:01,srv7-hbaB1 16 | 20:02:24:25:b5:b0:91:02,srv8-hbaB0 17 | 20:02:24:25:b5:b1:91:02,srv8-hbaB1 -------------------------------------------------------------------------------- /Examples/SAN/zone-PURE-A.csv: -------------------------------------------------------------------------------- 1 | Name,DevAlias1,DevAlias2 2 | hcPure01,hcPure01-CT0FC0,hcPure01-CT1FC0 -------------------------------------------------------------------------------- /Examples/SAN/zone-PURE-B.csv: -------------------------------------------------------------------------------- 1 | Name,DevAlias1,DevAlias2 2 | hcPure01,hcPure01-CT0FC1,hcPure01-CT1FC1 -------------------------------------------------------------------------------- /Examples/SAN/zone-VNX-A.csv: -------------------------------------------------------------------------------- 1 | Name,DevAlias1,DevAlias2,DevAlias3,DevAlias4 2 | VNXa,primVNX-SPA0,primVNX-SPA1,primVNX-SPB0,primVNX-SPB1 -------------------------------------------------------------------------------- /Examples/SAN/zone-VNX-B.csv: -------------------------------------------------------------------------------- 1 | Name,DevAlias1,DevAlias2,DevAlias3,DevAlias4 2 | VNXb,primVNX-SPA2,primVNX-SPA3,primVNX-SPB2,primVNX-SPB3 -------------------------------------------------------------------------------- /Examples/SAN/zone-srv-A.csv: -------------------------------------------------------------------------------- 1 | Name,DevAlias 2 | srv1-hbaA0,srv1-hbaA0 3 | srv1-hbaA1,srv1-hbaA1 4 | srv2-hbaA0,srv2-hbaA0 5 | srv2-hbaA1,srv2-hbaA1 6 | srv3-hbaA0,srv3-hbaA0 7 | srv3-hbaA1,srv3-hbaA1 8 | srv4-hbaA0,srv4-hbaA0 9 | srv4-hbaA1,srv4-hbaA1 10 | srv5-hbaA0,srv5-hbaA0 11 | srv5-hbaA1,srv5-hbaA1 12 | srv6-hbaA0,srv6-hbaA0 13 | srv6-hbaA1,srv6-hbaA1 14 | srv7-hbaA0,srv7-hbaA0 15 | srv7-hbaA1,srv7-hbaA1 16 | srv8-hbaA0,srv8-hbaA0 17 | srv8-hbaA1,srv8-hbaA1 -------------------------------------------------------------------------------- /Examples/SAN/zone-srv-B.csv: -------------------------------------------------------------------------------- 1 | Name,DevAlias 2 | srv1-hbaB0,srv1-hbaB0 3 | srv1-hbaB1,srv1-hbaB1 4 | srv2-hbaB0,srv2-hbaB0 5 | srv2-hbaB1,srv2-hbaB1 6 | srv3-hbaB0,srv3-hbaB0 7 | srv3-hbaB1,srv3-hbaB1 8 | srv4-hbaB0,srv4-hbaB0 9 | srv4-hbaB1,srv4-hbaB1 10 | srv5-hbaB0,srv5-hbaB0 11 | srv5-hbaB1,srv5-hbaB1 12 | srv6-hbaB0,srv6-hbaB0 13 | srv6-hbaB1,srv6-hbaB1 14 | srv7-hbaB0,srv7-hbaB0 15 | srv7-hbaB1,srv7-hbaB1 16 | srv8-hbaB0,srv8-hbaB0 17 | srv8-hbaB1,srv8-hbaB1 -------------------------------------------------------------------------------- /Examples/SSH-demo-run-cfg-ANY.ps1: -------------------------------------------------------------------------------- 1 | Import-Module .\demoVars.psm1 2 | 3 | 4 | $devName=read-Host -Prompt "Hostname or IP: " 5 | $cmd1=read-Host -Prompt "Command: " 6 | $ssh1=New-SshSession -ComputerName $devName -Username $devUsr -Password $devPwd 7 | 8 | $cmd_output=Invoke-SshCommand -ComputerName $devName -Command $cmd1 -Quiet 9 | 10 | $dtstr=get-dtstr 11 | $outfile=$devName+"-"+$cmd1+$dtstr+".txt" 12 | $cmd_output | Out-File $outfile -------------------------------------------------------------------------------- /Examples/SSH-demo-run-cfg-demoN5k01.ps1: -------------------------------------------------------------------------------- 1 | Import-Module .\demoVars.psm1 2 | 3 | 4 | $devName="demoN5K01.flashstack.local" 5 | $ssh1=New-SshSession -ComputerName $devName -Username $devUsr -Password $devPwd 6 | 7 | $cmd_output=Invoke-SshCommand -ComputerName $devName -Command "show run" -Quiet 8 | 9 | $dtstr=get-dtstr 10 | $outfile="demoN5K01-run-cfg"+$dtstr+".txt" 11 | $cmd_output | Out-File $outfile -------------------------------------------------------------------------------- /Examples/SSH-demo-show-vlan-demoN5k01.ps1: -------------------------------------------------------------------------------- 1 | Import-Module .\demoVars.psm1 2 | 3 | 4 | $devName="demoN5K01.flashstack.local" 5 | $ssh1=New-SshSession -ComputerName $devName -Username $devUsr -Password $devPwd 6 | 7 | $cmd_output=Invoke-SshCommand -ComputerName $devName -Command "show vlan" -Quiet 8 | 9 | $dtstr=get-dtstr 10 | $outfile="demoN5K01-show-vlan"+$dtstr+".txt" 11 | $cmd_output | Out-File $outfile -------------------------------------------------------------------------------- /Examples/UCS/MACpool.csv: -------------------------------------------------------------------------------- 1 | Name,ss,f,t,Size,Org,vNIC,Template used,Comment,Order 2 | mpSrvMgmtA,0,a,1,2,Pod1,nicSrvMgmtA,ntSrvMgmtA,Mgmt fabric A for hosts,sequential 3 | mpSrvMgmtB,0,b,1,2,Pod1,nicSrvMgmtB,ntSrvMgmtB,Mgmt fabric B for hosts,sequential 4 | mpVMotion,99,c,1,2,Pod1,nicVMotion,ntVMotion,Vmotion fabric AB for hosts,sequential 5 | mpUpl01A,1,a,1,2,Pod1,nicUpl01A,ntUpl1A,VM uplink fabric A for hosts,sequential 6 | mpUpl01B,1,b,1,2,Pod1,nicUpl01B,ntUpl1B,VM uplink fabric B for hosts,sequential 7 | mpUpl02A,2,a,1,2,Pod1,nicUpl02A,ntUpl2A,VM uplink fabric A for hosts,sequential 8 | mpUpl02B,2,b,1,2,Pod1,nicUpl02B,ntUpl2B,VM uplink fabric B for hosts,sequential 9 | mpSrvMgmtA,0,a,2,2,Pod2,nicSrvMgmtA,ntSrvMgmtA,Mgmt fabric A for hosts,sequential 10 | mpSrvMgmtB,0,b,2,2,Pod2,nicSrvMgmtB,ntSrvMgmtB,Mgmt fabric B for hosts,sequential 11 | mpVMotion,99,c,2,2,Pod2,nicVMotion,ntVMotion,Vmotion fabric AB for hosts,sequential 12 | mpUpl01A,1,a,2,2,Pod2,nicUpl01A,ntUpl1A,VM uplink fabric A for hosts,sequential 13 | mpUpl01B,1,b,2,2,Pod2,nicUpl01B,ntUpl1B,VM uplink fabric B for hosts,sequential 14 | mpUpl02A,2,a,2,2,Pod2,nicUpl02A,ntUpl2A,VM uplink fabric A for hosts,sequential 15 | mpUpl02B,2,b,2,2,Pod2,nicUpl02B,ntUpl2B,VM uplink fabric B for hosts,sequential -------------------------------------------------------------------------------- /Examples/UCS/ORG.csv: -------------------------------------------------------------------------------- 1 | Name,ParentOrg,Descr 2 | Pod1,root,POD 1 3 | Pod2,root,POD 2 -------------------------------------------------------------------------------- /Examples/UCS/UUIDPool.csv: -------------------------------------------------------------------------------- 1 | Name,Org,Order,Prefix,From,To,Descr 2 | upPod1,Pod1,sequential,afa110ff-1000-1000,1000-00e55500ee01,1000-00e55500ee0a,uuid 3 | upPod2,Pod2,sequential,afa120ff-2000-2000,2000-00e55500ee01,2000-00e55500ee0a,uuid -------------------------------------------------------------------------------- /Examples/UCS/VLAN-add.csv: -------------------------------------------------------------------------------- 1 | vlanname,vlan,native 2 | mgmt191,3191,no 3 | mgmt291,3291,no 4 | -------------------------------------------------------------------------------- /Examples/UCS/VLAN-add2nictmpl.csv: -------------------------------------------------------------------------------- 1 | org,name 2 | sddcPod1,ntSrvMgmtA 3 | sddcPod2,ntSrvMgmtB -------------------------------------------------------------------------------- /Examples/UCS/VLAN.csv: -------------------------------------------------------------------------------- 1 | vlanname,vlan 2 | mgmt101,3101 3 | HA101,3102 4 | VM101-1,3111 5 | VM101-2,3112 6 | VM101-3,3113 7 | mgmt201,3201 8 | HA201,3202 9 | VM201-1,3211 10 | VM201-2,3212 11 | VM201-3,3213 -------------------------------------------------------------------------------- /Examples/UCS/add-MACpool.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1mrobas/PowerShell-for-Networking-Engineers-20170213/d00f345f5be81000bdb628ce0e2e82717fea0f78/Examples/UCS/add-MACpool.ps1 -------------------------------------------------------------------------------- /Examples/UCS/add-ORG.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1mrobas/PowerShell-for-Networking-Engineers-20170213/d00f345f5be81000bdb628ce0e2e82717fea0f78/Examples/UCS/add-ORG.ps1 -------------------------------------------------------------------------------- /Examples/UCS/add-UUIDpool.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1mrobas/PowerShell-for-Networking-Engineers-20170213/d00f345f5be81000bdb628ce0e2e82717fea0f78/Examples/UCS/add-UUIDpool.ps1 -------------------------------------------------------------------------------- /Examples/UCS/add-VLAN.ps1: -------------------------------------------------------------------------------- 1 | #Load list 2 | $List= Import-Csv "VLAN.csv" 3 | 4 | foreach($itemUCS in $ucsList) 5 | { 6 | $ucsRes="Adding VLANs to UCS system - "+$itemUCS.ucs.name 7 | echo-infoYES $ucsRes 8 | 9 | foreach($item in $List) 10 | { 11 | $ucsLanCloud = Get-UcsLanCloud -Ucs $itemUCS.ucs 12 | $vlanRes = Add-UcsVlan -Id $item.vlan -Name $item.vlanname -LanCloud $ucsLanCloud -Ucs $itemUCS.ucs 13 | $echoRes="Added VLAN "+$vlanRes.name 14 | echo-task $echoRes 15 | } 16 | } -------------------------------------------------------------------------------- /Examples/UCS/add-additional-VLANs.ps1: -------------------------------------------------------------------------------- 1 | #Load list 2 | $listVLAN= Import-Csv "VLAN-add.csv" 3 | $listNICtmpl=Import-Csv "VLAN-add2nictmpl.csv" 4 | 5 | 6 | foreach($itemUCS in $ucsList) 7 | { 8 | $ucsRes="Adding VLANs to UCS system - "+$itemUCS.ucs.name 9 | echo-task $ucsRes 10 | 11 | foreach($item in $listVLAN) 12 | { 13 | $ucsLanCloud = Get-UcsLanCloud -Ucs $itemUCS.ucs 14 | $vlanRes = Add-UcsVlan -Id $item.vlan -Name $item.vlanname -LanCloud $ucsLanCloud -Ucs $itemUCS.ucs 15 | $echoRes=" + Added VLAN "+$vlanRes.name 16 | echo-out $echoRes 17 | } 18 | echo-task "DONE - VLANs added to LAN Cloud" 19 | 20 | echo-out " " 21 | echo-out "-------------------------------------------------------" 22 | echo-out " " 23 | 24 | $ucsRes="Adding VLANs to NICs on "+$itemUCS.ucs.name 25 | echo-task $ucsRes 26 | 27 | foreach($itemNICtmpl in $listNICtmpl) 28 | { 29 | $CfgOrg = Get-UcsOrg -Name $itemNICtmpl.Org -Ucs $itemUCS.ucs 30 | $cfgDN=$CfgOrg.dn+"/lan-conn-templ-"+$itemNICtmpl.Name 31 | $nictmpl = Get-UcsVnicTemplate -dn $cfgDN -Org $CfgOrg.Dn -Ucs $itemUCS.ucs 32 | 33 | $echoRes=" + Adding VLANs to "+$nictmpl.name 34 | echo-out $echoRes 35 | 36 | foreach($itemVLAN in $listVLAN) 37 | { 38 | $nictmplRes=Add-UcsVnicInterface -Name $itemVLAN.vlanname -VnicTemplate $nictmpl -DefaultNet $itemVLAN.native 39 | $echoRes=" + Added VLAN "+$itemVLAN.vlanname 40 | echo-out $echoRes 41 | } 42 | } 43 | $ucsRes="DONE - VLANs added to NICs on "+$itemUCS.ucs.name 44 | echo-task $ucsRes 45 | echo-out " " 46 | echo-out "=======================================================" 47 | echo-out " " 48 | 49 | } -------------------------------------------------------------------------------- /Examples/UCS/delete-ORG.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1mrobas/PowerShell-for-Networking-Engineers-20170213/d00f345f5be81000bdb628ce0e2e82717fea0f78/Examples/UCS/delete-ORG.ps1 -------------------------------------------------------------------------------- /Examples/UCS/delete-VLAN.ps1: -------------------------------------------------------------------------------- 1 | #Load list 2 | $List= Import-Csv "VLAN.csv" 3 | 4 | foreach($itemUCS in $ucsList) 5 | { 6 | $ucsRes="Deleting VLAN from UCS system - "+$itemUCS.ucs.name 7 | echo-infoYES $ucsRes 8 | 9 | foreach($item in $List) 10 | { 11 | $ucsLanCloud = Get-UcsLanCloud -Ucs $itemUCS.ucs 12 | $vlanObj = Get-UcsVlan -Id $item.vlan -Ucs $itemUCS.ucs -LanCloud $ucsLanCloud 13 | $vlanRes = Remove-UcsVlan -Vlan $vlanObj -Ucs $itemUCS.ucs -Force 14 | $echoRes="Removed VLAN "+$vlanRes.name 15 | echo-task $echoRes 16 | } 17 | } -------------------------------------------------------------------------------- /Examples/UCS/delete-additional-VLANs.ps1: -------------------------------------------------------------------------------- 1 | #Load list 2 | $listVLAN= Import-Csv "VLAN-add.csv" 3 | $listNICtmpl=Import-Csv "VLAN-add2nictmpl.csv" 4 | 5 | 6 | foreach($itemUCS in $ucsList) 7 | { 8 | $ucsRes="Removing VLANs from NICs on "+$itemUCS.ucs.name 9 | echo-task $ucsRes 10 | 11 | foreach($itemNICtmpl in $listNICtmpl) 12 | { 13 | $CfgOrg = Get-UcsOrg -Name $itemNICtmpl.Org -Ucs $itemUCS.ucs 14 | $cfgDN=$CfgOrg.dn+"/lan-conn-templ-"+$itemNICtmpl.Name 15 | $nictmpl = Get-UcsVnicTemplate -dn $cfgDN -Org $CfgOrg.Dn -Ucs $itemUCS.ucs 16 | $echoRes=" - Removing VLANs from "+$nictmpl.name 17 | echo-out $echoRes 18 | 19 | foreach($itemVLAN in $listVLAN) 20 | { 21 | $nicintf=Get-UcsVnicInterface -VnicTemplate $nictmpl -Name $itemVLAN.vlanname -Ucs $itemUCS.ucs 22 | $nictmplRes=Remove-UcsVnicInterface -VnicInterface $nicintf -Ucs $itemUCS.ucs -Force 23 | $echoRes=" - Removed VLAN "+$itemVLAN.vlanname 24 | echo-out $echoRes 25 | } 26 | } 27 | $ucsRes="DONE - VLANs removed from NICs on "+$itemUCS.ucs.name 28 | echo-task $ucsRes 29 | 30 | echo-out " " 31 | echo-out "-------------------------------------------------------" 32 | echo-out " " 33 | 34 | $ucsRes="Deleting VLANs from UCS system - "+$itemUCS.ucs.name 35 | echo-task $ucsRes 36 | 37 | foreach($item in $listVLAN) 38 | { 39 | $ucsLanCloud = Get-UcsLanCloud -Ucs $itemUCS.ucs 40 | $vlanObj = Get-UcsVlan -Id $item.vlan -Ucs $itemUCS.ucs -LanCloud $ucsLanCloud 41 | $vlanRes = Remove-UcsVlan -Vlan $vlanObj -Ucs $itemUCS.ucs -Force 42 | $echoRes=" - Removed VLAN "+$vlanRes.name 43 | echo-out $echoRes 44 | } 45 | echo-task "DONE - VLANs removed from LAN Cloud" 46 | echo-out " " 47 | echo-out "=======================================================" 48 | echo-out " " 49 | 50 | } -------------------------------------------------------------------------------- /Examples/UCS/demoConnect.ps1: -------------------------------------------------------------------------------- 1 | 2 | <##### 3 | # Connect to UCS1 and UCS2 4 | #####> 5 | echo-inprogress "Connecting to $ucs_sddcUCS1vip" 6 | $global:ucsUCS1= Connect-Ucs -Name $ucs_sddcUCS1vip -Credential $ucsCredentials -NotDefault 7 | echo-inprogress "Connecting to $ucs_sddcUCS2vip" 8 | $global:ucsUCS2= Connect-Ucs -Name $ucs_sddcUCS2vip -Credential $ucsCredentials -NotDefault 9 | 10 | echo-success "Connected to UCSes" 11 | echo-task $ucsUCS1.Ucs 12 | echo-task $ucsUCS2.Ucs 13 | 14 | $global:ucsList=@() 15 | $ucsRow = @{ UCS=$ucsUCS1} 16 | $global:ucsList += New-Object PSObject -Property $ucsRow 17 | 18 | $ucsRow = @{ UCS=$ucsUCS2} 19 | $global:ucsList += New-Object PSObject -Property $ucsRow 20 | -------------------------------------------------------------------------------- /Examples/demoConnect.ps1: -------------------------------------------------------------------------------- 1 | <#### 2 | # Set working directory 3 | #####> 4 | 5 | cd $workDir 6 | 7 | <##### 8 | # Connect to vCenter 9 | #####> 10 | echo-inprogress "Connecting to $vcInfra_name" 11 | $global:vcInfra=Connect-VIServer -Server $vcInfra_name -User $vcUsr -Password $vcPwd -WarningAction SilentlyContinue 12 | 13 | <##### 14 | # Connect to UCS1 and UCS2 15 | #####> 16 | echo-inprogress "Connecting to $ucs_sddcUCS1vip" 17 | $global:ucsUCS1= Connect-Ucs -Name $ucs_sddcUCS1vip -Credential $ucsCredentials -NotDefault 18 | echo-inprogress "Connecting to $ucs_sddcUCS2vip" 19 | $global:ucsUCS2= Connect-Ucs -Name $ucs_sddcUCS2vip -Credential $ucsCredentials -NotDefault 20 | 21 | echo-success "Connected to vCenters and UCSes" 22 | echo-out $vcInfra.Name 23 | echo-out $ucsUCS1.Ucs 24 | echo-out $ucsUCS2.ucs 25 | 26 | # Set-UcsPowerToolConfiguration -SupportMultipleDefaultUcs $true 27 | 28 | 29 | -------------------------------------------------------------------------------- /Examples/demoVars.psm1: -------------------------------------------------------------------------------- 1 | <##### 2 | # vCenters & credentials 3 | #####> 4 | $global:vcInfra_name="infravc.sddc.local" 5 | $global:vcUsr="administrator@vsphere.local" 6 | $global:vcPwd="test123" 7 | 8 | <##### 9 | # UCSes and credentials 10 | #####> 11 | $global:ucs_sddcUCS1vip="sddcUCS1.sddc.local" 12 | $global:ucs_sddcUCS2vip="sddcUCS2.sddc.local" 13 | $ucsUsr="admin" 14 | $ucsPwd=ConvertTo-SecureString -String "test123" -AsPlainText -Force 15 | $global:ucsCredentials = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $ucsUsr, $ucsPwd 16 | 17 | <##### 18 | # Routers, switches 19 | #####> 20 | $global:devUsr="admin" 21 | $global:devPwd="test123" 22 | 23 | 24 | <##### 25 | # REST API credentials 26 | #####> 27 | $restUsr="admin" 28 | $restPwd=ConvertTo-SecureString -String "test123" -AsPlainText -Force 29 | $global:restCredentials = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $restUsr, $restPwd 30 | 31 | $global:urlSW1="http://demoN5K01.flashstack.local:8088/ins" 32 | $global:nameSW1="demoN5K01.flashstack.local" 33 | $global:shortnameSW1="demoN5K01" 34 | 35 | -------------------------------------------------------------------------------- /PSHELL profile/Microsoft.PowerShell_profile.ps1: -------------------------------------------------------------------------------- 1 | ."C:/Program Files (x86)/VMware/Infrastructure/PowerCLI/Scripts/Initialize-PowerCLIEnvironment.ps1" 2 | Import-Module PureStoragePowerShellSDK 3 | Import-Module PureStoragePowerShellToolkit 4 | Import-Module Cisco.IMC 5 | Import-Module Cisco.UCS.Core 6 | Import-Module Cisco.UCS.DesiredStateConfiguration 7 | Import-Module Cisco.UCSManager 8 | Import-Module SSH-Sessions 9 | Import-Module PSExcel 10 | 11 | Get-Module 12 | 13 | function prompt { 14 | $p = Split-Path -leaf -path (Get-Location) 15 | "$p> " 16 | } 17 | 18 | #cd "c:\temp\" 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PowerShell for Networking Engineers - 20170213 2 | This repository contains examples/demos shown and discussed during the 3 | Powershell for Networking Engineers webinar with @ipspace 4 | 5 | ##Subdirectories 6 | * **PSHELL profile** - PowerShell profile example 7 | * **SSH-Sessions** - PowerShell SSH module 8 | * **XML** - XML templates used in PowerShell examples 9 | * **SAN** - FC SAN XML templates 10 | * **LAN** - DC networking XML templates 11 | * **Examples** - Examples from webinar 12 | * **HTTP server** - Simple HTTP server 13 | * **SAN** - SAN config generate examples 14 | * **UCS** - UCS PowerTool config generate&apply examples 15 | 16 | 17 | ## Installation 18 | I was using PowerShell version 5 but examples also work with the latest PowerShell version 19 | * You can download and install [PowerShell](https://www.microsoft.com/en-us/download/details.aspx?id=50395) from Microsoft's website 20 | * For Cisco UCS PowerShell module search for, download and install [Cisco UCS PowerTool Suite](https://software.cisco.com/download/release.html?i=!y&mdfid=286305108&softwareid=284574017&release=2.1.1) 21 | * For VMware vSphere PowerShell module search for, download and install [VMware PowerCLI](https://my.vmware.com/web/vmware/details?downloadGroup=PCLI630R1&productId=491) 22 | * For VMware NSX PowerShell module search for, download and install [VMware PowerNSX](https://github.com/vmware/powernsx) 23 | * For OpenSSH module search for, download and install [Win32-OpenSSH](https://github.com/PowerShell/Win32-OpenSSH) 24 | 25 | -------------------------------------------------------------------------------- /SSH-Sessions/Renci.SshNet.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1mrobas/PowerShell-for-Networking-Engineers-20170213/d00f345f5be81000bdb628ce0e2e82717fea0f78/SSH-Sessions/Renci.SshNet.dll -------------------------------------------------------------------------------- /SSH-Sessions/Renci.SshNet.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1mrobas/PowerShell-for-Networking-Engineers-20170213/d00f345f5be81000bdb628ce0e2e82717fea0f78/SSH-Sessions/Renci.SshNet.zip -------------------------------------------------------------------------------- /SSH-Sessions/SSH-Sessions.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1mrobas/PowerShell-for-Networking-Engineers-20170213/d00f345f5be81000bdb628ce0e2e82717fea0f78/SSH-Sessions/SSH-Sessions.psd1 -------------------------------------------------------------------------------- /SSH-Sessions/SSH-Sessions.psm1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1mrobas/PowerShell-for-Networking-Engineers-20170213/d00f345f5be81000bdb628ce0e2e82717fea0f78/SSH-Sessions/SSH-Sessions.psm1 -------------------------------------------------------------------------------- /SSH-Sessions/SSH-Sessions.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1mrobas/PowerShell-for-Networking-Engineers-20170213/d00f345f5be81000bdb628ce0e2e82717fea0f78/SSH-Sessions/SSH-Sessions.zip -------------------------------------------------------------------------------- /SSH-Sessions/SSH-SessionsPSv3.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1mrobas/PowerShell-for-Networking-Engineers-20170213/d00f345f5be81000bdb628ce0e2e82717fea0f78/SSH-Sessions/SSH-SessionsPSv3.zip -------------------------------------------------------------------------------- /SSH-Sessions/load-SSH.ps1: -------------------------------------------------------------------------------- 1 | Import-Module .\SSH-Sessions 2 | 3 | get-help *ssh* -------------------------------------------------------------------------------- /XML/LAN/add-HSRP.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2 4 | cli_conf 5 | 0 6 | sid 7 | interface vlan#VLAN_ID# ; hsrp 99 ; ip #HSRP_IP# ; preempt ; priority #HSRP_PRI# ; no shut 8 | xml 9 | -------------------------------------------------------------------------------- /XML/LAN/add-L3-VLAN.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2 4 | cli_conf 5 | 0 6 | sid 7 | interface vlan#VLAN_ID# ; ip address #IP_ADDR# #NET_MASK# ; no shut 8 | xml 9 | -------------------------------------------------------------------------------- /XML/LAN/add-VLAN.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2 4 | cli_conf 5 | 0 6 | sid 7 | vlan #VLAN_ID# ; name #VLAN_NAME# 8 | xml 9 | -------------------------------------------------------------------------------- /XML/LAN/delete-L3-VLAN.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2 4 | cli_conf 5 | 0 6 | sid 7 | no interface vlan#VLAN_ID# 8 | xml 9 | -------------------------------------------------------------------------------- /XML/LAN/delete-VLAN.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2 4 | cli_conf 5 | 0 6 | sid 7 | no vlan #VLAN_ID# 8 | xml 9 | -------------------------------------------------------------------------------- /XML/LAN/show-VLAN-ID.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2 4 | cli_show 5 | 0 6 | sid 7 | show vlan id #VLAN_ID# 8 | xml 9 | -------------------------------------------------------------------------------- /XML/LAN/show-VLAN.XML: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.0 4 | cli_show 5 | 0 6 | sid 7 | show vlan 8 | xml 9 | -------------------------------------------------------------------------------- /XML/LAN/show-run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2 4 | cli_show_ascii 5 | 0 6 | sid 7 | show run 8 | xml 9 | -------------------------------------------------------------------------------- /XML/SAN/SAN-activate-zoneset.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2 4 | cli_conf 5 | 0 6 | sid 7 | zoneset activate name #SAN_ZSET# vsan #VSAN_ID# 8 | xml 9 | -------------------------------------------------------------------------------- /XML/SAN/SAN-add-device-alias.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2 4 | cli_conf 5 | 0 6 | sid 7 | device-alias database ;device-alias name #DEV_AL# pwwn #DEV_PWWN# ;device-alias commit 8 | xml 9 | 10 | -------------------------------------------------------------------------------- /XML/SAN/SAN-add-zone-member.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2 4 | cli_conf 5 | 0 6 | sid 7 | member device-alias #DEV_AL# 8 | xml 9 | -------------------------------------------------------------------------------- /XML/SAN/SAN-add-zone-with-members.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2 4 | cli_conf 5 | 0 6 | sid 7 | zone name #ZONE_NAME# vsan #VSAN_ID# ; member device-alias #DEV_AL1# ; member device-alias #DEV_AL2# 8 | xml 9 | -------------------------------------------------------------------------------- /XML/SAN/SAN-add-zone.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2 4 | cli_conf 5 | 0 6 | sid 7 | zone name #ZONE_NAME# vsan #VSAN_ID# 8 | xml 9 | -------------------------------------------------------------------------------- /XML/SAN/SAN-cfg-zoneset.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2 4 | cli_conf 5 | 0 6 | sid 7 | zoneset name #SAN_ZSET# vsan #VSAN_ID# ; member #ZONE_NAME# 8 | xml 9 | -------------------------------------------------------------------------------- /XML/SAN/SAN-commit-zone.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2 4 | cli_conf 5 | 0 6 | sid 7 | zone commit vsan #VSAN_ID# 8 | xml 9 | -------------------------------------------------------------------------------- /XML/SAN/SAN-del-zoneset.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2 4 | cli_conf 5 | 0 6 | sid 7 | zoneset name #SAN_ZSET# vsan #VSAN_ID# ; no member #ZONE_NAME# 8 | xml 9 | -------------------------------------------------------------------------------- /XML/SAN/SAN-flogi-db.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2 4 | cli_show_ascii 5 | 0 6 | sid 7 | show flogi database 8 | xml 9 | --------------------------------------------------------------------------------