Skip to content

Instantly share code, notes, and snippets.

@vexx32

vexx32/BashScripter62.ps1

Last active Apr 11, 2019
Embed
What would you like to do?
$PrimeNode = nslookup dockerhost.mycorp.com 192.168.31.67 |
Select-String -Pattern Address |
Where-Object LineNumber -eq 5 |
ForEach-Object { $_.Line.Split(' ')[-1] }
$SshData = ssh -q docker@$PrimeNode "cat /dns/zones/db.192.168.169" |
Select-String -Pattern "\d{1,3}(\.\d{1,3}){3}"
$IPList = $SshData -split '; ' | Select-String -Pattern "\d{1,3}(\.\d{1,3}){3}"
$NodeList = foreach($IP in $IPList) {
$server = ssh -q docker@$IP 'docker info' |
Select-String -Pattern (' Data Space Used',' Data Space Total',' Data Space Available','Is Manager','Swarm','mycorp.com')
$Node = $server -replace ':',' =' | ConvertFrom-StringData
# Add the IP as an extra property so we keep all the data together.
$Node.Add('IP', $IP)
# Drop output here, it will be collected in $NodeList (above) after the loop completes.
# The type cast turns the returned hashtable into a more conventional object for better display formatting.
[PSCustomObject] $Node
}
# Print found nodes as a table
$NodeList | Format-Table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment