|
97 | 97 | [void]($Module.Add($m)) |
98 | 98 | } |
99 | 99 | else { |
100 | | - Write-Warning "$($m) did not exists in the system, skipping this module..." |
| 100 | + Write-Warning "$m did not exists in the system, skipping this module..." |
101 | 101 | } |
102 | 102 | } |
103 | 103 | } |
|
126 | 126 |
|
127 | 127 | # Start looping trough every module that are stored in the string Module |
128 | 128 | foreach ($m in $Module) { |
129 | | - Write-Verbose "Checks if $($m) are installed" |
| 129 | + Write-Verbose "Checks if $m are installed" |
130 | 130 | if ($m -in $InstalledModules.Name) { |
131 | 131 |
|
132 | 132 | # Getting the latest installed version of the module |
133 | | - Write-Verbose "Collecting all installed version of $($m)..." |
| 133 | + Write-Verbose "Collecting all installed version of $m..." |
134 | 134 | $GetAllInstalledVersions = Get-InstalledModule -Name $m -AllVersions | Sort-Object { $_.Version -as [version] } -Descending | Select-Object Version |
135 | 135 | [version]$LatestInstalledVersion = $($GetAllInstalledVersions | Select-Object Version -First 1).version |
136 | 136 |
|
137 | 137 | # Collects the latest version of module from the source where the module was installed from |
138 | | - Write-Verbose "Looking up the latest version of $($m)..." |
| 138 | + Write-Verbose "Looking up the latest version of $m..." |
139 | 139 | [version]$CollectLatestVersion = $(Find-Module -Name $m -AllVersions | Sort-Object { $_.Version -as [version] } -Descending | Select-Object Version -First 1).version |
140 | 140 |
|
141 | 141 | # Looking if the version of the module are the latest version, it it's not the latest it will install the latest version. |
142 | 142 | if ($LatestInstalledVersion -lt $CollectLatestVersion) { |
143 | 143 | try { |
144 | | - Write-Output "Found a newer version of $($m), version $($CollectLatestVersion)" |
145 | | - Write-Output "Updating $($m) from $($LatestInstalledVersion) to version $($CollectLatestVersion)..." |
146 | | - Update-Module -Name $($m) -Scope $Scope -Force |
147 | | - Write-Output "$($m) has now been updated to version $($CollectLatestVersion)!`n" |
| 144 | + Write-Output "Found a newer version of $m, version $CollectLatestVersion" |
| 145 | + Write-Output "Updating $m from $($LatestInstalledVersion) to version $CollectLatestVersion..." |
| 146 | + Update-Module -Name $m -Scope $Scope -Force |
| 147 | + Write-Output "$m has now been updated to version $CollectLatestVersion!`n" |
148 | 148 | } |
149 | 149 | catch { |
150 | 150 | Write-Error "$($PSItem.Exception)" |
|
155 | 155 | # If switch -UninstallOldVersion has been used then the old versions will be uninstalled from the module |
156 | 156 | if ($UninstallOldVersion -eq $true) { |
157 | 157 | if ($GetAllInstalledVersions.Count -gt 1) { |
158 | | - Write-Output "Uninstalling old versions $($LatestInstalledVersion) of $($m)..." |
| 158 | + Write-Output "Uninstalling old versions $LatestInstalledVersion of $m..." |
159 | 159 | Uninstall-RSModule -Module $m |
160 | 160 | } |
161 | 161 | } |
162 | 162 | else { |
163 | | - Write-Verbose "$($m) already has the newest version installed, no need to install anything!" |
| 163 | + Write-Verbose "$m already has the newest version installed, no need to install anything!" |
164 | 164 | } |
165 | 165 | } |
166 | 166 | else { |
167 | 167 | # If the switch InstallMissing are set to true the modules will get installed if they are missing |
168 | 168 | if ($InstallMissing -eq $true) { |
169 | 169 | try { |
170 | | - Write-Output "$($m) are not installed, installing $($m)..." |
171 | | - Install-Module -Name $($m) -Scope $Scope -Force |
172 | | - Write-Output "$($m) has now been installed!" |
| 170 | + Write-Output "$m are not installed, installing $m..." |
| 171 | + Install-Module -Name $m -Scope $Scope -Force |
| 172 | + Write-Output "$m has now been installed!" |
173 | 173 | } |
174 | 174 | catch { |
175 | 175 | Write-Error "$($PSItem.Exception)" |
176 | 176 | continue |
177 | 177 | } |
178 | 178 | } |
179 | 179 | else { |
180 | | - Write-Warning "$($m) module are not installed, and you have not chosen to install missing modules. Continuing without any actions!" |
| 180 | + Write-Warning "$m module are not installed, and you have not chosen to install missing modules. Continuing without any actions!" |
181 | 181 | } |
182 | 182 | } |
183 | 183 | } |
|
191 | 191 | Write-Verbose "Starting to import the modules..." |
192 | 192 | foreach ($m in $Module) { |
193 | 193 | if ($m -in $ImportedModules.Name) { |
194 | | - Write-Verbose "$($m) are already imported!" |
| 194 | + Write-Verbose "$m are already imported!" |
195 | 195 | } |
196 | 196 | else { |
197 | 197 | try { |
198 | | - Write-Output "Importing $($m)..." |
| 198 | + Write-Output "Importing $m..." |
199 | 199 | Import-Module -Name $m -Force |
200 | | - Write-Output "$($m) has been imported!" |
| 200 | + Write-Output "$m has been imported!" |
201 | 201 | } |
202 | 202 | catch { |
203 | 203 | Write-Error "$($PSItem.Exception)" |
|
0 commit comments