Skip to content

Commit

Permalink
Populate AzurePS demand if Az module is installed on Agent machine (#…
Browse files Browse the repository at this point in the history
…1984)

* Populate AzurePS demand if Az module is installed on Agent machine

Populate AzurePS demand if Az module is installed on Agent machine

* Resolving comments

Resolving comments
  • Loading branch information
niadak authored and chshrikh committed Nov 27, 2018
1 parent 8553b6b commit d560086
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/Misc/layoutbin/powershell/Add-AzurePowerShellCapabilities.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ $script:capabilityName = "AzurePS"

function Get-FromModulePath {
[CmdletBinding()]
param([switch]$Classic)
param([string]$ModuleName)

# Determine which module to look for.
if ($Classic) {
$name = "Azure"
} else {
$name = "AzureRM"
# Valid ModuleName values are Az.Profile, AzureRM and Azure
# We are looking for Az.Profile module because "Get-Module -Name Az" is not working due to a known PowerShell bug.
if (($ModuleName -ne "Az.Profile") -and ($ModuleName -ne "AzureRM") -and ($ModuleName -ne "Azure")) {
Write-Host "Attempting to find invalid module."
return $false
}

# Attempt to resolve the module.
Write-Host "Attempting to find the module '$name' from the module path."
$module = Get-Module -Name $name -ListAvailable | Select-Object -First 1
Write-Host "Attempting to find the module '$ModuleName' from the module path."
$module = Get-Module -Name $ModuleName -ListAvailable | Select-Object -First 1
if (!$module) {
Write-Host "Not found."
return $false
}

if (!$Classic) {
if ($ModuleName -eq "AzureRM") {
# For AzureRM, validate the AzureRM.profile module can be found as well.
$profileName = "AzureRM.profile"
Write-Host "Attempting to find the module $profileName"
Expand Down Expand Up @@ -89,7 +89,8 @@ function Get-FromSdkPath {
}

Write-Host "Env:PSModulePath: '$env:PSModulePath'"
$null = (Get-FromModulePath -Classic:$false) -or
$null = (Get-FromModulePath -ModuleName:"Az.Profile") -or
(Get-FromModulePath -ModuleName:"AzureRM") -or
(Get-FromSdkPath -Classic:$false) -or
(Get-FromModulePath -Classic:$true) -or
(Get-FromModulePath -ModuleName:"Azure") -or
(Get-FromSdkPath -Classic:$true)

0 comments on commit d560086

Please sign in to comment.