# Make sure you have the required Azure PowerShell modules installed
# Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
# Login to Azure
Connect-AzAccount
# Define the input JSON-like structure
$jsonInput = 'your-json-string-here'
$data = ConvertFrom-Json $jsonInput
# Function to get resource group name by ID substring
function Get-ResourceGroupName($idSubstring) {
$resourceGroups = Get-AzResourceGroup | Where-Object { $_.ResourceGroupName -like "*$idSubstring*" }
return $resourceGroups.ResourceGroupName
}
# Function to get function app config settings
function Get-FunctionAppConfig($functionAppName) {
$appSettings = Get-AzWebApp -Name $functionAppName | Select -ExpandProperty SiteConfig.AppSettings
return $appSettings
}
# Process each resource group and function app
foreach ($rg in $data.resourceGroups) {
$resourceGroupName = Get-ResourceGroupName -idSubstring $rg.id
foreach ($app in $rg.functionApps) {
$actualConfig = Get-FunctionAppConfig -functionAppName $app.name
foreach ($key in $app.configSettings.PSObject.Properties.Name) {
$expectedValue = $app.configSettings.$key
$actualValue = $actualConfig | Where-Object { $_.Name -eq $key } | Select-Object -ExpandProperty Value
$match = $actualValue -eq $expectedValue
$result = [PSCustomObject]@{
ResourceGroup = $resourceGroupName
ResourceType = "Azure Function App"
ResourceName = $app.name
ConfigKey = $key
ConfigValue = $actualValue
ExpectedValue = $expectedValue
Match = $match
}
$result | Format-Table -AutoSize
}
}
}
尝试使用azure func应用程序。我需要能够与 azure 数据工厂进行相同的操作,以便可以列出并比较键值对 int e 设置和配置
需要能够对 Azure 数据工厂执行相同的操作:
Get-AzDataFactoryV2LinkedService
,
Get-AzDataFactoryV2
PowerShell 命令,列出了数据工厂的所有相关信息,完整的 PowerShell 脚本详述如下。
$jsonInput = Get-content -path "/home/xxx/modifiedjson.json"
$data = $jsonInput | convertFrom-json
function Get-ResourceGroupName($idSubstring) {
$resourceGroups = Get-AzResourceGroup | Where-Object { $_.ResourceGroupName -eq "*$idSubstring*" }
return $resourceGroups.ResourceGroupName
}
$resourceGroupName = "xxxx"
$dataFactoryName="xxxxdfactory"
# Function to get Data Factory config settings
function Get-DataFactoryConfig($dataFactoryName, $resourceGroupName) {
$adf = Get-AzDataFactoryV2 -Name $dataFactoryName -ResourceGroupName $resourceGroupName
$adfConfig = Get-AzDataFactoryV2LinkedService -ResourceGroupName $resourceGroupName -DataFactoryName $dataFactoryName | Select -ExpandProperty Properties
return $adfConfig
}
# Process each resource group and Data Factory
foreach ($rg in $data.resourceGroups) {
$resourceGroupName = Get-ResourceGroupName -idSubstring $rg.id
foreach ($adf in $rg.dataFactories) {
$actualConfig = Get-DataFactoryConfig -dataFactoryName $adf.name -resourceGroupName $resourceGroupName
foreach ($key in $adf.configSettings.PSObject.Properties.Name) {
$expectedValue = $adf.configSettings.$key
$actualValue = $actualConfig | Where-Object { $_.Name -eq $key } | Select-Object -ExpandProperty Value
$match = $actualValue -eq $expectedValue
$result = [PSCustomObject]@{
ResourceGroup = $resourceGroupName
ResourceType = "Azure Data Factory"
ResourceName = $adf.name
ConfigKey = $key
ConfigValue = $actualValue
ExpectedValue = $expectedValue
Match = $match
}
$result | Format-Table -AutoSize
}
}
}
输出: