From 840105475cdad04ac6cbfea46206e7fab5a68b25 Mon Sep 17 00:00:00 2001 From: davide_martusciello Date: Fri, 29 Sep 2023 12:18:13 +0200 Subject: [PATCH 1/3] param resourcegroup as array of strings and conversion in graph query --- AzureResourceInventory.ps1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/AzureResourceInventory.ps1 b/AzureResourceInventory.ps1 index d3747dd..1dbe8c4 100644 --- a/AzureResourceInventory.ps1 +++ b/AzureResourceInventory.ps1 @@ -71,7 +71,7 @@ param ($TenantID, $ManagementGroup, $Appid, $Secret, - $ResourceGroup, + [string[]]$ResourceGroup, $TagKey, $TagValue, [switch]$SkipAdvisory, @@ -113,7 +113,7 @@ param ($TenantID, Write-Host "" Write-Host " -TenantID : Specifies the Tenant to be inventoried. " Write-Host " -SubscriptionID : Specifies Subscription(s) to be inventoried. " - Write-Host " -ResourceGroup : Specifies one unique Resource Group to be inventoried, This parameter requires the -SubscriptionID to work. " + Write-Host " -ResourceGroup : Specifies one (or more) unique Resource Group to be inventoried, This parameter requires the -SubscriptionID to work. " Write-Host " -TagKey : Specifies the tag key to be inventoried, This parameter requires the -SubscriptionID to work. " Write-Host " -TagValue : Specifies the tag value be inventoried, This parameter requires the -SubscriptionID to work. " Write-Host " -SkipAdvisory : Do not collect Azure Advisory. " @@ -545,7 +545,7 @@ param ($TenantID, $Subscri = $SubscriptionID - $GraphQuery = "resources | where resourceGroup == '$ResourceGroup' and strlen(properties.definition.actions) < 123000 | summarize count()" + $GraphQuery = "resources | where resourceGroup in ('$([String]::Join("','",$ResourceGroup))') and strlen(properties.definition.actions) < 123000 | summarize count()" $EnvSize = az graph query -q $GraphQuery --subscriptions $Subscri --output json --only-show-errors | ConvertFrom-Json $EnvSizeNum = $EnvSize.data.'count_' @@ -556,7 +556,7 @@ param ($TenantID, $Limit = 0 while ($Looper -lt $Loop) { - $GraphQuery = "resources | where resourceGroup == '$ResourceGroup' and strlen(properties.definition.actions) < 123000 | project id,name,type,tenantId,kind,location,resourceGroup,subscriptionId,managedBy,sku,plan,properties,identity,zones,extendedLocation$($GraphQueryTags) | order by id asc" + $GraphQuery = "resources | where resourceGroup in ('$([String]::Join("','",$ResourceGroup))') and strlen(properties.definition.actions) < 123000 | project id,name,type,tenantId,kind,location,resourceGroup,subscriptionId,managedBy,sku,plan,properties,identity,zones,extendedLocation$($GraphQueryTags) | order by id asc" $Resource = (az graph query -q $GraphQuery --subscriptions $Subscri --skip $Limit --first 1000 --output json --only-show-errors).tolower() | ConvertFrom-Json $Global:Resources += $Resource.data @@ -784,7 +784,7 @@ param ($TenantID, $GraphQueryExtension = "| join kind=inner (resourcecontainers | where type == 'microsoft.resources/subscriptions' | mv-expand managementGroupParent = properties.managementGroupAncestorsChain | where managementGroupParent.name =~ '$ManagementGroup' | project subscriptionId, managanagementGroup = managementGroupParent.name) on subscriptionId" } if (![string]::IsNullOrEmpty($ResourceGroup)) { - $GraphQueryExtension = "$GraphQueryExtension | where resourceGroup == '$ResourceGroup'" + $GraphQueryExtension = "$GraphQueryExtension | where resourceGroup in ('$([String]::Join("','",$ResourceGroup))')" } $GraphQuery = "advisorresources $GraphQueryExtension | summarize count()" @@ -835,7 +835,7 @@ param ($TenantID, $GraphQueryExtension = "| join kind=inner (resourcecontainers | where type == 'microsoft.resources/subscriptions' | mv-expand managementGroupParent = properties.managementGroupAncestorsChain | where managementGroupParent.name =~ '$ManagementGroup' | project subscriptionId, managanagementGroup = managementGroupParent.name) on subscriptionId" } if (![string]::IsNullOrEmpty($ResourceGroup)) { - $GraphQueryExtension = "$GraphQueryExtension | where resourceGroup == '$ResourceGroup'" + $GraphQueryExtension = "$GraphQueryExtension | where resourceGroup in ('$([String]::Join("','",$ResourceGroup))')" } #$SecSize = az graph query -q "securityresources | where properties['status']['code'] == 'Unhealthy' | summarize count()" --subscriptions $Subscri --output json --only-show-errors | ConvertFrom-Json $SecSize = az graph query -q "securityresources $GraphQueryExtension | where properties['status']['code'] == 'Unhealthy' | summarize count()" --output json --only-show-errors | ConvertFrom-Json @@ -880,7 +880,7 @@ param ($TenantID, $GraphQueryExtension = "| join kind=inner (resourcecontainers | where type == 'microsoft.resources/subscriptions' | mv-expand managementGroupParent = properties.managementGroupAncestorsChain | where managementGroupParent.name =~ '$ManagementGroup' | project subscriptionId, managanagementGroup = managementGroupParent.name) on subscriptionId" } if (![string]::IsNullOrEmpty($ResourceGroup)) { - $GraphQueryExtension = "$GraphQueryExtension | where resourceGroup == '$ResourceGroup'" + $GraphQueryExtension = "$GraphQueryExtension | where resourceGroup in ('$([String]::Join("','",$ResourceGroup))')" } #$AVDSize = az graph query -q "desktopvirtualizationresources | summarize count()" --subscriptions $Subscri --output json --only-show-errors | ConvertFrom-Json $AVDSize = az graph query -q "desktopvirtualizationresources $GraphQueryExtension | summarize count()" --output json --only-show-errors | ConvertFrom-Json From 1783c55b41e243c63350da1b7d40e9388a29e16d Mon Sep 17 00:00:00 2001 From: Claudio Merola <108147804+Claudio-Merola@users.noreply.github.com> Date: Fri, 29 Sep 2023 12:06:27 -0300 Subject: [PATCH 2/3] 3.1.5 --- Automation/ARI_Automation.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Automation/ARI_Automation.ps1 b/Automation/ARI_Automation.ps1 index 85726c9..26ee37d 100644 --- a/Automation/ARI_Automation.ps1 +++ b/Automation/ARI_Automation.ps1 @@ -12,7 +12,7 @@ https://github.com/microsoft/ARI/Automation/ARI_Automation.ps1 This powershell Script is part of Azure Resource Inventory (ARI) .NOTES -Version: 3.1.4 +Version: 3.1.5 First Release Date: 19th November, 2020 Authors: Claudio Merola @@ -94,7 +94,7 @@ Write-Output 'Extracting Advisories' } -$Subscriptions = Get-AzContext -ListAvailable | Where-Object {$_.Subscription.State -ne 'Disabled'} +$Subscriptions = Get-AzSubscription | Where-Object {$_.State -ne 'Disabled'} $Subscriptions = $Subscriptions.Subscription if($RunDebug) { @@ -258,4 +258,4 @@ Write-Output 'Uploading Excel File to Storage Account' Set-AzStorageBlobContent -File $File -Container $aristg -Context $Context | Out-Null if($Diagram){Set-AzStorageBlobContent -File $DDFile -Container $aristg -Context $Context | Out-Null} -Write-Output 'Completed' \ No newline at end of file +Write-Output 'Completed' From 282db4c1dc2a1190b6a2d3b38faf07c333682b8a Mon Sep 17 00:00:00 2001 From: Claudio Merola <108147804+Claudio-Merola@users.noreply.github.com> Date: Fri, 29 Sep 2023 12:23:47 -0300 Subject: [PATCH 3/3] 3.1.6 --- Automation/ARI_Automation.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Automation/ARI_Automation.ps1 b/Automation/ARI_Automation.ps1 index 26ee37d..1c774c6 100644 --- a/Automation/ARI_Automation.ps1 +++ b/Automation/ARI_Automation.ps1 @@ -12,7 +12,7 @@ https://github.com/microsoft/ARI/Automation/ARI_Automation.ps1 This powershell Script is part of Azure Resource Inventory (ARI) .NOTES -Version: 3.1.5 +Version: 3.1.6 First Release Date: 19th November, 2020 Authors: Claudio Merola @@ -47,7 +47,7 @@ $RunDebug = $false <######################################################### SCRIPT ######################################################################> -Clear-AzContext -Force +#Clear-AzContext -Force Connect-AzAccount -Identity