Skip to content

Latest commit

 

History

History
170 lines (116 loc) · 2.72 KB

File metadata and controls

170 lines (116 loc) · 2.72 KB

PowerShell on AWS CloudShell Demos

List available tools

ls -la /usr/local/bin

Show assumed role

aws sts get-caller-identity

List EC2 instances

aws ec2 describe-instances

Pretty print EC2 instances

aws ec2 describe-instances | jq .

Install AWS CDK

npm install aws-cdk

Print the AWS CDK version

cdk --version

List binaries

ls /usr/bin

Start PowerShell

pwsh

Show assumed role

Get-STSCallerIdentity

List modules

Get-Module -ListAvailable

List commands

Get-Command

List variables

Get-Variable
Get-ChildItem env:

Show profile location

$PROFILE

Show profile content

Get-Content $PROFILE

Add to the profile

Add-Content -Path $PROFILE -Value "Write-Output 'Hello Summit!'"

Reload the profile

. $PROFILE

Trust the PowerShell Gallery

Set-PSRepository -Name 'PSGallery' -InstallationPolicy 'Trusted'

Install Pester

Install-Module -Name 'Pester'

Run Pester

Get-Content ./pesterDemo.ps1
Invoke-Pester ./pesterDemo.ps1 -Output 'Detailed'

Automatically install Pester using the profile

Add-Content -Path $PROFILE -Value 'if($null -eq (Get-Module -ListAvailable Pester)) { Install-Module -Name Pester -Force }'

Reload the profile

Uninstall-Module Pester
. $PROFILE

Create an S3 bucket

New-S3Bucket -BucketName 'powershell2023summit'

Upload the file

Write-S3Object -BucketName 'powershell2023summit' -Key 'profile.ps1' -File $PROFILE

Download the file then reload the profile

Read-S3Object -BucketName 'powershell2023summit' -Key 'profile.ps1' -File $PROFILE && . $PROFILE

Create lots of S3 buckets

1..300 | ForEach-Object { New-S3Bucket -BucketName "powershell2023summit$_" -WhatIf }

Update all gp2 EBS volumes to gp3

Get-EC2Volume | Where-Object { $_.VolumeType -eq 'gp2' } | Edit-EC2Volume -VolumeType 'gp3' | Format-Table -AutoSize

Sync command history

$cloudHistory = Read-S3Object -BucketName 'powershell2023summit' -Key 'ConsoleHost_history.txt' -File (New-TemporaryFile)
$localHistory = (Get-PSReadLineOption).HistorySavePath
Add-Content -Path $localHistory -Value (Get-Content $cloudHistory)
Write-S3Object -BucketName 'powershell2023summit' -Key 'ConsoleHost_history.txt' -File $localHistory