11param (
2- [string ]$subscriptionId ,
32[string ]$resourceGroupName ,
3+ [Parameter (Mandatory = $true )]
4+ [string ]$subscriptionId ,
45[bool ]$whatIf = $false
56)
67
78if ([string ]::IsNullOrEmpty($subscriptionId )) {
89 $subscriptionId = Read-Host - Prompt " Please enter the subscription ID"
910}
1011
11- if ([string ]::IsNullOrEmpty($resourceGroupName )) {
12- $resourceGroupName = Read-Host - Prompt " Please enter the resource group name"
13- }
12+ # if ([string]::IsNullOrEmpty($resourceGroupName)) {
13+ # $resourceGroupName = Read-Host -Prompt "Please enter the resource group name"
14+ # }
1415
1516if ([string ]::IsNullOrEmpty($whatIf )) {
1617 $dryRun = Read-Host - Prompt " Would you like to run this as a dry run? (yes/no)"
@@ -21,27 +22,40 @@ if ([string]::IsNullOrEmpty($whatIf)) {
2122 }
2223}
2324
24- if ([string ]::IsNullOrEmpty($resourceGroupName ) -or [string ]::IsNullOrEmpty($subscriptionId )) {
25- Write-Host " Either the resource group or subscription ID is not specified. Please provide both to proceed."
26- exit
27- } else {
28- Write-Host " Performing actions on ResourceGroup: $ ( $resourceGroupName ) in Subscription:$ ( $subscriptionId ) "
29- }
25+ Write-Host " Resource Group Name: $resourceGroupName "
26+ Write-Host " Subscription ID: $subscriptionId "
27+ Write-Host " WhatIf: $WhatIf "
3028
31- $query = @"
32- Resources
33- | where type =~ 'microsoft.azurearcdata/sqlserverinstances'
34- | where resourceGroup =~ '$resourceGroupName '
35- | where subscriptionId =~ '$subscriptionId '
36- | project name, resourceGroup
37- "@
29+ if ([string ]::IsNullOrEmpty($subscriptionId )) {
30+ Write-Host " The subscription ID is required."
31+ exit
32+ }
3833
3934$minSupportedApiVersion = ' 2024-07-10'
35+ $query = $null
36+ $resources = $null
37+
38+ if ([string ]::IsNullOrEmpty($resourceGroupName )){
39+ $query = "
40+ Resources
41+ | where type =~ 'microsoft.azurearcdata/sqlserverinstances'
42+ | where subscriptionId =~ '$subscriptionId '
43+ | project name, resourceGroup
44+ "
45+ } else {
46+ $query = "
47+ Resources
48+ | where type =~ 'microsoft.azurearcdata/sqlserverinstances'
49+ | where resourceGroup =~ '$resourceGroupName '
50+ | where subscriptionId =~ '$subscriptionId '
51+ | project name, resourceGroup
52+ "
53+ }
4054
4155$resources = Search-AzGraph - Query $query
4256
4357if ([string ]::IsNullOrEmpty($resources )) {
44- Write-Host " No resources were found in this resource group ."
58+ Write-Host " No SQL Server Instances were found in this scope ."
4559 exit
4660}
4761
@@ -51,7 +65,7 @@ $resources = $resources | ForEach-Object {
5165 SqlArcResource = $_.name
5266 }
5367}
54- Write-Host $resources
68+
5569$arcMachineResourceIds = @ ()
5670foreach ($resource in $resources ) {
5771 Write-Host " ResourceGroup: $ ( $resource.ResourceGroup ) , Sql Arc resource: $ ( $resource.SqlArcResource ) "
0 commit comments