Using Pester tests, you can define the expected configuration rules and execute it against your existing switches to verify everything is configured correctly or not.
Here in this example, I will show how to verify the below.
#Provide interface range to verify status
[int]$Start_port = Read-host "Enter starting switch port number"
[int]$End_port = Read-host "Enter ending switch port number"
#Provide VLANs to verify status
[int[]]$vlans = 20,23
$check_vlans = @{}
#New SSH session to the Switch
$sw_creds = Get-Credential -Message "Enter switch creds"
Write-Host "Creating new SSH session to Switch."
$SWssh = New-SSHSession -ComputerName 192.168.10.4 -Credential $sw_creds -Force -ConnectionTimeout 300
Write-Host "Collecting configuration details from Switch. This will take few seconds."
Start-Sleep -s 3
Write-Host "Collecting VLAN details from Switch. This will take few seconds."
for ($j=0; $j -lt $vlans.Count; $j++) {
Write-Host "Collecting details of VLAN $($vlans[$j])"
$cmd_vlan = "show interfaces vlan $($vlans[$j])"
$check_vlan = invoke-sshcommand -Command $cmd_vlan -SSHSession $SWssh
Start-Sleep -s 3
$check_vlans[$j] = $check_vlan.Output
}
#Collecting networking OS info
$Networking_OS = Invoke-SSHCommand -SSHSession $SWssh -Command "show system"
Start-Sleep -s 3
#Collecting interface status details
$interface_cmd = "show interfaces twentyFiveGigE 1/$Start_port-1/$End_port"
$interface_status = Invoke-SSHCommand -SSHSession $SWssh -Command $interface_cmd
Write-Host "Configuration verification started.`n"
Describe "System basic checks" {
Context "Check networking OS version" {
It "Should be Dell EMC Networking OS Version : 9.12(1.0)" {
($Networking_OS.Output) -match 'Dell EMC Networking OS Version : 9\.12\(1\.0\)\s\s$' | Should be $true
}
}
}
$Global:i=1
Describe "Interface checks" {
for ($i=$Start_port; $i -le $End_port; $i++) {
Context "Interface should be UP" {
It "Interface 1/$i should be UP" {
$Global:c1 = "twentyFiveGigE 1/$i is up, line protocol is up"
$res = ($interface_status.Output) -match $c1
$res | should be $true
}
}
}
}
Describe "VLAN checks" {
for ($j=0; $j -lt $vlans.Count; $j++) {
Context "Check VLAN $($vlans[$j])" {
It "Should contain VLAN $($vlans[$j])" {
$check = ($check_vlans[$j]) -match '% Error: No such interface'
$check | should be $null
Write-host $check
}
It "VLAN $($vlans[$j]) should be UP" {
$tt = "Vlan $($vlans[$j]) is up, line protocol is up"
$t3 = ($check_vlans[$j]) -match $tt
$t3 | should be $true
}
}
}
}
Remove-SSHSession -SSHSession $SWssh
#Sample output
You can write custom Pester tests according to your switching infrastructure configuration, where you can verify port channels, VLAN membership of switch ports, VLT configuration etc. Hope this was helpful. Cheers!