Introduction
From the AWS documentation:
The AWS Tools for PowerShell are a set of PowerShell cmdlets that are built on top of the functionality exposed by the AWS SDK for .NET. The AWS Tools for PowerShell enable you to script operations on your AWS resources from the PowerShell command line.
Just like the AWS CLI, the AWS Tools for PowerShell let developers and administrators manage their AWS services and resources in the PowerShell scripting environment.
Installation and Configuration (on Windows)
These tools are only available from version on computers that are running Windows with Windows PowerShell 5.1, or PowerShell Core 6.0 or later.
Run the Windows PowerShell as Administrator.
Run the following command to install AWS Tools for PowerShell:
Install-Module -Name AWSPowerShell
Answer "Y" to the interactive prompts.
Next, try to see if the application has installed correctly:
Get-AWSPowerShellVersion
Incase you encounter errors stating that "... the module could not be loaded ..." or that the module "... cannot be loaded because running scripts is disabled on this system ...", you may need to change the Execution Policy.
Run the following command to change the Execution Policy:
Set-ExecutionPolicy RemoteSigned
Answer "Y" to the interactive prompts.
Next, set the proper AWS Credentials. If you don't have an administrator set up for your AWS account, follow the instructions here.
Once the administartor user has been set up, generate access keys for that user and securely store that information.
To add a new profile to the AWS SDK store, run the command (replace the AccessKey
and SecretKey
codes with the administrator access keys):
Set-AWSCredential `
-AccessKey AKIA0123456787EXAMPLE `
-SecretKey wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY `
-StoreAs Administrator
Next, save the configuration as the default profile and region for every PowerShell session:
Initialize-AWSDefaultConfiguration -ProfileName Administrator -Region us-west-2
AWS Tools for PowerShell Example Cmdlets
Here are some example cmdlets:
Create Key-Pair
$myPSKeyPair = New-EC2KeyPair -KeyName myPSKeyPair
View Key-Pair Details
$myPSKeyPair | Get-Member
Save Key-Pair
$myPSKeyPair.KeyMaterial | Out-File -Encoding ascii myPSKeyPair.pem
Remove Key Pair from AWS
Remove-EC2KeyPair -KeyName myPSKeyPair
Create Security Group
New-EC2SecurityGroup -GroupName myPSSecurityGroup -GroupDescription "EC2-Classic from PowerShell"
View Security Groups
Get-EC2SecurityGroup -GroupNames myPSSecurityGroup
Remove Security Group
Remove-EC2SecurityGroup -GroupId sg-0113e926ee099393f
Launch an instance
New-EC2Instance -ImageId ami-0ca285d4c2cda3300 `
-MinCount 1 `
-MaxCount 1 `
-KeyName myPSKeyPair `
-SecurityGroups myPSSecurityGroup `
-InstanceType t2.micro
View Instance
$reservation = New-Object 'collections.generic.list[string]'
$reservation.add("r-b70a0ef1")
$filter_reservation = New-Object Amazon.EC2.Model.Filter -Property @{Name = "reservation-id"; Values = $reservation}
(Get-EC2Instance -Filter $filter_reservation).Instances
Terminate Instance
Remove-EC2Instance -InstanceId i-0453116cdface121d
List Buckets
Get-S3Bucket
Create a bucket
New-S3Bucket -BucketName uniquebucketname2258 -Region us-west-2
Upload an object to the bucket
Write-S3Object -BucketName uniquebucketname2258 -File .\sample.txt
List Bucket Contents
Get-S3Object -BucketName uniquebucketname2258
Delete Bucket and its objects
Remove-S3Bucket -BucketName uniquebucketname2258 -DeleteBucketContent
List Users
Get-IAMUserList
Create a user
New-IAMUser -UserName Bob
Create a new group
New-IAMGroup -GroupName DummyGroup
Add users to group
Add-IAMUserToGroup -UserName "Bob" -GroupName "DummyGroup"
List the group, group details and its users
$results = Get-IAMGroup -GroupName "DummyGroup"
$results
$results.Group
$results.Users
Removes all users from a group and then deletes the group
(Get-IAMGroup -GroupName DummyGroup).Users | Remove-IAMUserFromGroup -GroupName DummyGroup -Force
Remove-IAMGroup -GroupName DummyGroup -Force
Deletes a user
Remove-IAMUser -UserName Bob
For more information on AWS Tools for PowerShell visit AWS Tools for PowerShell Cmdlet Reference page
Top comments (0)