Skip to content

Commit a40aa92

Browse files
authored
Merge pull request #722 from Clare-Zheng82/0619-Add_script_for_find_impacted_objects
Add script for finding impacted objects
2 parents b00444f + 6371f76 commit a40aa92

File tree

2 files changed

+227
-47
lines changed

2 files changed

+227
-47
lines changed

Connector/FindImpactedObjects.ps1

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ $LegacyV1LSTypes = @(
131131
"AzureMariaDB",
132132
"GoogleBigQuery",
133133
"PostgreSql",
134-
135-
# To be end of support
136134
"ServiceNow",
137135
"Snowflake",
138136
"Salesforce",
@@ -147,11 +145,16 @@ $LegacyV1VersionLSTypes = @(
147145
"Vertica",
148146
"Oracle",
149147
"Greenplum",
150-
"AzurePostgreSql",
151-
# V2 Preview
148+
"AzurePostgreSql",
149+
"Teradata",
150+
"AmazonRdsForOracle",
151+
"Hive",
152+
"Impala",
152153
"Spark",
153154
"Presto",
154-
"Cassandra"
155+
"Cassandra",
156+
# V2 Preview
157+
"QuickBooks"
155158
)
156159

157160
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
@@ -204,45 +207,4 @@ foreach ($df in $dataFactories) {
204207
} catch {
205208
Write-Host "Failed to fetch linked services for $dataFactoryName" -ForegroundColor Red
206209
}
207-
}
208-
209-
# Sometimes, Get-AzDataFactoryV2LinkedService will fail to deserialize the payload due to invalid payload, or out-of-date version, let's use Rest API instead
210-
# foreach ($df in $dataFactories) {
211-
# $dataFactoryName = $df.DataFactoryName
212-
# $resourceGroup = $df.ResourceGroupName
213-
# Write-Host "Data Factory $dataFactoryName (Resource Group $resourceGroup)" -ForegroundColor Green
214-
215-
# # Get all Linked Services for this Data Factory
216-
# $linkedServices = Get-AzDataFactoryV2LinkedService -ResourceGroupName $resourceGroup -DataFactoryName $dataFactoryName
217-
218-
# if ($linkedServices.Count -gt 0) {
219-
# foreach ($ls in $linkedServices) {
220-
# $type = $ls.Properties.GetType().Name -replace 'LinkedService$', ''
221-
# # Find all the legacy types
222-
# if ($LegacyLSTypes -contains $type) {
223-
# Write-Host "$dataFactoryName, $($ls.Name), $type"
224-
# }
225-
226-
# # Find v1 versions.
227-
# if ($LSWithV1Types -contains $type) {
228-
# $version = $ls.Properties.version
229-
# if ($version -ne "2.0") { # skip version 2.0
230-
# switch ($type) { # We need some custom logic per types
231-
# "MySql" {
232-
# $connectionString = $ls.Properties.ConnectionString
233-
# if (-not [string]::IsNullOrEmpty($connectionString)) {
234-
# Write-Host "$dataFactoryName, $($ls.Name), $type"
235-
# }
236-
# break
237-
# }
238-
# default {
239-
# Write-Host "$dataFactoryName, $($ls.Name), $type"
240-
# break
241-
# }
242-
# }
243-
# }
244-
# }
245-
246-
# }
247-
# }
248-
# }
210+
}

