Skip to content

. #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 26, 2015
Merged

. #116

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified tools/AzureRM/AzureRM.psd1
Binary file not shown.
84 changes: 67 additions & 17 deletions tools/AzureRM/AzureRM.psm1
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#Requires -RunAsAdministrator

$AzureRMProfileVersion = "0.9.8";

$AzureRMModules = @{
"Azure.Storage" = "0.9.8";
"AzureRM.ApiManagement" = "0.9.8";
Expand Down Expand Up @@ -25,12 +29,31 @@ $AzureRMModules = @{
"AzureRM.Websites" = "0.9.8"
}

function Import-ModuleWithVersionCheck([string]$Name,[string]$MinimumVersion,[string]$Repository,[string]$Scope)
{
$minVer = $MinimumVersion
$maxVer = "$($minVer.Split(".")[0]).9999.0"
try {
if ([string]::IsNullOrWhiteSpace($Repository))
{
Install-Module -Name $Name -Scope $Scope -MinimumVersion $minVer -MaximumVersion $maxVer -ErrorAction Stop
} else {
Install-Module -Name $Name -Repository $Repository -Scope $Scope -MinimumVersion $minVer -MaximumVersion $maxVer -ErrorAction Stop
}
$v = (Get-InstalledModule -Name $Name)[0].Version.ToString()
Write-Output "$Name $v installed..."
} catch {
Write-Warning "Skipping $Name package..."
Write-Warning $_
}
}

<#
.Synopsis
Install Azure Resource Manager cmdlet modules

.Description
Installs all the available Azure Resource Manager cmdlet modules that start with "AzureRM".
Installs all the available Azure Resource Manager cmdlet modules.

.Parameter Repository
Limit the search for "AzureRM" cmdlets in a specific repository.
Expand All @@ -41,12 +64,11 @@ $AzureRMModules = @{
function Update-AzureRM
{
param(
[Parameter(Position=0; Mandatory = $false)]
[Parameter(Position=0, Mandatory = $false)]
[string]
$Repository;

[Parameter(Position=1; Mandatory = $false)]
[ValidateSet("CurrentUser";"AllUsers")]
$Repository,
[Parameter(Position=1, Mandatory = $false)]
[ValidateSet("CurrentUser","AllUsers")]
[string]
$Scope)

Expand All @@ -57,19 +79,47 @@ function Update-AzureRM

Write-Output "Installing AzureRM modules."

$result = $AzureRMModules | ForEach {
Import-ModuleWithVersionCheck "AzureRM.Profile" $AzureRMProfileVersion $Repository $Scope

$result = $AzureRMModules.Keys | ForEach {
Start-Job -Name $_ -ScriptBlock {
if ([string]::IsNullOrWhiteSpace($args[1]))
{
Install-Module -Name $args[0] -Scope $args[2]
} else {
Install-Module -Name $args[0] -Repository $args[1] -Scope $args[2]
}
$v = (Get-InstalledModule -Name $args[0])[0].Version.ToString()
Write-Output "$($args[0]) $v installed..."
} -ArgumentList $_; $Repository; $Scope }
Import-ModuleWithVersionCheck $args[0] $args[1] $args[2] $args[3]
} -ArgumentList $_, $AzureRMModules[$_], $Repository, $Scope }

$AzureRMModules | ForEach {Get-Job -Name $_ | Wait-Job | Receive-Job }
$AzureRMModules.Keys | ForEach {Get-Job -Name $_ | Wait-Job | Receive-Job }
}

<#
.Synopsis
Remove Azure Resource Manager cmdlet modules

.Description
Removes all installed Azure Resource Manager cmdlet modules.
#>
function Uninstall-AzureRM
{
param(
[Parameter(Position=0, Mandatory = $false)]
[string]
$Repository)

Write-Output "Uninstalling AzureRM modules."

$installedModules = Get-InstalledModule

$AzureRMModules.Keys | ForEach {
$moduleName = $_
if (($installedModules | where {$_.Name -eq $moduleName}) -ne $null) {
Uninstall-Module -Name $_ -ErrorAction Stop
Write-Output "$moduleName uninstalled..."
}
}

if (($installedModules | where {"AzureRM.Profile" -eq $moduleName}) -ne $null) {
Uninstall-Module -Name "AzureRM.Profile" -ErrorAction Stop
Write-Output "AzureRM.Profile uninstalled..."
}
}

New-Alias -Name Install-AzureRM -Value Update-AzureRM
Export-ModuleMember -function * -Alias *