Skip to content

Commit a2e26c4

Browse files
Merge pull request #395 from Marc013/Support-PSResourceGet
Added PSResourceGet support for auto update
2 parents 5f54f3b + bbf5ac3 commit a2e26c4

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

Modules/Public/PublicFunctions/Invoke-ARI.ps1

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Function Invoke-ARI {
124124
[CmdletBinding(PositionalBinding=$false)]
125125
param (
126126
[ValidateSet(1, 2, 3)]
127-
[int]$Overview = 1,
127+
[int]$Overview = 1,
128128
[ValidateSet('AzureCloud', 'AzureUSGovernment', 'AzureChinaCloud', 'AzureGermanCloud')]
129129
[string]$AzureEnvironment = 'AzureCloud',
130130
[string]$TenantID,
@@ -182,7 +182,7 @@ Function Invoke-ARI {
182182

183183
if ($Lite.IsPresent) { $RunLite = $true }else { $RunLite = $false }
184184
if ($DiagramFullEnvironment.IsPresent) {$FullEnv = $true}else{$FullEnv = $false}
185-
if ($Automation.IsPresent)
185+
if ($Automation.IsPresent)
186186
{
187187
$SkipAPIs = $true
188188
$RunLite = $true
@@ -265,11 +265,21 @@ Function Invoke-ARI {
265265
{
266266
$TenantID = Connect-ARILoginSession -AzureEnvironment $AzureEnvironment -TenantID $TenantID -SubscriptionID $SubscriptionID -DeviceLogin $DeviceLogin -AppId $AppId -Secret $Secret -CertificatePath $CertificatePath
267267

268-
if (!$NoAutoUpdate.IsPresent)
269-
{
270-
Write-Host ('Checking for Powershell Module Updates..')
268+
if (!$NoAutoUpdate.IsPresent) {
269+
Write-Host ('Checking for Powershell Module Updates..')
270+
if (Get-InstalledModule -Name AzureResourceInventory -ErrorAction SilentlyContinue) {
271271
Update-Module -Name AzureResourceInventory -AcceptLicense
272272
}
273+
elseif (Get-InstalledPSResource -Name AzureResourceInventory -Scope CurrentUser -ErrorAction SilentlyContinue) {
274+
Update-PSResource -Name AzureResourceInventory -Scope CurrentUser -AcceptLicense
275+
}
276+
elseif (Get-InstalledPSResource -Name AzureResourceInventory -Scope AllUsers -ErrorAction SilentlyContinue) {
277+
Update-PSResource -Name AzureResourceInventory -Scope AllUsers -AcceptLicense
278+
}
279+
else {
280+
Write-Warning 'Unable to update AzureResourceInventory module. It is not installed from the PowerShell Gallery. Skipping update.'
281+
}
282+
}
273283
}
274284
elseif ($Automation.IsPresent)
275285
{
@@ -279,7 +289,7 @@ Function Invoke-ARI {
279289
Set-AzContext -SubscriptionName $AzureConnection.Subscription -DefaultProfile $AzureConnection
280290
}
281291
catch {
282-
Write-Output "Failed to set Automation Account requirements. Aborting."
292+
Write-Output "Failed to set Automation Account requirements. Aborting."
283293
exit
284294
}
285295
}
@@ -355,7 +365,7 @@ Function Invoke-ARI {
355365
$File = Join-Path $DefaultPath $FileName
356366
#$DFile = ($DefaultPath + $Global:ReportName + "_Diagram_" + (get-date -Format "yyyy-MM-dd_HH_mm") + ".vsdx")
357367
$DDName = ($ReportName + "_Diagram_" + (get-date -Format "yyyy-MM-dd_HH_mm") + ".xml")
358-
$DDFile = Join-Path $DefaultPath $DDName
368+
$DDFile = Join-Path $DefaultPath $DDName
359369

360370
Write-Debug ((get-date -Format 'yyyy-MM-dd_HH_mm_ss')+' - '+'Excel file: ' + $File)
361371

0 commit comments

Comments
 (0)