-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPSModule-AutoUpdate.ps1
More file actions
47 lines (40 loc) · 1.44 KB
/
PSModule-AutoUpdate.ps1
File metadata and controls
47 lines (40 loc) · 1.44 KB
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
<#
.SYNOPSIS
Update all local PowerShell Modules if newer version available.
.PARAMETER install
Typing "PSModule-AutoUpdate.ps1 -install" will create a local machine Task Scheduler job under credentials of the current user. Job runs first of each month to download latest PS module with "Update-Module -Force" command.
.NOTES
File Name: PSModule-AutoUpdate.ps1
Author : Jeff Jones - @spjeff
Version : 1.0.0
Modified : 2019-09-22
.LINK
https://github.com/spjeff/spadmin
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $False, Position = 1, ValueFromPipeline = $false, HelpMessage = 'Use -install -i parameter to add script to Windows Task Scheduler on local machine')]
[Alias("i")]
[switch]$install
)
# Installer
if ($install) {
schtasks /s $_ /create /tn "PSModule-AutoUpdate" /ru $user /rp $pass /sc monthly /mo 1
}
# Available Modules
$modules = Get-Module -ListAvailable
foreach ($mod in $modules) {
$module = $mod.Name
$available = Find-Module $module
if ($available) {
# Current Module
$current = (Get-Module -ListAvailable | ? { $_.Name -eq $module })
# Compare Module Version
if ($available.Version -gt $current.Version) {
# Execute Module Update
Write-Host " - UPDATE AVAILABLE" -ForegroundColor Yellow
Remove-Item (Split-Path $current.Path) -Confirm:$false -Force
Install-Module $module -AllowClobber -Force
}
}
}