Skip to content

Commit

Permalink
BugFix for Windows Powershell
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudio-Merola committed Jul 5, 2024
1 parent e3015dc commit 6b7630f
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions AzureResourceInventory.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# #
# * Azure Resource Inventory ( ARI ) Report Generator * #
# #
# Version: 3.1.30 #
# Version: 3.1.31 #
# #
# Date: 07/05/2024 #
# #
Expand Down Expand Up @@ -318,7 +318,7 @@ param ($TenantID,
}
else
{
$AZConfig = az config get core.enable_broker_on_windows | ConvertFrom-Json
$AZConfig = az config get core.enable_broker_on_windows --only-show-errors | ConvertFrom-Json
if ($AZConfig.value -eq $true)
{
az config set core.enable_broker_on_windows=false --only-show-errors
Expand Down Expand Up @@ -1102,10 +1102,11 @@ param ($TenantID,
$Modules | ForEach-Object {
If ($RunOnline -eq $true) {
$Modul = $_.split('/')
$ModName = $Modul[2].split(".ps1")[0]
$ModName = $Modul[2]
$ModName = $ModName.replace(".ps1","")
$ModuSeq = (New-Object System.Net.WebClient).DownloadString($RawRepo + '/' + $_)
} Else {
$ModName = $_.Name.split(".ps1")[0]
$ModName = $_.Name.replace(".ps1","")
$ModuSeq0 = New-Object System.IO.StreamReader($_.FullName)
$ModuSeq = $ModuSeq0.ReadToEnd()
$ModuSeq0.Dispose()
Expand All @@ -1129,9 +1130,10 @@ param ($TenantID,
$Modules | ForEach-Object {
If ($RunOnline -eq $true) {
$Modul = $_.split('/')
$ModName = $Modul[2].split(".ps1")[0]
$ModName = $Modul[2]
$ModName = $ModName.replace(".ps1","")
} Else {
$ModName = $_.Name.split(".ps1")[0]
$ModName = $_.Name.replace(".ps1","")
}
Start-Sleep -Milliseconds 250

Expand All @@ -1151,9 +1153,10 @@ param ($TenantID,
$Modules | ForEach-Object {
If ($RunOnline -eq $true) {
$Modul = $_.split('/')
$ModName = $Modul[2].split(".ps1")[0]
$ModName = $Modul[2]
$ModName = $ModName.replace(".ps1","")
} Else {
$ModName = $_.Name.split(".ps1")[0]
$ModName = $_.Name.replace(".ps1","")
}
Start-Sleep -Milliseconds 250

Expand Down Expand Up @@ -1261,8 +1264,6 @@ param ($TenantID,

foreach ($Module in $Modules) {

Write-Debug ((get-date -Format 'yyyy-MM-dd_HH_mm_ss')+' - '+"Running Module: '$Module'")

$c = (($ReportCounter / $Lops) * 100)
$c = [math]::Round($c)
Write-Progress -Id 1 -activity "Building Report" -Status "$c% Complete." -PercentComplete $c
Expand All @@ -1276,18 +1277,28 @@ param ($TenantID,
$ModuSeq = $ModuSeq0.ReadToEnd()
$ModuSeq0.Dispose()
}
Start-Sleep -Milliseconds 50
$ModuleName = $Module.name.replace('.ps1','')

$ModuleResourceCount = $SmaResources[$ModuleName].count

if ($ModuleResourceCount -gt 0)
{
Start-Sleep -Milliseconds 100
Write-Debug ((get-date -Format 'yyyy-MM-dd_HH_mm_ss')+' - '+"Running Module: '$ModuleName'. Resources Count: $ModuleResourceCount")

$ExcelRun = ([PowerShell]::Create()).AddScript($ModuSeq).AddArgument($PSScriptRoot).AddArgument($null).AddArgument($InTag).AddArgument($null).AddArgument('Reporting').AddArgument($file).AddArgument($SmaResources).AddArgument($TableStyle).AddArgument($Unsupported)
$ExcelRun = ([PowerShell]::Create()).AddScript($ModuSeq).AddArgument($PSScriptRoot).AddArgument($null).AddArgument($InTag).AddArgument($null).AddArgument('Reporting').AddArgument($file).AddArgument($SmaResources).AddArgument($TableStyle).AddArgument($Unsupported)

$ExcelJob = $ExcelRun.BeginInvoke()
$ExcelJob = $ExcelRun.BeginInvoke()

while ($ExcelJob.IsCompleted -contains $false) { Start-Sleep -Milliseconds 100 }
while ($ExcelJob.IsCompleted -contains $false) { Start-Sleep -Milliseconds 100 }

$ExcelRun.EndInvoke($ExcelJob)
$ExcelRun.EndInvoke($ExcelJob)

$ExcelRun.Dispose()
$ExcelRun.Dispose()

[System.GC]::GetTotalMemory($true) | out-null
[System.GC]::GetTotalMemory($true) | out-null
}

$ReportCounter ++

Expand Down Expand Up @@ -1636,4 +1647,5 @@ if(!$SkipDiagram.IsPresent)
write-host $DDFile -ForegroundColor Cyan
Write-Host ''
}
Clear-Variable -Name Resources -Scope Global
Clear-Variable -Name Resources -Scope Global
Clear-Variable -Name SmaResources -Scope Global

0 comments on commit 6b7630f

Please sign in to comment.