1+ param (
2+ [string ]$resourceGroupName = ' myResourceGroup' ,
3+ [string ]$subscriptionId = ' 00000000-0000-0000-0000-000000000000' ,
4+ [switch ]$WhatIf = $false ,
5+ [string ]$propertiesJSON = @"
6+ {
7+ "backupPolicy": null,
8+ "upgradeLockedUntil": null,
9+ "monitoring": {
10+ "enabled": false
11+ },
12+ "migration": {
13+ "assessment": {
14+ "enabled": false
15+ }
16+ }
17+ }
18+ "@
19+ )
20+
21+ Write-Verbose " Resource Group Name: $resourceGroupName "
22+ Write-Verbose " Subscription ID: $subscriptionId "
23+ Write-Verbose " WhatIf: $WhatIf "
24+ Write-Verbose " Properties JSON: $propertiesJSON "
25+
26+ $properties = $propertiesJSON | ConvertFrom-Json
27+
28+ try {
29+ Write-Verbose " Connecting to Azure with subscription ID: $subscriptionId "
30+ $defaultProfile = Connect-AzAccount - SubscriptionId $subscriptionId - ErrorAction Stop
31+
32+ if ([string ]::IsNullOrEmpty($resourceGroupName )) {
33+ Write-Verbose " Fetching resources for subscription ID: $subscriptionId "
34+ $resources = Get-AzResource - ResourceType " Microsoft.AzureArcData/SqlServerInstances" - ErrorAction Stop - Pre - ExpandProperties
35+ } else {
36+ Write-Verbose " Fetching resources for subscription ID: $subscriptionId and resource group: $resourceGroupName "
37+ $resources = Get-AzResource - ResourceType " Microsoft.AzureArcData/SqlServerInstances" - ErrorAction Stop - Pre - ExpandProperties - ResourceGroupName $resourceGroupName
38+ }
39+ $resources = $resources | Where-Object { ' SSIS' , ' SSAS' , ' SSRS' -notcontains $_.Properties.serviceType }
40+
41+ foreach ($resource in $resources ) {
42+ try {
43+ if ($WhatIf ) {
44+ Write-Verbose " Performing dry-run patch for resource: $ ( $resource.Id ) "
45+ $resource | Set-AzResource - Properties $properties - UsePatchSemantics - Pre - Force - DefaultProfile $defaultProfile - ErrorAction Stop - WhatIf
46+ } else {
47+ Write-Verbose " Patching resource: $ ( $resource.Id ) "
48+ $resource | Set-AzResource - Properties $properties - UsePatchSemantics - Pre - Force - DefaultProfile $defaultProfile - ErrorAction Stop
49+ Write-Host (" Resource patched: $ ( $resource.Id ) " )
50+ }
51+ } catch {
52+ Write-Error " Failed to patch resource: $ ( $resource.Id ) . Error: $_ "
53+ }
54+ }
55+ } catch {
56+ Write-Error " An error occurred: $_ "
57+ }
0 commit comments