Skip to content

Instantly share code, notes, and snippets.

View DrBob5188's full-sized avatar

Robert Thomson DrBob5188

  • Brisbane, Australia
View GitHub Profile
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.
# 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' {