Skip to content

Commit 1a6d71a

Browse files
3.5.1
1 parent e58f7b6 commit 1a6d71a

File tree

11 files changed

+406
-256
lines changed

11 files changed

+406
-256
lines changed

AzureResourceInventory.psm1

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@
6666
Function Invoke-ARI {
6767
param ([ValidateSet('AzureCloud', 'AzureUSGovernment')]
6868
$AzureEnvironment = 'AzureCloud',
69+
[ValidateSet(1, 2, 3)]
70+
$Overview = 1,
6971
$TenantID,
72+
$AppId,
73+
[Security.SecureString]$Secret,
7074
$SubscriptionID,
7175
$ManagementGroup,
7276
[string[]]$ResourceGroup,
@@ -175,23 +179,26 @@ param ([ValidateSet('AzureCloud', 'AzureUSGovernment')]
175179

176180
if ($PlatOS -ne 'Azure CloudShell' -and !$Automation.IsPresent)
177181
{
178-
$TenantID = Connect-ARILoginSession -AzureEnvironment $AzureEnvironment -TenantID $TenantID -SubscriptionID $SubscriptionID -DeviceLogin $DeviceLogin
182+
$TenantID = Connect-ARILoginSession -AzureEnvironment $AzureEnvironment -TenantID $TenantID -SubscriptionID $SubscriptionID -DeviceLogin $DeviceLogin, -AppId $AppId -Secret $Secret
179183
}
180184
elseif ($Automation.IsPresent)
181185
{
182186
try {
183187
$AzureConnection = (Connect-AzAccount -Identity).context
184188

185189
Set-AzContext -SubscriptionName $AzureConnection.Subscription -DefaultProfile $AzureConnection
186-
187-
$StorageContext = New-AzStorageContext -StorageAccountName $StorageAccount -UseConnectedAccount
188190
}
189191
catch {
190192
Write-Output "Failed to set Automation Account requirements. Aborting."
191193
exit
192194
}
193195
}
194196

197+
if ($StorageAccount)
198+
{
199+
$StorageContext = New-AzStorageContext -StorageAccountName $StorageAccount -UseConnectedAccount
200+
}
201+
195202
$Subscriptions = Get-ARISubscriptions -TenantID $TenantID -SubscriptionID $SubscriptionID
196203

197204
if ($PlatOS -eq 'Azure CloudShell')
@@ -298,7 +305,7 @@ param ([ValidateSet('AzureCloud', 'AzureUSGovernment')]
298305
$polco = [string]$PolicyAssign.policyAssignments.Count
299306

300307
#### Creating Excel file variable:
301-
if ($Automation.IsPresent)
308+
if ($StorageAccount)
302309
{
303310
$Date = get-date -Format "yyyy-MM-dd_HH_mm"
304311

@@ -318,9 +325,9 @@ param ([ValidateSet('AzureCloud', 'AzureUSGovernment')]
318325

319326
Write-Debug ((get-date -Format 'yyyy-MM-dd_HH_mm_ss')+' - '+'Starting Resources Report Function.')
320327

321-
Build-AzureResourceReport -Subscriptions $Subscriptions -ExtractionRunTime $ExtractionRuntime -Resources $Resources -SecurityCenter $SecurityCenter -File $File -DDFile $DDFile -SkipDiagram $SkipDiagram -RunLite $RunLite -PlatOS $PlatOS -InTag $InTag -SkipPolicy $SkipPolicy -SkipAdvisory $SkipAdvisory -Automation $Automation -SkipAPIs $SkipAPIs -Debug $Debug
328+
Build-AzureResourceReport -Subscriptions $Subscriptions -DefaultPath $DefaultPath -ExtractionRunTime $ExtractionRuntime -Resources $Resources -SecurityCenter $SecurityCenter -File $File -DDFile $DDFile -SkipDiagram $SkipDiagram -RunLite $RunLite -PlatOS $PlatOS -InTag $InTag -SkipPolicy $SkipPolicy -SkipAdvisory $SkipAdvisory -Automation $Automation -SkipAPIs $SkipAPIs, -Overview $Overview -Debug $Debug
322329

323-
if ($Automation.IsPresent)
330+
if ($StorageAccount)
324331
{
325332
Set-AzStorageBlobContent -File $File -Container $StorageContainer -Context $StorageContext | Out-Null
326333
}

Modules/ARIResourceJobs.psm1

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,19 @@ function Start-ARIResourceJobs {
1616
$EnvSizeLooper = 1000
1717
$DebugEnvSize = 'Small'
1818
}
19-
{$_ -gt 1000 -and $_ -le 30000}
19+
{$_ -gt 1000 -and $_ -le 10000}
2020
{
21-
$EnvSizeLooper = 5000
21+
$EnvSizeLooper = 2500
2222
$DebugEnvSize = 'Medium'
2323
}
24-
{$_ -gt 30000 -and $_ -le 60000}
24+
{$_ -gt 10000}
2525
{
26-
$EnvSizeLooper = 10000
26+
$EnvSizeLooper = 5000
2727
$DebugEnvSize = 'Large'
2828
Write-Host $DebugEnvSize -NoNewline -ForegroundColor Green
2929
Write-Host (' Size Environment Identified.')
3030
Write-Host ('Jobs will be run in batches to avoid CPU Overload.')
3131
}
32-
{$_ -gt 60000}
33-
{
34-
$EnvSizeLooper = 5000
35-
$DebugEnvSize = 'Enormous'
36-
Write-Host $DebugEnvSize -NoNewline -ForegroundColor Green
37-
Write-Host (' Size Environment Identified.')
38-
Write-Host ('Jobs will be run in batches to prevent CPU Overload.')
39-
}
4032
}
4133
Write-Debug ((get-date -Format 'yyyy-MM-dd_HH_mm_ss')+' - '+'Starting Processing Jobs in '+ $DebugEnvSize +' Mode.')
4234

@@ -135,7 +127,7 @@ function Start-ARIResourceJobs {
135127
} -ArgumentList $null, $PSScriptRoot, $Subscriptions, $InTag, $Resource, 'Processing', $null, $null, $null, $Unsupported | Out-Null
136128
$Limit = $Limit + $EnvSizeLooper
137129
Start-Sleep -Milliseconds 250
138-
if($DebugEnvSize -in ('Large','Enormous') -and $JobLoop -eq 5)
130+
if($DebugEnvSize -in ('Large') -and $JobLoop -eq 5)
139131
{
140132
Write-Debug ((get-date -Format 'yyyy-MM-dd_HH_mm_ss')+' - '+'Waiting Batch of Jobs to Complete.')
141133

Modules/ARIResourcesReport.psm1

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function Start-ARIResourceReporting {
2-
Param($InTag, $file, $SmaResources, $TableStyle, $Unsupported, $DebugEnvSize, $DataActive, $Debug)
2+
Param($InTag, $file, $SmaResources, $DefaultPath, $TableStyle, $Unsupported, $DebugEnvSize, $DataActive, $Debug)
33
if ($Debug.IsPresent)
44
{
55
$DebugPreference = 'Continue'
@@ -26,6 +26,12 @@ function Start-ARIResourceReporting {
2626
$Lops = $Modules.count
2727
$ReportCounter = 0
2828

29+
if($DebugEnvSize -eq 'Large')
30+
{
31+
Write-Debug ((get-date -Format 'yyyy-MM-dd_HH_mm_ss')+' - '+'Looking for Cache Files.')
32+
$LocalCacheFiles = Get-ChildItem -Path ($DefaultPath+'\ReportCache\*.json')
33+
}
34+
2935
foreach ($Module in $Modules) {
3036

3137
$c = (($ReportCounter / $Lops) * 100)
@@ -38,6 +44,21 @@ function Start-ARIResourceReporting {
3844
Start-Sleep -Milliseconds 50
3945
$ModuleName = $Module.name.replace('.ps1','')
4046

47+
if($DebugEnvSize -eq 'Large')
48+
{
49+
$SmaResources = foreach ($LocalFile in $LocalCacheFiles)
50+
{
51+
$TempContent = Get-Content -Path $LocalFile | ConvertFrom-Json
52+
if ($TempContent.$ModuleName.count -gt 0)
53+
{
54+
$TempVar = @{
55+
$ModuleName = $TempContent.$ModuleName
56+
}
57+
}
58+
$TempVar
59+
}
60+
}
61+
4162
$ModuleResourceCount = $SmaResources.$ModuleName.count
4263

4364
if ($ModuleResourceCount -gt 0)
@@ -49,7 +70,7 @@ function Start-ARIResourceReporting {
4970

5071
$ExcelJob = $ExcelRun.BeginInvoke()
5172

52-
while ($ExcelJob.IsCompleted -contains $false) { Start-Sleep -Milliseconds 100 }
73+
while ($ExcelJob.IsCompleted -contains $false) { Start-Sleep -Milliseconds 500 }
5374

5475
$ExcelRun.EndInvoke($ExcelJob)
5576

@@ -58,14 +79,20 @@ function Start-ARIResourceReporting {
5879
[System.GC]::GetTotalMemory($true) | out-null
5980
}
6081

82+
if($DebugEnvSize -eq 'Large')
83+
{
84+
Clear-Variable SmaResources
85+
[System.GC]::GetTotalMemory($true) | out-null
86+
}
87+
6188
$ReportCounter ++
6289

6390
}
6491

65-
if($DebugEnvSize -in ('Large','Enormous'))
92+
if($DebugEnvSize -eq 'Large')
6693
{
67-
Clear-Variable SmaResources -Scope Global
68-
[System.GC]::GetTotalMemory($true) | out-null
94+
Write-Debug ((get-date -Format 'yyyy-MM-dd_HH_mm_ss')+' - '+'Cleaning Cache Files.')
95+
Remove-Item -Path ($DefaultPath+'\ReportCache\') -Recurse
6996
}
7097

7198
Write-Debug ((get-date -Format 'yyyy-MM-dd_HH_mm_ss')+' - '+'Resource Reporting Phase Done.')

Modules/Core/ARILoginSession.psm1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Authors: Claudio Merola
1818
1919
#>
2020
function Connect-ARILoginSession {
21-
Param($AzureEnvironment,$TenantID,$SubscriptionID,$DeviceLogin,$Debug)
21+
Param($AzureEnvironment, $TenantID, $SubscriptionID, $DeviceLogin, $AppId, $Secret, $Debug)
2222
if ($Debug.IsPresent)
2323
{
2424
$DebugPreference = 'Continue'
@@ -97,6 +97,11 @@ function Connect-ARILoginSession {
9797
{
9898
Connect-AzAccount -Tenant $TenantID -UseDeviceAuthentication -Environment $AzureEnvironment | Out-Null
9999
}
100+
elseif($AppId -and $Secret -and $TenantID)
101+
{
102+
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $AppId, $Secret
103+
Connect-AzAccount -ServicePrincipal -TenantId $TenantId -Credential $Credential
104+
}
100105
else
101106
{
102107
try

Modules/Extras/ARIReportCharts.psm1

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Authors: Claudio Merola
1818
1919
#>
2020
function Build-ARIExcelChart {
21-
param($File, $TableStyle, $PlatOS, $Subscriptions, $ExtractionRunTime, $ReportingRunTime, $RunLite, $Debug)
21+
param($File, $TableStyle, $PlatOS, $Subscriptions, $ExtractionRunTime, $ReportingRunTime, $RunLite, $Overview, $Debug)
2222
if ($Debug.IsPresent)
2323
{
2424
$DebugPreference = 'Continue'
@@ -34,6 +34,15 @@ function Build-ARIExcelChart {
3434
$ScriptVersion = [string]$ARIMod.Version
3535
Write-Debug ((get-date -Format 'yyyy-MM-dd_HH_mm_ss')+' - '+'Starting Excel Charts Customization.')
3636

37+
if ($RunLite)
38+
{
39+
Write-Debug ((get-date -Format 'yyyy-MM-dd_HH_mm_ss')+' - '+'Running in Lite Mode.')
40+
}
41+
else
42+
{
43+
Write-Debug ((get-date -Format 'yyyy-MM-dd_HH_mm_ss')+' - '+'Running in Full Mode.')
44+
}
45+
3746
if(!$RunLite)
3847
{
3948
$Excel = New-Object -TypeName OfficeOpenXml.ExcelPackage $File
@@ -318,31 +327,31 @@ function Build-ARIExcelChart {
318327
$P00Name = 'Resources'
319328
}
320329
$DrawP0 = $WS.Drawings | Where-Object { $_.Name -eq 'TP0' }
321-
if ($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'Outages' }) {
330+
if (($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'Outages' }) -and $Overview -eq 1) {
322331
$P0Name = 'Outages'
323332
}
324-
elseif ($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'Advisor' }) {
333+
elseif (($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'Advisor' }) -and $Overview -eq 2) {
325334
$P0Name = 'Advisories'
326335
}
327336
else {
328337
$P0Name = 'Public IPs'
329338
}
330339
$DrawP0.RichText.Add($P0Name) | Out-Null
331340

332-
if ($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'AdvisorScore' }) {
341+
if (($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'AdvisorScore' }) -and $Overview -eq 1) {
333342
$P1Name = 'AdvisorScore'
334343
}
335-
elseif ($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'Subscriptions' }) {
344+
elseif (($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'Subscriptions' }) -and $Overview -eq 2) {
336345
$P1Name = 'Subscriptions'
337346
}
338347
$DrawP1 = $WS.Drawings | Where-Object { $_.Name -eq 'TP1' }
339348
$DrawP1.RichText.Add($P1Name) | Out-Null
340349

341350
$DrawP2 = $WS.Drawings | Where-Object { $_.Name -eq 'TP2' }
342-
if ($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'Policy' }) {
351+
if (($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'Policy' }) -and $Overview -eq 1) {
343352
$P2Name = 'Policy'
344353
}
345-
elseif ($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'Advisor' }) {
354+
elseif (($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'Advisor' }) -and $Overview -eq 2) {
346355
$P2Name = 'Annual Savings'
347356
}
348357
else {
@@ -352,10 +361,10 @@ function Build-ARIExcelChart {
352361
$DrawP2.RichText.Add($P2Name) | Out-Null
353362

354363
$DrawP3 = $WS.Drawings | Where-Object { $_.Name -eq 'TP3' }
355-
if ($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'SupportTickets' }) {
364+
if (($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'SupportTickets' }) -and $Overview -eq 1) {
356365
$P3Name = 'SupportTickets'
357366
}
358-
elseif ($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'AKS' }) {
367+
elseif (($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'AKS' }) -and $Overview -eq 2) {
359368
$P3Name = 'Azure Kubernetes'
360369
}
361370
else {
@@ -364,10 +373,10 @@ function Build-ARIExcelChart {
364373
$DrawP3.RichText.Add($P3Name) | Out-Null
365374

366375
$DrawP4 = $WS.Drawings | Where-Object { $_.Name -eq 'TP4' }
367-
if ($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'Outages' }) {
376+
if (($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'Outages' }) -and $Overview -eq 1) {
368377
$P4Name = 'Outages'
369378
}
370-
elseif ($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'Quota Usage' }) {
379+
elseif (($Excel.Workbook.Worksheets | Where-Object { $_.Name -eq 'Quota Usage' }) -and $Overview -eq 2) {
371380
$P4Name = 'Quota Usage'
372381
}
373382
else {

0 commit comments

Comments
 (0)