This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-StringLCP | |
{ | |
<# | |
.SYNOPSIS | |
Get the longest common string prefix from an array of strings. | |
.DESCRIPTION | |
Get the longest common string prefix from an array of strings. | |
Note that empty strings and null values are allowed in the array. | |
Nulls will be automatically type cast by PowerShell as an empty string. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Split the records using a regex with lookahead. It's flexible, selective and doesn't consume the delimiter | |
$records = $SwitchInfo -split "(?m)(?=^.+-network)" | |
foreach ($record in $records){ | |
#the match operator fills the matches collection and saves us splitting/parsing | |
if ($record -match '([^ ]+)\s+cluster-network\s+([^ ]+)\s+(.+)'){ | |
$SwitchName = $matches[1] | |
$SwitchIP = $matches[2] | |
$SwitchModel = $matches[3] | |
Switch ($SwitchModel) { | |
'CN1610' { |