2023年9月24日
環境
Windows Server2019(AWS EC2)
AWS Tools for Windows PowerShell
概要
AWS Tools for Windows PowerShellは、WindowsコマンドラインからAWSを実行できる
PowerShellギャラリーからのインストールはPowerShell5. 0 以降のためAWS公式サイトに
AWS Tools for Windows PowerShellは、WindowsコマンドラインからAWSを実行できる
ようにするAWS公式モジュールです。
PowerShellギャラリーからのインストールはPowerShell5.0 以降のためAWS公式サイトに
あるzipファイルからインストールします。
AWS Tools for Windows PowerShellは、WindowsコマンドラインからAWSを実行できる
ようにするAWS公式モジュールです。
PowerShellギャラリーからのインストールはPowerShell5.0 以降のためAWS公式サイトに
あるzipファイルからインストールします。
操作方法
1.AWS Tools for Windows PowerShellをアンインストールする
1 ) .コントロールパネル>プログラム>Programs and Featuresをクリックします。
2 ) 「AWS Tools for Windows」を右クリックからアンインストールをクリックします。
1).コントロールパネル>プログラム>Programs and Featuresをクリックします。
2)「AWS Tools for Windows」を右クリックからアンインストールをクリックします。
1).コントロールパネル>プログラム>Programs and Featuresをクリックします。
2)「AWS Tools for Windows」を右クリックからアンインストールをクリックします。
3).アンインストール後は、Get-AWSPowerShellVersionで確認します
> Get-AWSPowerShellVersion
> Get-AWSPowerShellVersion
> Get-AWSPowerShellVersion
2.AWS Tools for Windows PowerShellをアップデートする
1).以下のAWSPowerShellをインストールのページを開き、AWSPowerShell.zipをダウンロードします。
https://docs.aws.amazon.com/ja_jp/powershell/latest/userguide/pstools-getting-set-up-windows.html#ps-installing-awswindowspowershell
2).$Env:PSModulePath コマンドを実行し、表示されたモジュールディレクトリに上記zipファイルを展開して解凍します。
C:\Program Files\WindowsPowerShell\Modulesに配置します。
3).PowerShellでSet-ExecutionPolicy RemoteSignedを実行します。
> Set-ExecutionPolicy RemoteSigned
> Set-ExecutionPolicy RemoteSigned
> Set-ExecutionPolicy RemoteSigned
4).PowerShell プロファイル(テキスト)を修正します。ファイルが存在しない場合は作成します。
全ユーザーのPowerShellのプロファイル
C:\Windows\System32\WindowsPowerShell\v1. 0 \Microsoft. PowerShell_profile . ps1
C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
指定したユーザーのPowerShellのプロファイル
C:\Users\ ( ユーザ名 ) \Documents\WindowsPowerShell\Microsoft. PowerShell_profile . ps1
C:\Users\(ユーザ名)\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
C:\Users\(ユーザ名)\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Import Moduleを実行します。
> Import-Module "C:\Program Files\WindowsPowerShell\Modules\AWSPowerShell.4.1.312\AWSPowerShell\4.1.312\AWSPowerShell.psd1"
> Import-Module "C:\Program Files\WindowsPowerShell\Modules\AWSPowerShell.4.1.312\AWSPowerShell\4.1.312\AWSPowerShell.psd1"
> Import-Module "C:\Program Files\WindowsPowerShell\Modules\AWSPowerShell.4.1.312\AWSPowerShell\4.1.312\AWSPowerShell.psd1"
5).PowerShellを再起動します。
3.PowerShellのバージョンを確認する
バージョンを確認する ( Get-AWSPowerShellVersion )
> Get-AWSPowerShellVersion
> $PSVersionTable
バージョンを確認する(Get-AWSPowerShellVersion)
> Get-AWSPowerShellVersion
> $PSVersionTable
バージョンを確認する(Get-AWSPowerShellVersion)
> Get-AWSPowerShellVersion
4.AWS Tools for Windows PowerShellからS3へのコマンド
1).S3へファイルを送信する
形式
Write-S3Object -BucketName バケット名 -key awsのパスとファイル名 -File ローカルのパスとファイル名
Write-S3Object -BucketName バケット名 -key awsのパスとファイル名 -File ローカルのパスとファイル名
Write-S3Object -BucketName バケット名 -key awsのパスとファイル名 -File ローカルのパスとファイル名
操作例
Write-S3Object -BucketName test-s3-data- 2023 -File result. txt
Write-S3Object -BucketName test-s3-data- 2023 -Key "testfolder/cft.txt" -File cft. txt
Write-S3Object -BucketName test-s3-data-2023 -File result.txt
Write-S3Object -BucketName test-s3-data-2023 -Key "testfolder/cft.txt" -File cft.txt
Write-S3Object -BucketName test-s3-data-2023 -File result.txt
Write-S3Object -BucketName test-s3-data-2023 -Key "testfolder/cft.txt" -File cft.txt
2).S3からファイルを取得する
形式
Copy-S3Object -BucketName バケット名 -Key awsのパスとファイル名 -LocalFile ローカルのパスとファイル名
Copy-S3Object -BucketName バケット名 -Key awsのパスとファイル名 -LocalFile ローカルのパスとファイル名
Copy-S3Object -BucketName バケット名 -Key awsのパスとファイル名 -LocalFile ローカルのパスとファイル名
操作例
Copy-S3Object -BucketName test-s3-data- 2023 -Key cft. txt -LocalFile .\test\cft. txt
Copy-S3Object -BucketName test-s3-data- 2023 -Key "testfolder/yangzh.txt" -LocalFile .\test2\yangzh. txt
Copy-S3Object -BucketName test-s3-data-2023 -Key cft.txt -LocalFile .\test\cft.txt
Copy-S3Object -BucketName test-s3-data-2023 -Key "testfolder/yangzh.txt" -LocalFile .\test2\yangzh.txt
Copy-S3Object -BucketName test-s3-data-2023 -Key cft.txt -LocalFile .\test\cft.txt
Copy-S3Object -BucketName test-s3-data-2023 -Key "testfolder/yangzh.txt" -LocalFile .\test2\yangzh.txt
3).S3のファイルの一覧を表示する
形式
Get-S3Object -BucketName バケット名
Get-S3Object -BucketName バケット名
Get-S3Object -BucketName バケット名
操作例
Get-S3Object -BucketName test-s3-data- 2023
Get-S3Object -BucketName test-s3-data-2023
Get-S3Object -BucketName test-s3-data-2023