Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
trentbl authored May 4, 2023
1 parent 2a4104e commit 7610af4
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 0 deletions.
170 changes: 170 additions & 0 deletions PowerShell on AWS CloudShell by Trent Blackburn/demos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# PowerShell on AWS CloudShell Demos
<!-- spell-checker:words pwsh -->

List available tools

```shell
ls -la /usr/local/bin
```

Show assumed role

```shell
aws sts get-caller-identity
```

List EC2 instances

```shell
aws ec2 describe-instances
```

Pretty print EC2 instances

```shell
aws ec2 describe-instances | jq .
```

Install AWS CDK

```shell
npm install aws-cdk
```

Print the AWS CDK version

```shell
cdk --version
```

List binaries

```shell
ls /usr/bin
```

Start PowerShell

```shell
pwsh
```

Show assumed role

```powershell
Get-STSCallerIdentity
```

List modules

```powershell
Get-Module -ListAvailable
```

List commands

```powershell
Get-Command
```

List variables

```powershell
Get-Variable
Get-ChildItem env:
```

Show profile location

```powershell
$PROFILE
```

Show profile content

```powershell
Get-Content $PROFILE
```

Add to the profile

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

Reload the profile

```powershell
. $PROFILE
```

Trust the PowerShell Gallery

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

Install Pester

```powershell
Install-Module -Name 'Pester'
```

Run Pester

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

Automatically install Pester using the profile

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

Reload the profile

```powershell
Uninstall-Module Pester
. $PROFILE
```

Create an S3 bucket

```powershell
New-S3Bucket -BucketName 'powershell2023summit'
```

Upload the file

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

Download the file then reload the profile

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

Create lots of S3 buckets

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

Update all gp2 EBS volumes to gp3

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

Sync command history

```powershell
$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
```
10 changes: 10 additions & 0 deletions PowerShell on AWS CloudShell by Trent Blackburn/pesterDemo.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Describe 'Bucket check' {
It 'powershell2023summit should exist' {
$bucket = Get-S3Bucket -BucketName 'powershell2023summit'
$bucket | Should -Not -BeNullOrEmpty
}
It 'doesnotexistpowershell2023summit should not exist' {
$bucket = Get-S3Bucket -BucketName 'doesnotexistpowershell2023summit'
$bucket | Should -BeNullOrEmpty
}
}
Binary file not shown.

0 comments on commit 7610af4

Please sign in to comment.