Connector/FindImpactedObjects1.ps1

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
# Make sure run PowerShell cmd with administrator
2+
3+
param (
4+
[Parameter(Mandatory = $true)]
5+
[string]$TenantId
6+
)
7+
8+
# Disable warning for get access token
9+
function Get-PlainAccessToken {
10+
$prev = $WarningPreference
11+
$WarningPreference = 'SilentlyContinue'
12+
$token = (Get-AzAccessToken).Token
13+
$WarningPreference = $prev
14+
15+
$plainToken = [Runtime.InteropServices.Marshal]::PtrToStringBSTR(
16+
[Runtime.InteropServices.Marshal]::SecureStringToBSTR($token)
17+
)
18+
return $plainToken
19+
}
20+
21+
function Get-AllLinkedServices {
22+
param (
23+
[string]$Uri
24+
)
25+
26+
$allLinkedServices = New-Object System.Collections.ArrayList
27+
$nextUri = $Uri
28+
$token = Get-PlainAccessToken
29+
30+
$headers = @{
31+
Authorization = "Bearer $token"
32+
"Content-Type" = "application/json"
33+
}
34+
35+
while ($nextUri) {
36+
try {
37+
$response = Invoke-RestMethod -Method GET -Uri $nextUri -Headers $headers
38+
}
39+
catch {
40+
Write-Warning "Failed to fetch: $nextUri"
41+
break
42+
}
43+
44+
if ($response.value -ne $null -and $response.value.Count -gt 0) {
45+
#Write-Host " Retrieved $($response.value.Count) linked services"
46+
foreach ($item in $response.value) {
47+
[void]$allLinkedServices.Add($item)
48+
}
49+
}
50+
else {
51+
#Write-Warning "No linked services found in current batch."
52+
break
53+
}
54+
55+
$nextUri = if ($response.PSObject.Properties.Name -contains 'nextLink') { $response.nextLink } else { $null }
56+
57+
# # Optional: delay to avoid throttling
58+
# Start-Sleep -Milliseconds 300
59+
}
60+
61+
return $allLinkedServices
62+
}
63+
64+
function Print-Result {
65+
param (
66+
[string]$subName,
67+
[string]$dfName,
68+
[string]$lsName,
69+
[string]$lsType,
70+
[string]$outputFileName
71+
)
72+
Write-Host "$subName, $dfName, $lsName, $lsType"
73+
74+
75+
# Output it to a file
76+
$data = [PSCustomObject]@{
77+
SubName = $subName
78+
DataFactoryName = $dfName
79+
LinkedServiceName = $lsName
80+
Type = $lsType
81+
}
82+
$data | Export-Csv -Path $outputFileName -NoTypeInformation -Append
83+
}
84+
85+
# Legacy linked services, we can extend this list
86+
$LegacyV1LSTypes = @(
87+
# Disabled:
88+
"AmazonMWS",
89+
# End of support:
90+
"Zoho",
91+
"SalesforceMarketingCloud",
92+
"Phoenix",
93+
"PayPal",
94+
"OracleServiceCloud",
95+
"Responsys",
96+
"Eloqua",
97+
"Marketo",
98+
"Magento",
99+
"HBase",
100+
"Drill",
101+
"Couchbase",
102+
"Concur",
103+
"AzureMariaDB",
104+
"GoogleBigQuery",
105+
"PostgreSql",
106+
"ServiceNow",
107+
"Snowflake",
108+
"Salesforce",
109+
"SalesforceServiceCloud"
110+
)
111+
112+
$LegacyV1VersionLSTypes = @(
113+
# End of support
114+
"MySql",
115+
"MariaDB",
116+
# V2 GA
117+
"Vertica",
118+
"Oracle",
119+
"Greenplum",
120+
"AzurePostgreSql",
121+
"Teradata",
122+
"AmazonRdsForOracle",
123+
"Hive",
124+
"Impala",
125+
"Spark",
126+
"Presto",
127+
"Cassandra",
128+
# V2 Preview
129+
"QuickBooks"
130+
)
131+
132+
# Install/Update Required Modules
133+
Write-Host "Checking for Az modules..." -ForegroundColor Cyan
134+
Install-Module -Name Az.DataFactory -Force -AllowClobber
135+
Import-Module Az.DataFactory
136+
# If you hit incompatible version, try Install-Module -Name Az.Accounts -RequiredVersion <your version>, and reopen the cmd
137+
138+
# Show the version in use
139+
$module = Get-Module -Name Az.DataFactory
140+
if ($module) {
141+
Write-Host "Az.DataFactory version in use: $($module.Version)" -ForegroundColor Green
142+
} else {
143+
Write-Host "Az.DataFactory module not loaded." -ForegroundColor Red
144+
}
145+
146+
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
147+
$filename = "output_$timestamp.csv"
148+
149+
# Log into Azure
150+
Connect-AzAccount -ErrorAction Stop -tenantId $TenantId
151+
152+
Write-Host "Retrieving Subscriptions..." -ForegroundColor Cyan
153+
$Subscriptions = Get-AzSubscription -tenantId $TenantId
154+
155+
foreach ($sub in $Subscriptions) {
156+
$SubscriptionId = $sub.Id
157+
$subName = $sub.Name
158+
# Set sub ID
159+
Write-Host "Connecting to sub $SubscriptionId " -ForegroundColor Cyan
160+
Set-AzContext -Subscription $SubscriptionId -TenantId $tenantId | Out-Null
161+
162+
# Get all Data Factories in the subscription
163+
Write-Host "Retrieving Data Factories..." -ForegroundColor Cyan
164+
$dataFactories = Get-AzDataFactoryV2
165+
166+
if ($dataFactories.Count -eq 0) {
167+
Write-Host "No Data Factories found in subscription $SubscriptionId"
168+
}
169+
170+
foreach ($df in $dataFactories) {
171+
$resourceGroup = $df.ResourceGroupName
172+
$dataFactoryName = $df.DataFactoryName
173+
174+
$uri = "https://management.azure.com/subscriptions/$SubscriptionId/resourceGroups/$resourceGroup/providers/Microsoft.DataFactory/factories/$dataFactoryName/linkedservices?api-version=2018-06-01"
175+
176+
try {
177+
$response = Invoke-AzRestMethod -Method GET -Uri $uri
178+
$linkedServices = Get-AllLinkedServices -Uri $uri
179+
180+
181+
if ($linkedServices.Count -eq 0) {
182+
continue
183+
}
184+
185+
foreach ($ls in $linkedServices) {
186+
$name = $ls.name
187+
$type = $ls.properties.type
188+
$version = $ls.properties.version
189+
$typeProps = $ls.properties.typeProperties | ConvertTo-Json -Depth 10 | ConvertFrom-Json
190+
191+
if ($LegacyV1LSTypes -contains $type) {
192+
Print-Result -subName $subName -dfName $dataFactoryName -lsName $name -lsType $type -outputFileName $filename
193+
}
194+
195+
# Find v1 versions.
196+
if ($LegacyV1VersionLSTypes -contains $type) {
197+
if ($version -ne "2.0") { # Skip version 2.0, it must be non-legacy
198+
switch ($type) { # MySql and MariaDB are not following the version design, hence, need some custom logic here
199+
{($_ -eq "MariaDB") -or ($_ -eq "MySql")} {
200+
$connectionString = $typeProps.connectionString
201+
if (-not [string]::IsNullOrEmpty($connectionString)) {
202+
Print-Result -subName $subName -dfName $dataFactoryName -lsName $name -lsType $type -outputFileName $filename
203+
}
204+
break
205+
}
206+
default {
207+
Print-Result -subName $subName -dfName $dataFactoryName -lsName $name -lsType $type -outputFileName $filename
208+
break
209+
}
210+
}
211+
}
212+
}
213+
}
214+
} catch {
215+
Write-Host "Failed to fetch linked services for $dataFactoryName" -ForegroundColor Red
216+
}
217+
}
218+
}

0 commit comments

Comments
 (0)