Functions/Networking/Get-IPConfig.ps1
Function Get-IPConfig { [cmdletbinding()] Param() Process { # Get Legacy IPConfig Stack Info and trim the string data $IPCONFIG = (ipconfig /all) $IPCONFIG_RWS = $IPCONFIG | where {$_} # Start an Open Reading Frame over the string data $ORF_Open = $false $ORF_Close = $false # Step through string data and attach known strings to properties and aggregate into an array $I=0 $ORFArray = Foreach ($Line in $IPCONFIG_RWS) { if ($Line -like "Ethernet adapter *") { $ORF_Open = $true $ORF_Open_Line = $I } if ($Line -like "*NetBIOS over Tcpip*") { $ORF_Close = $true $ORF_Close_Line = $I } if ($ORF_Open -and $ORF_Close) { $ORF_Open = $False $ORF_Close = $False $ORF = $IPCONFIG_RWS[($ORF_Open_Line)..($ORF_Close_Line)] $ORF[0] = "Adapter Name: $(($ORF[0] -split 'Ethernet Adapter ')[-1] -replace ':','')" $n=0 $IPn=1 $DNS = foreach ($R in $ORF) { if ($R -like "*DNS Servers*") { $D = $N @(($ORF[$N] -split ': ')[-1]) foreach ($E in ($ORF[($n)..(($Orf.count-2))] -like " *")){$E.trim()} } if ($R -like "*IPv4 Address*") { $ORF[$n] = $R -replace 'IPv4 Address',"IPv4 Address $IPn" } if ($R -like "*Subnet Mask*") { $ORF[$n] = $R -replace 'Subnet Mask',"Subnet Mask $IPn" $IPN++ } $N++ } $DNSString = $DNS -join ',' $ORF[$D] = " DNS Servers . . . . . . . . . . . : $DNSString" $ORFBlock = ((($ORF | where {$_ -notlike " *"}) -replace '\(Preferred\)','' -replace '\. ','' -replace ' :',':' -replace ': ',':' -replace ' :',':' | foreach {$_.Trim()}) -replace ':','=') -join "`r`n" $ORFHash = $ORFBlock | ConvertFrom-StringDataOrdered [pscustomobject]($ORFHash) } $I++ } # Output IP Stack Objects $ORFArray } } |