Last active
August 12, 2020 17:19
-
-
Save ChrisLynchHPE/ad5c9b4691aff5b879654a22a289dda6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$NetworksWithAssociations = @() | |
# Get associated newtorks with server profiles | |
$NetworksWithAssociations += (Send-OVRequest -Uri '/rest/index/associations?name=SERVER_PROFILE_TEMPLATE_TO_NETWORK').members | |
# Get associated newtorks with server profile templates | |
$NetworksWithAssociations += (Send-OVRequest -Uri '/rest/index/associations?name=server_profiles_to_networks').members | |
# Get list of networks associated with network sets | |
$NetworksWithAssociations += (Send-OVRequest -Uri '/rest/index/associations?name=NETWORKSET_TO_NETWORK').members | |
# Get list of networks associated with uplink sets | |
$NetworksWithAssociations += (Send-OVRequest -Uri '/rest/index/associations?name=UPLINK_SET_TO_NETWORK').members | |
# Get list of networks associated with logical interconnect groups | |
$NetworksWithAssociations += (Send-OVRequest -Uri '/rest/index/associations?name=LOGICAL_INTERCONNECT_GROUP_TO_NETWORK').members | |
# Get the unique URI's from the collection | |
$UniqueNetworkUris = $NetworksWithAssociations | select childUri -unique | |
# Get all network resources | |
# You can add the -Type parameter in order to compare a specific set of network types that are not associated with other network resources | |
$Networks = Get-OVNetwork | |
# Get the list of networks that have no association | |
$Results = (Compare-Object $networks.uri -DifferenceObject $UniqueNetworkUris.childUri | ? SideIndicator -eq '<=').InputObject | |
ForEach ($UnassociatedNetworkUri in $Results) { | |
$Net = Send-OVRequest -Uri $UnassociatedNetworkUri | |
Write-Host ("'" + $Net.name + "'") -Foreground Red -NoNewLine | |
Write-Host " is not associated with any other resource, and will be removed" | |
## Delete the network object. Uncomment to remove the network | |
# Send-OVRequest -Uri $UnassociatedNetworkUri -Method DELETE -OutVariable Tasks | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment