Using PowerShell for managing AWS resources: Difference between revisions

From PUBLIC-WIKI
Jump to navigation Jump to search
Eyales (talk | contribs)
No edit summary
Eyales (talk | contribs)
No edit summary
Line 46: Line 46:
: For more information about installation or upgrade of PowerShellGet, see:
: For more information about installation or upgrade of PowerShellGet, see:
: https://docs.microsoft.com/en-us/powershell/gallery/installing-psget
: https://docs.microsoft.com/en-us/powershell/gallery/installing-psget
* Run the command below to install AWS tools for PowerShell core:
: '''Install-Module -Name AWSPowerShell.NetCore -AllowClobber -Force'''
* Run the command below to update to the latest AWS PowerShell module:
: '''Update-Module -Name AWSPowerShell.NetCore -Force'''
* To view the installed versions of AWS PowerShell module, run the command below:
: '''Get-Module -Name AWSPowerShell.NetCore -List | select Name,Version'''
* To view the list of AWS services supported by the Tools for PowerShell, run the command below:
: '''Get-AWSPowerShellVersion -ListServiceVersionInfo'''
== How to configure AWS Account and Access Keys ==
* Login to the IAM Console:
: https://console.aws.amazon.com/iam/
* From the left pane, click on Users -> click on “Add user” -> specify the user name -> access type: “Programmatic access” -> do not select “AWS Management Console access” -> click “Next: Permissions”
* From the “add user to group”, either select existing group or click on “Create group” -> click “Next: Review” -> click on “Create user”
* Download the CSV file with the “Access key ID” and “Secret access key” and save the CSV file in a secure location
* Click Close
== Managing Profiles ==
* Login to the machine using privileged account.
* From command prompt, run the command below to invoke PowerShell (Windows platform)
: '''powershell'''
* From command prompt, run the command below to invoke PowerShell (CentOS platform)
: '''sudo pwsh'''
* Run the command below to add a new profile:
: '''Set-AWSCredential -AccessKey <AWS_Access_Key> -SecretKey <AWS_Secret_Key> -StoreAs <Profile_Name>'''
: Note 1: Replace '''<AWS_Access_Key>''' with the relevant value from the CSV file created above.
: Note 2: Replace '''<AWS_Secret_Key>''' with the relevant value from the CSV file created above.
: Note 3: Replace '''<Profile_Name>''' with your own profile name
* List all available profiles:
: '''Get-AWSCredential -ListProfileDetail'''
Reference:
: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html

Revision as of 09:30, 10 March 2019

How to configure PowerShell for managing AWS resources (Windows platform)

  • Login to the machine using privileged account.
  • From command prompt, run the command below to invoke PowerShell:
powershell
Note: You need to run cmd.exe or PowerShell.exe as administrator.
  • Run the command below to find out the current PowerShell version:
$PSVersionTable.PSVersion
  • In-case you currently have version older than 5.1, follow the article below to locate the download URL for upgrading to the latest version of PowerShell:
https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell?view=powershell-6
Also, review the article below for PowerShell installation pre-requirements:
https://docs.microsoft.com/en-us/powershell/scripting/setup/windows-powershell-system-requirements?view=powershell-5.1
  • Run the below command to check if you have PowerShellGet installed on your system:
Get-Module PowerShellGet -list | Select-Object Name,Version,Path
  • In-case you don’t have PowerShellGet, run the commands below:
Install-PackageProvider Nuget –Force
Install-Module -Name PowerShellGet –Force
For more information about installation or upgrade of PowerShellGet, see:
https://docs.microsoft.com/en-us/powershell/gallery/installing-psget
  • Run the command below to install AWS tools for PowerShell core:
Install-Module -Name AWSPowerShell.NetCore -AllowClobber -Force
  • Run the command below to import the AWS PowerShell module:
Import-Module AWSPowerShell
  • Run the command below to update to the latest AWS PowerShell module:
Update-Module -Name AWSPowerShell.NetCore -Force
  • To view the installed versions of AWS PowerShell module, run the command below:
Get-Module -Name AWSPowerShell -List | select Name,Version
Get-Module -Name AWSPowerShell.NetCore -List | select Name,Version
  • To view the list of AWS services supported by the Tools for PowerShell, run the command below:
Get-AWSPowerShellVersion -ListServiceVersionInfo

How to configure PowerShell for managing Azure resources (CentOS platform)

  • Login to the machine using privileged account.
  • Run the command below to register the RedHat repository:
curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
Note: The above command should be written in a single line
  • Run the command below to install PowerShell:
sudo yum install -y powershell
  • From command prompt, run the command below to invoke PowerShell:
sudo pwsh
  • Run the command below to find out the current PowerShell version:
$PSVersionTable.PSVersion
  • Run the below command to check if you have PowerShellGet installed on your system:
Get-Module PowerShellGet -list | Select-Object Name,Version,Path
  • In-case you don’t have PowerShellGet, run the commands below:
Install-Module -Name PowerShellGet –Force
For more information about installation or upgrade of PowerShellGet, see:
https://docs.microsoft.com/en-us/powershell/gallery/installing-psget
  • Run the command below to install AWS tools for PowerShell core:
Install-Module -Name AWSPowerShell.NetCore -AllowClobber -Force
  • Run the command below to update to the latest AWS PowerShell module:
Update-Module -Name AWSPowerShell.NetCore -Force
  • To view the installed versions of AWS PowerShell module, run the command below:
Get-Module -Name AWSPowerShell.NetCore -List | select Name,Version
  • To view the list of AWS services supported by the Tools for PowerShell, run the command below:
Get-AWSPowerShellVersion -ListServiceVersionInfo

How to configure AWS Account and Access Keys

  • Login to the IAM Console:
https://console.aws.amazon.com/iam/
  • From the left pane, click on Users -> click on “Add user” -> specify the user name -> access type: “Programmatic access” -> do not select “AWS Management Console access” -> click “Next: Permissions”
  • From the “add user to group”, either select existing group or click on “Create group” -> click “Next: Review” -> click on “Create user”
  • Download the CSV file with the “Access key ID” and “Secret access key” and save the CSV file in a secure location
  • Click Close

Managing Profiles

  • Login to the machine using privileged account.
  • From command prompt, run the command below to invoke PowerShell (Windows platform)
powershell
  • From command prompt, run the command below to invoke PowerShell (CentOS platform)
sudo pwsh
  • Run the command below to add a new profile:
Set-AWSCredential -AccessKey <AWS_Access_Key> -SecretKey <AWS_Secret_Key> -StoreAs <Profile_Name>
Note 1: Replace <AWS_Access_Key> with the relevant value from the CSV file created above.
Note 2: Replace <AWS_Secret_Key> with the relevant value from the CSV file created above.
Note 3: Replace <Profile_Name> with your own profile name
  • List all available profiles:
Get-AWSCredential -ListProfileDetail

Reference:

https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html