Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions GetNetworkManagerScope.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"subsid": "",
"resourceGroupName": "",
"networkManagerName": "",
"outputPath": "./scope.json"
}

40 changes: 40 additions & 0 deletions GetNetworkManagerScope.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#// Copyright (c) Microsoft Corporation.
#// Licensed under the MIT license.

# Setup
$configPath = '.\GetNetworkManagerScope.json'

try
{
$Configs = Get-Content -Path $configPath | ConvertFrom-Json -AsHashtable -ErrorAction SilentlyContinue
$subId = $configs["subsid"]
Write-Host "Subscription Id: " $subId
$rgname = $configs["resourceGroupName"]
Write-Host "ResourceGroup Id: " $rgname
$networkManagerName = $configs["networkManagerName"]
Write-Host "NetworkManager Name: " $NetworkManagerName
$outputPath = $configs["outputPath"]
Write-Host "OutputPath: " $outputPath
}
catch
{
Write-Host "Config file is in incorrect json format, please format it correctly" -ForegroundColor Red
return
}

if ($null -eq $configs)
{
Write-Host "Config file is in incorrect json format, please format it correctly" -ForegroundColor Red
return
}

Connect-AzAccount -Subscription $subId

$networkManager = Get-AzNetworkManager -ResourceGroupName $rgname -Name $networkManagerName

$scope = $networkManager.NetworkManagerScopes | Select-Object * -ExcludeProperty "CrossTenantScopes", "ManagementGroupsText", "SubscriptionsText", "CrossTenantScopesText"
$scope | ConvertTo-Json | Out-File -FilePath $outputPath

Write-Host "Get Scope Completed In " $outputPath -ForegroundColor Green


9 changes: 4 additions & 5 deletions ScopeValidation.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
"subsid": "",
"resourceGroupName": "",
"networkManagerName": "",
"subscriptions": [""],
"managementGroups": [""]
"subscriptions": [],
"managementGroups": []
"scopePath": "./scope.json",
"isDryRun": "false"
}





43 changes: 38 additions & 5 deletions ScopeValidation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,34 @@

# Setup
$configPath = '.\ScopeValidation.json'

try
{
$Configs = Get-Content -Path $configPath | ConvertFrom-Json -AsHashtable -ErrorAction SilentlyContinue
$subId = $configs["subsid"]
Write-Host "Subscription Id: " $SubId
Write-Host "Subscription Id: " $subId
$rgname = $configs["resourceGroupName"]
Write-Host "ResourceGroup Id: " $rgname
$networkManagerName = $configs["networkManagerName"]
Write-Host "NetworkManager Name: " $NetworkManagerName
$subscriptions = $configs["subscriptions"]
$managementGroups = $configs["managementGroups"]
$scopePath = $configs["scopePath"]

if($scopePath.Length -ne 0)
{
Write-Host "Get Scope From ScopePath: " $scopePath
$updatedScope = Get-Content -Path $scopePath | ConvertFrom-Json -AsHashtable -ErrorAction SilentlyContinue
$subscriptions = $updatedScope["Subscriptions"]
$managementGroups = $updatedScope["ManagementGroups"]
}
else{
$subscriptions = $configs["subscriptions"]
$managementGroups = $configs["managementGroups"]
}



$isDryRun = $configs["isDryRun"]
Write-Host "IsDryRun: " $isDryRun
}
catch
{
Expand Down Expand Up @@ -164,7 +180,24 @@
return
}
}


}

if($isDryRun -eq "False" || $isDryRun -eq "false")
{
# Update
return
$scope = New-AzNetworkManagerScope -Subscription $subscriptions -ManagementGroup $managementGroups
$networkManager.NetworkManagerScopes = $scope;
$newNetworkManager = Set-AzNetworkManager -InputObject $networkManager
Write-Host "Removed Scopes Do Not Contain Deployed Resources, Network Manager Scope is Updated" -ForegroundColor Green
}
else
{
Write-Host "Removed Scopes Do Not Contain Deployed Resources, Safe To Remove" -ForegroundColor Green
}



Write-Host "Removed Scopes Do Not Contain Deployed Resources, Safe To Remove" -ForegroundColor Green