Skip to content

Instantly share code, notes, and snippets.

@pcgeek86
Created December 21, 2017 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcgeek86/7691df04a19c6e0f81cf33fe70cad019 to your computer and use it in GitHub Desktop.
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.
<#
.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