-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheck-ModuleUpdate.ps1
62 lines (54 loc) · 1.84 KB
/
Check-ModuleUpdate.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
[cmdletbinding()]
[outputtype("moduleInfo")]
Param(
[Parameter(Position = 0, HelpMessage = "Enter a module name or names. Wildcards are allowed.")]
[ValidateNotNullorEmpty()]
[string[]]$Name = "*"
)
Write-Verbose "Getting installed modules"
Try {
$modules = Get-Module -Name $name -ListAvailable -ErrorAction Stop
}
Catch {
Throw $_
}
if ($modules) {
Write-Verbose "Found $($modules.count) matching modules"
#group to identify modules with multiple versions installed
Write-Verbose "Grouping modules"
$g = $modules | Group-Object name -NoElement | Where-Object count -GT 1
Write-Verbose "Filter to modules from the PSGallery"
$gallery = $modules.where( { $_.repositorysourcelocation })
Write-Verbose "Comparing to online versions"
foreach ($module in $gallery) {
#find the current version in the gallery
Try {
Write-Verbose "Looking online for $($module.name)"
$online = Find-Module -Name $module.name -Repository PSGallery -ErrorAction Stop
#compare versions
if (($online.version -as [version]) -gt ($module.version -as [version])) {
$UpdateAvailable = $True
}
else {
$UpdateAvailable = $False
}
#write a custom object to the pipeline
[pscustomobject]@{
PSTypeName = "moduleInfo"
Name = $module.name
MultipleVersions = ($g.name -contains $module.name)
InstalledVersion = $module.version
OnlineVersion = $online.version
Update = $UpdateAvailable
Path = $module.modulebase
}
}
Catch {
Write-Warning "Module $($module.name) was not found in the PSGallery"
}
} #foreach
}
else {
Write-Warning "No matching modules found."
}
Write-Verbose "Check complete"