# Function that can find objects and deduce properties from a naming convention supplied in the form of a regex string. Function Objectize-Regex { Param([array]$strings,[string]$regex) $myCol = @() ForEach ($string in $strings) { If ($string -match $regex) { $myObj = "" | Select Name $myObj.Name = $Matches[0] ForEach ($Key in ($Matches.Keys | Where{$_ -ne "0"})) { $myObj | Add-Member -MemberType NoteProperty -Name $Key -Value $Matches["$Key"] } $myCol += $myObj } } Return $myCol } # Example strings that contain server names $myStrings = "Server one is: EHV-DB-TST-01", "AMS-WEB-PRD-06 is another server.", "I don't know what EHV-MISC-DEV-03 is for..." # Example regex string. Descibes a naming convention for server names. Important to name the groups you want to match. $myRegex = "(?\w{3})-(?\w+)-(?PRD|ACC|DEV|TST)-(?\d{2})" # Example Sytax for running the function Objectize-Regex -Strings $myStrings -Regex $myRegex