Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Blog: Creates a launchd job that updates the AWS PowerShell .NET Core module on a daily basis.
<#
.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