Skip to content

Instantly share code, notes, and snippets.

@BlueDoge
Last active July 12, 2022 22:13
Show Gist options
  • Save BlueDoge/ea1768dd2806f3170dea110ce9caf13b to your computer and use it in GitHub Desktop.
Save BlueDoge/ea1768dd2806f3170dea110ce9caf13b to your computer and use it in GitHub Desktop.
Super simple AWS Updater, for specific modules, in Powershell
#Created by Elizabeth Clements in 2022
#License MIT
#Change this to the packages you want installed...
[String[]]$ModulesToInstall = `
"EC2", "S3" `
, "ElasticLoadBalancingV2", "SecretsManager" `
, "Route53", "CloudWatch", "CloudWatchLogs", "RDS" `
, "CloudFormation", "SSOAdmin", "IdentityStore" `
, "ECR", "AutoScaling", "KeyManagementService" `
, "Elasticsearch", "ECS", "SimpleNotificationService" `
, "Lambda", "SQS", "DynamoDBv2", "CognitoIdentityProvider" `
, "CognitoIdentity", "CloudFront", "DirectoryService" `
, "SSO", "EventBridge", "SSOOIDC", "APIGatewayV2" `
, "CertificateManager", "Athena", "AccessAnalyzer" `
, "ElasticBeanstalk", "ElastiCache", "EKS", "EBS" `
, "CostExplorer", "AWSHealth", "CloudTrail", "Kafka" `
, "ElasticFileSystem", "Pricing", "MQ", "Glacier" `
, "ConfigService", "AWSSupport", "RedShift" `
, "Route53Domains", "IoT", "FMS", "IoTEvents" `
, "Route53Resolver", "Budgets", "Snowball" `
, "CloudSearch", "AuditManager"
########################
## Actual code below:
########################
$DumpModulesToString = $(
$Output = ""
for ($Iter = 0; $Iter -lt $ModulesToInstall.Count; $Iter++)
{
$Output += $ModulesToInstall[$Iter]
if($Iter -ne ($ModulesToInstall.Count - 1))
{
$Output += ", "
}
}
$Output #Return it
)
$NeedsAWSInstaller = 0 #Gets flipped to 1 if the system needs the Installer package
try {
$TheVoid = Get-InstalledModule -Name AWS.Tools.Installer | Select-Object Name
}
catch {
Write-Error "Failed to find AWS.Tools.Installer!"
$NeedsAWSInstaller = 1
}
finally {
$TheVoid = ""
}
if($NeedsAWSInstaller -eq 1) {
try {
Write-Host "Attempting to install AWS.Tools.Installer ..."
Start-Process powershell -Verb RunAs -ArgumentList '-Command','& {Install-Module -Name AWS.Tools.Installer -SkipPublisherCheck -AcceptLicense}'
}
catch {
Write-Error "Failed to install the AWS Installer ..."
Exit 1 #Fail, pass the first error
}
}
try {
$Header = "Please Wait...";
$InfoForUser = "Attempting to install/update (" + $DumpModulesToString + ") modules ..."
Write-Host $InfoForUser
$HeaderAndInfo = "Write-Host '"+$Header+"'; Write-Host '"+$InfoForUser+"';"
[String[]]$TempCommandArray = "-Command", '"& {' + $HeaderAndInfo + ' Install-AWSToolsModule -Name ' + $DumpModulesToString + ' -CleanUp -Scope AllUsers}"'
Start-Process powershell -Verb RunAs -ArgumentList $TempCommandArray
}
catch {
Write-Error "Failed to run the AWS Installer/Updater ..."
Exit 2 #Fail, pass the second error
}
MIT License
Copyright (c) 2022 Elizabeth Clements
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment