Skip to content

Commit b4bb0b6

Browse files
Clare Zheng (Shanghai Wicresoft Co Ltd)Clare Zheng (Shanghai Wicresoft Co Ltd)
authored andcommitted
Add script
1 parent b00444f commit b4bb0b6

File tree

1 file changed

+215
-0
lines changed

1 file changed

+215
-0
lines changed

Connector/FindImpactedObjects1.ps1

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
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+
107+
# To be end of support
108+
"ServiceNow",
109+
"Snowflake",
110+
"Salesforce",
111+
"SalesforceServiceCloud"
112+
)
113+
114+
$LegacyV1VersionLSTypes = @(
115+
# End of support
116+
"MySql",
117+
"MariaDB",
118+
# V2 GA
119+
"Vertica",
120+
"Oracle",
121+
"Greenplum",
122+
"AzurePostgreSql",
123+
# V2 Preview
124+
"Spark",
125+
"Presto",
126+
"Cassandra"
127+
)
128+
129+
# Install/Update Required Modules
130+
Write-Host "Checking for Az modules..." -ForegroundColor Cyan
131+
Install-Module -Name Az.DataFactory -Force -AllowClobber
132+
Import-Module Az.DataFactory
133+
# If you hit incompatible version, try Install-Module -Name Az.Accounts -RequiredVersion <your version>, and reopen the cmd
134+
135+
# Show the version in use
136+
$module = Get-Module -Name Az.DataFactory
137+
if ($module) {
138+
Write-Host "Az.DataFactory version in use: $($module.Version)" -ForegroundColor Green
139+
} else {
140+
Write-Host "Az.DataFactory module not loaded." -ForegroundColor Red
141+
}
142+
143+
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
144+
$filename = "output_$timestamp.csv"
145+
146+
# Log into Azure
147+
Connect-AzAccount -ErrorAction Stop -tenantId $TenantId
148+
149+
Write-Host "Retrieving Subscriptions..." -ForegroundColor Cyan
150+
$Subscriptions = Get-AzSubscription -tenantId $TenantId
151+
152+
foreach ($sub in $Subscriptions) {
153+
$SubscriptionId = $sub.Id
154+
$subName = $sub.Name
155+
# Set sub ID
156+
Write-Host "Connecting to sub $SubscriptionId " -ForegroundColor Cyan
157+
Set-AzContext -Subscription $SubscriptionId -TenantId $tenantId | Out-Null
158+
159+
# Get all Data Factories in the subscription
160+
Write-Host "Retrieving Data Factories..." -ForegroundColor Cyan
161+
$dataFactories = Get-AzDataFactoryV2
162+
163+
if ($dataFactories.Count -eq 0) {
164+
Write-Host "No Data Factories found in subscription $SubscriptionId"
165+
}
166+
167+
foreach ($df in $dataFactories) {
168+
$resourceGroup = $df.ResourceGroupName
169+
$dataFactoryName = $df.DataFactoryName
170+
171+
$uri = "https://management.azure.com/subscriptions/$SubscriptionId/resourceGroups/$resourceGroup/providers/Microsoft.DataFactory/factories/$dataFactoryName/linkedservices?api-version=2018-06-01"
172+
173+
try {
174+
$response = Invoke-AzRestMethod -Method GET -Uri $uri
175+
$linkedServices = Get-AllLinkedServices -Uri $uri
176+
177+
178+
if ($linkedServices.Count -eq 0) {
179+
continue
180+
}
181+
182+
foreach ($ls in $linkedServices) {
183+
$name = $ls.name
184+
$type = $ls.properties.type
185+
$version = $ls.properties.version
186+
$typeProps = $ls.properties.typeProperties | ConvertTo-Json -Depth 10 | ConvertFrom-Json
187+
188+
if ($LegacyV1LSTypes -contains $type) {
189+
Print-Result -subName $subName -dfName $dataFactoryName -lsName $name -lsType $type -outputFileName $filename
190+
}
191+
192+
# Find v1 versions.
193+
if ($LegacyV1VersionLSTypes -contains $type) {
194+
if ($version -ne "2.0") { # Skip version 2.0, it must be non-legacy
195+
switch ($type) { # MySql and MariaDB are not following the version design, hence, need some custom logic here
196+
{($_ -eq "MariaDB") -or ($_ -eq "MySql")} {
197+
$connectionString = $typeProps.connectionString
198+
if (-not [string]::IsNullOrEmpty($connectionString)) {
199+
Print-Result -subName $subName -dfName $dataFactoryName -lsName $name -lsType $type -outputFileName $filename
200+
}
201+
break
202+
}
203+
default {
204+
Print-Result -subName $subName -dfName $dataFactoryName -lsName $name -lsType $type -outputFileName $filename
205+
break
206+
}
207+
}
208+
}
209+
}
210+
}
211+
} catch {
212+
Write-Host "Failed to fetch linked services for $dataFactoryName" -ForegroundColor Red
213+
}
214+
}
215+
}

0 commit comments

Comments
 (0)