Created
December 21, 2017 22:49
-
-
Save pcgeek86/7691df04a19c6e0f81cf33fe70cad019 to your computer and use it in GitHub Desktop.
Blog: Creates a launchd job that updates the AWS PowerShell .NET Core module on a daily basis.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Description | |
This PowerShell script will create and register a new launchd job that keeps the AWSPowerShell.NetCore module | |
up-to-date on your MacOS system. | |
If you receive an error upon registration, it's probably just because the service doesn't already exist. | |
This script tries to unload and reload the service, whether or not it exists, hence the error on initial run. | |
#> | |
$PListFile = @' | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>UpdateAWSPowerShell</key> | |
<true/> | |
<key>Label</key> | |
<string>PowerShell.UpdateAWSPowerShell</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/local/bin/pwsh</string> | |
<string>-Command</string> | |
<string>Install-Module -Name AWSPowerShell.NetCore -Scope CurrentUser -Force</string> | |
</array> | |
<key>StartInterval</key> | |
<integer>86400</integer> | |
</dict> | |
</plist> | |
'@ | |
$Params = @{ | |
Path = '~/Library/LaunchAgents/update.awspowershell.plist' | |
Value = $PListFile | |
} | |
Set-Content @Params | |
launchctl unload $Params.Path | |
Write-Host -Object 'Deregistering service' | |
launchctl load $Params.Path | |
Write-Host -Object 'Registering service' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment