Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 28c0c5c

Browse files
author
Robin Stolpe
committed
update
1 parent a64784b commit 28c0c5c

4 files changed

Lines changed: 48 additions & 202 deletions

File tree

.src/MaintainModule.psd1.source

Lines changed: 0 additions & 154 deletions
This file was deleted.

.src/Public/Function/Uninstall-RSModule.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@
5555
Write-Verbose "Looking so the modules exists in the system..."
5656
foreach ($m in $OldModule) {
5757
if ($m -in $InstalledModules.name) {
58-
Write-Verbose "$($m) did exists in the system..."
58+
Write-Verbose "$m did exists in the system..."
5959
[void]($Module.Add($m))
6060
}
6161
else {
62-
Write-Warning "$($m) did not exists in the system, skipping this module..."
62+
Write-Warning "$m did not exists in the system, skipping this module..."
6363
}
6464
}
6565
}
6666

6767
foreach ($m in $Module) {
68-
Write-Verbose "Collecting all installed version of the module $($m)"
68+
Write-Verbose "Collecting all installed version of the module $m"
6969
$GetAllInstalledVersions = Get-InstalledModule -Name $m -AllVersions | Sort-Object { $_.Version -as [version] } -Descending | Select-Object -ExpandProperty Version
7070

7171
# If the module has more then one version loop trough the versions and only keep the most current one
@@ -74,20 +74,20 @@
7474
[version]$MostRecentVersion = $GetAllInstalledVersions[0]
7575
Foreach ($Version in $GetAllInstalledVersions | Where-Object { [version]$_ -lt [version]$MostRecentVersion }) {
7676
try {
77-
Write-Output "Uninstalling previous version $($Version) of module $($m)..."
77+
Write-Output "Uninstalling previous version $Version of module $m..."
7878
Uninstall-Module -Name $m -RequiredVersion $Version -Force -ErrorAction SilentlyContinue
79-
Write-Output "Version $($Version) of $($m) are now uninstalled!"
79+
Write-Output "Version $Version of $m are now uninstalled!"
8080
}
8181
catch {
8282
Write-Error "$($PSItem.Exception)"
8383
continue
8484
}
8585
}
8686
# bygga in en check så att den verkligen kan verifiera detta
87-
Write-Output "All older versions of $($m) are now uninstalled, the only installed version of $($m) is $($MostRecentVersion)"
87+
Write-Output "All older versions of $m are now uninstalled, the only installed version of $m is $MostRecentVersion"
8888
}
8989
else {
90-
Write-Verbose "$($m) don't have any older versions installed then $($GetAllInstalledVersions), no need to uninstall anything."
90+
Write-Verbose "$m don't have any older versions installed then $GetAllInstalledVersions, no need to uninstall anything."
9191
}
9292
}
9393
Write-Output "`n=== \\\ Script Finished! /// ===`n"

.src/Public/Function/Update-RSModule.ps1

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
[void]($Module.Add($m))
9898
}
9999
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..."
101101
}
102102
}
103103
}
@@ -126,25 +126,25 @@
126126

127127
# Start looping trough every module that are stored in the string Module
128128
foreach ($m in $Module) {
129-
Write-Verbose "Checks if $($m) are installed"
129+
Write-Verbose "Checks if $m are installed"
130130
if ($m -in $InstalledModules.Name) {
131131

132132
# 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..."
134134
$GetAllInstalledVersions = Get-InstalledModule -Name $m -AllVersions | Sort-Object { $_.Version -as [version] } -Descending | Select-Object Version
135135
[version]$LatestInstalledVersion = $($GetAllInstalledVersions | Select-Object Version -First 1).version
136136

137137
# 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..."
139139
[version]$CollectLatestVersion = $(Find-Module -Name $m -AllVersions | Sort-Object { $_.Version -as [version] } -Descending | Select-Object Version -First 1).version
140140

141141
# Looking if the version of the module are the latest version, it it's not the latest it will install the latest version.
142142
if ($LatestInstalledVersion -lt $CollectLatestVersion) {
143143
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"
148148
}
149149
catch {
150150
Write-Error "$($PSItem.Exception)"
@@ -155,29 +155,29 @@
155155
# If switch -UninstallOldVersion has been used then the old versions will be uninstalled from the module
156156
if ($UninstallOldVersion -eq $true) {
157157
if ($GetAllInstalledVersions.Count -gt 1) {
158-
Write-Output "Uninstalling old versions $($LatestInstalledVersion) of $($m)..."
158+
Write-Output "Uninstalling old versions $LatestInstalledVersion of $m..."
159159
Uninstall-RSModule -Module $m
160160
}
161161
}
162162
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!"
164164
}
165165
}
166166
else {
167167
# If the switch InstallMissing are set to true the modules will get installed if they are missing
168168
if ($InstallMissing -eq $true) {
169169
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!"
173173
}
174174
catch {
175175
Write-Error "$($PSItem.Exception)"
176176
continue
177177
}
178178
}
179179
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!"
181181
}
182182
}
183183
}
@@ -191,13 +191,13 @@
191191
Write-Verbose "Starting to import the modules..."
192192
foreach ($m in $Module) {
193193
if ($m -in $ImportedModules.Name) {
194-
Write-Verbose "$($m) are already imported!"
194+
Write-Verbose "$m are already imported!"
195195
}
196196
else {
197197
try {
198-
Write-Output "Importing $($m)..."
198+
Write-Output "Importing $m..."
199199
Import-Module -Name $m -Force
200-
Write-Output "$($m) has been imported!"
200+
Write-Output "$m has been imported!"
201201
}
202202
catch {
203203
Write-Error "$($PSItem.Exception)"

0 commit comments

Comments
 (0)