Skip to content

Instantly share code, notes, and snippets.

@dcolebatch
Created March 27, 2017 17:27
Show Gist options
  • Save dcolebatch/51a926e7028942613194220cc2342ce6 to your computer and use it in GitHub Desktop.
Save dcolebatch/51a926e7028942613194220cc2342ce6 to your computer and use it in GitHub Desktop.
Discover how much NLB is running in your environment
$output = @{}
$servers = Get-SCVirtualMachine | Select Name, VirtualNetworkAdapters
$nics = $servers | ForEach-Object {
$NIC = $_.VirtualNetworkAdapters
ForEach ($adapter in $NIC)
{
If ($adapter.VirtualNetwork -like "*FrontEnd*")
{
$adapter.Name
}
}
}
$nics | Foreach-Object {
try
{
$nlbcluster = Get-NlbCluster $_
}
catch
{
write-host "No cluster for $_"
return
}
# Each NLB Node will return the same data, so just do it once per cluster:
If (-Not $output.containskey($nlbcluster.name) )
{
$nodes = Get-NlbClusterNode -InputObject $nlbcluster
$config= Get-NlbClusterPortRule -InputObject $nlbcluster
$vip = Get-NlbClusterVip -InputObject $nlbcluster
$output[$nlbcluster.name] = [ordered]@{}
$output[$nlbcluster.name] += @{ cluster_name = $nlbcluster.name }
$output[$nlbcluster.name] += @{ cluster_nodes = @() }
# Stuff nodes into this cluster's object
for ($i=0; $i -lt ($nodes).Count; $i++)
{
$nodedip = Get-NlbClusterNodeDip -InputObject $nodes[$i]
$node = [ordered]@{}
$node["hostname"] = $nodes[$i].name
$node["fqdn"] = $nodes[$i].Host
$node["state"] = $nodes[$i].State.NodeStatusCode.ToString()
$node["interface_name"] = $nodes[$i].InterfaceName
$node["node_ip"] = $nodedip.ipaddress
$node["node_netmask"] = $nodedip.subnetmask
$output[$nlbcluster.name]["cluster_nodes"] += $node
}
## Repeat for $config and $vip...
}
}
$date = Get-Date -Format dd-MM-yy
$output | ConvertTo-Json -Depth 99 | Out-File c:\tmp\nlb_config-$date.js -Encoding utf8 -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment