Skip to content

. #143

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
Oct 7, 2015
Merged

. #143

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
15 changes: 12 additions & 3 deletions setup-powershellget/Setup/ShortcutStartup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,19 @@ This may take some time...
$DefaultPSRepository = "PSGallery"
}

Install-Module AzureRM -Repository $DefaultPSRepository
Write-Output "AzureRM $((Get-InstalledModule -Name AzureRM)[0].Version) installed..."
$_InstallationPolicy = (Get-PSRepository -Name $DefaultPSRepository).InstallationPolicy
try
{
Set-PSRepository -Name $DefaultPSRepository -InstallationPolicy Trusted

Install-Module AzureRM -Repository $DefaultPSRepository
Write-Output "AzureRM $((Get-InstalledModule -Name AzureRM)[0].Version) installed..."

Update-AzureRM -Repository $DefaultPSRepository
Update-AzureRM -Repository $DefaultPSRepository
} finally {
# Clean up
Set-PSRepository -Name $DefaultPSRepository -InstallationPolicy $_InstallationPolicy
}
}
elseif ($Uninstall.IsPresent)
{
Expand Down
40 changes: 19 additions & 21 deletions tools/AzureRM/AzureRM.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$AzureMajorVersion = "0";
$AzureMajorVersion = "0"

$AzureRMModules = @(
"AzureRM.ApiManagement",
Expand Down Expand Up @@ -42,20 +42,21 @@ function Install-ModuleWithVersionCheck([string]$Name,[string]$MajorVersion,[str
{
$_MinVer = "$MajorVersion.0.0.0"
$_MaxVer = "$MajorVersion.9999.9999.9999"
$script:InstallCounter ++
try {
$_ExistingModule = Get-Module -ListAvailable -Name $Name
$_ModuleAction = "installed"
if ($_ExistingModule -ne $null)
{
Update-Module -Name $Name -MaximumVersion $_MaxVer -ErrorAction Stop
Install-Module -Name $Name -Repository $Repository -Scope $Scope -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -Force -ErrorAction Stop
$_ModuleAction = "updated"
}
else
{
Install-Module -Name $Name -Repository $Repository -Scope $Scope -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -ErrorAction Stop
}
$v = (Get-InstalledModule -Name $Name -ErrorAction Ignore)[0].Version.ToString()
Write-Output "$Name $v $_ModuleAction..."
Write-Output "$Name $v $_ModuleAction [$script:InstallCounter/$($AzureRMModules.Count + 1)]..."
} catch {
Write-Warning "Skipping $Name package..."
Write-Warning $_
Expand Down Expand Up @@ -96,29 +97,22 @@ function Update-AzureRM

Write-Output "Installing AzureRM modules."

$_InstallationPolicy = (Get-PSRepository -Name PSGallery).InstallationPolicy
$_InstallationPolicy = (Get-PSRepository -Name $Repository).InstallationPolicy
$script:InstallCounter = 0

try
{
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Set-PSRepository -Name $Repository -InstallationPolicy Trusted

Install-ModuleWithVersionCheck "AzureRM.Profile" $MajorVersion $Repository $Scope

# Stop and remove any previous jobs
$AzureRMModules | ForEach {Get-Job -Name "*$_"} | Stop-Job | Remove-Job

# Start new job
$result = $AzureRMModules | ForEach {
Start-Job -Name $_ -ScriptBlock {
Install-ModuleWithVersionCheck $args[0] $args[1] $args[2] $args[3]
} -ArgumentList $_, $MajorVersion, $Repository, $Scope }

# Get results from the jobs
$AzureRMModules | ForEach {Get-Job -Name $_ | Wait-Job | Receive-Job }
$AzureRMModules | ForEach {
Install-ModuleWithVersionCheck $_ $MajorVersion $Repository $Scope
}
} finally {
# Clean up
Set-PSRepository -Name PSGallery -InstallationPolicy $_InstallationPolicy
$AzureRMModules | ForEach {Get-Job -Name $_ | Remove-Job}
Set-PSRepository -Name $Repository -InstallationPolicy $_InstallationPolicy
}
}

Expand Down Expand Up @@ -167,11 +161,15 @@ function Uninstall-ModuleWithVersionCheck([string]$Name,[string]$MajorVersion)
$_MatchedModule = Get-InstalledModule -Name $Name -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -ErrorAction Ignore | where {$_.Name -eq $Name}
if ($_MatchedModule -ne $null) {
try {
Remove-Module -Name $_MatchedModule.Name -Force -ErrorAction Ignore
Uninstall-Module -Name $_MatchedModule.Name -RequiredVersion $_MatchedModule.Version -Confirm:$false -ErrorAction Stop
if ((Get-Module -Name $_MatchedModule.Name | where {$_.Version -eq $_MatchedModule.Version}) -eq $null)
Remove-Module -Name $Name -Force -ErrorAction Ignore
Uninstall-Module -Name $Name -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -Confirm:$false -ErrorAction Stop
if ((Get-Module -Name $Name -ListAvailable) -eq $null)
{
Write-Output "$Name uninstalled..."
}
else
{
Write-Output "$Name version $($_MatchedModule.Version) uninstalled..."
Write-Output "$Name partially uninstalled..."
}
} catch {
Write-Warning "Skipping $Name package..."
Expand Down