|
1 |
| -$AzureMajorVersion = "0"; |
| 1 | +$AzureMajorVersion = "0" |
2 | 2 |
|
3 | 3 | $AzureRMModules = @(
|
4 | 4 | "AzureRM.ApiManagement",
|
@@ -42,20 +42,21 @@ function Install-ModuleWithVersionCheck([string]$Name,[string]$MajorVersion,[str
|
42 | 42 | {
|
43 | 43 | $_MinVer = "$MajorVersion.0.0.0"
|
44 | 44 | $_MaxVer = "$MajorVersion.9999.9999.9999"
|
| 45 | + $script:InstallCounter ++ |
45 | 46 | try {
|
46 | 47 | $_ExistingModule = Get-Module -ListAvailable -Name $Name
|
47 | 48 | $_ModuleAction = "installed"
|
48 | 49 | if ($_ExistingModule -ne $null)
|
49 | 50 | {
|
50 |
| - Update-Module -Name $Name -MaximumVersion $_MaxVer -ErrorAction Stop |
| 51 | + Install-Module -Name $Name -Repository $Repository -Scope $Scope -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -Force -ErrorAction Stop |
51 | 52 | $_ModuleAction = "updated"
|
52 | 53 | }
|
53 | 54 | else
|
54 | 55 | {
|
55 | 56 | Install-Module -Name $Name -Repository $Repository -Scope $Scope -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -ErrorAction Stop
|
56 | 57 | }
|
57 | 58 | $v = (Get-InstalledModule -Name $Name -ErrorAction Ignore)[0].Version.ToString()
|
58 |
| - Write-Output "$Name $v $_ModuleAction..." |
| 59 | + Write-Output "$Name $v $_ModuleAction [$script:InstallCounter/$($AzureRMModules.Count + 1)]..." |
59 | 60 | } catch {
|
60 | 61 | Write-Warning "Skipping $Name package..."
|
61 | 62 | Write-Warning $_
|
@@ -96,29 +97,22 @@ function Update-AzureRM
|
96 | 97 |
|
97 | 98 | Write-Output "Installing AzureRM modules."
|
98 | 99 |
|
99 |
| - $_InstallationPolicy = (Get-PSRepository -Name PSGallery).InstallationPolicy |
| 100 | + $_InstallationPolicy = (Get-PSRepository -Name $Repository).InstallationPolicy |
| 101 | + $script:InstallCounter = 0 |
100 | 102 |
|
101 | 103 | try
|
102 | 104 | {
|
103 |
| - Set-PSRepository -Name PSGallery -InstallationPolicy Trusted |
| 105 | + Set-PSRepository -Name $Repository -InstallationPolicy Trusted |
104 | 106 |
|
105 | 107 | Install-ModuleWithVersionCheck "AzureRM.Profile" $MajorVersion $Repository $Scope
|
106 | 108 |
|
107 |
| - # Stop and remove any previous jobs |
108 |
| - $AzureRMModules | ForEach {Get-Job -Name "*$_"} | Stop-Job | Remove-Job |
109 |
| - |
110 | 109 | # Start new job
|
111 |
| - $result = $AzureRMModules | ForEach { |
112 |
| - Start-Job -Name $_ -ScriptBlock { |
113 |
| - Install-ModuleWithVersionCheck $args[0] $args[1] $args[2] $args[3] |
114 |
| - } -ArgumentList $_, $MajorVersion, $Repository, $Scope } |
115 |
| - |
116 |
| - # Get results from the jobs |
117 |
| - $AzureRMModules | ForEach {Get-Job -Name $_ | Wait-Job | Receive-Job } |
| 110 | + $AzureRMModules | ForEach { |
| 111 | + Install-ModuleWithVersionCheck $_ $MajorVersion $Repository $Scope |
| 112 | + } |
118 | 113 | } finally {
|
119 | 114 | # Clean up
|
120 |
| - Set-PSRepository -Name PSGallery -InstallationPolicy $_InstallationPolicy |
121 |
| - $AzureRMModules | ForEach {Get-Job -Name $_ | Remove-Job} |
| 115 | + Set-PSRepository -Name $Repository -InstallationPolicy $_InstallationPolicy |
122 | 116 | }
|
123 | 117 | }
|
124 | 118 |
|
@@ -167,11 +161,15 @@ function Uninstall-ModuleWithVersionCheck([string]$Name,[string]$MajorVersion)
|
167 | 161 | $_MatchedModule = Get-InstalledModule -Name $Name -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -ErrorAction Ignore | where {$_.Name -eq $Name}
|
168 | 162 | if ($_MatchedModule -ne $null) {
|
169 | 163 | try {
|
170 |
| - Remove-Module -Name $_MatchedModule.Name -Force -ErrorAction Ignore |
171 |
| - Uninstall-Module -Name $_MatchedModule.Name -RequiredVersion $_MatchedModule.Version -Confirm:$false -ErrorAction Stop |
172 |
| - if ((Get-Module -Name $_MatchedModule.Name | where {$_.Version -eq $_MatchedModule.Version}) -eq $null) |
| 164 | + Remove-Module -Name $Name -Force -ErrorAction Ignore |
| 165 | + Uninstall-Module -Name $Name -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -Confirm:$false -ErrorAction Stop |
| 166 | + if ((Get-Module -Name $Name -ListAvailable) -eq $null) |
| 167 | + { |
| 168 | + Write-Output "$Name uninstalled..." |
| 169 | + } |
| 170 | + else |
173 | 171 | {
|
174 |
| - Write-Output "$Name version $($_MatchedModule.Version) uninstalled..." |
| 172 | + Write-Output "$Name partially uninstalled..." |
175 | 173 | }
|
176 | 174 | } catch {
|
177 | 175 | Write-Warning "Skipping $Name package..."
|
|
0 commit comments