Author : MD TAREQ HASSAN | Updated : 2023/03/16
Installing PowerShell using chocolatey
# open cmd as administrator
choco install powershell-core -y
Upgrade
# open cmd as administrator
choco upgrade powershell-core -y
Installing PowerShell using Windows PowerShell
Open Windows PowerShell as administrator
# Installation wizard will show up
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"
# No installation wizard
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -Quiet"
# To install preview
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -Preview -UseMSI -Quiet"
# Note:
# Long version of above command-
# Invoke-Expression "& { $(Invoke-Restmethod https://aka.ms/install-powershell.ps1) } -UseMSI"
Upgrade: the above commands will install latest/preview version side by side with currently installed version of PowerShell.
Installing PowerShell using cmd
# open cmd as administrator
# check latest version: https://github.com/PowerShell/PowerShell/releases
curl --remote-name --location --url https://github.com/PowerShell/PowerShell/releases/download/v7.3.0-preview.6/PowerShell-7.3.0-preview.6-win-x64.msi
msiexec.exe /package %userprofile%\Downloads\PowerShell-7.3.0-preview.6-win-x64.msi /quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1 USE_MU=1 ENABLE_MU=1
Version check
$PSVersionTable.PSVersion
Uninstalling PowerShell
# open cmd as administrator
choco uninstall powershell-core -y
choco uninstall powershell-core -y -f
If installed using windows powershell or cmd, then uninstall from control panel.
PowerShellGet
PowerShellGet is the module manager for PowerShell.
#
# Check PowerShellGet module is installed or not
#
Get-Module -Name PowerShellGet -Listavailable
#
# If PowerShellGet module is not installed, then install PowerShellGet module
#
# Install/Update PowerShellGet module
# Check latest version of PowerShellGet: https://www.powershellgallery.com/packages/PowerShellGet
#
# If installation fails, try using follwoing flags (https://github.com/PowerShell/PowerShellGetv2/issues/599)
# -AllowClobber -SkipPublisherCheck
#
# Install-Module -Name PowerShellGet -RequiredVersion 2.2.5 -Force
#
Install-Module PowerShellGet -Repository PSGallery -Force
Install-Module PowerShellGet -Force # Dafault Repository: PSGallery
Uninstall AzureRM from Windows PowerShell
Notes:
Uninstall-AzureRM
is part of Az module- In order to remove AzureRM using
Uninstall-AzureRM
, we need to install Az module in Windows PowerShell first
Open Windows PowerShell as admin
Get-Module -ListAvailable | Where {$_.Name -like 'AzureRM.*'}
uninstall-module Azure
uninstall-module AzureRM
$Modules = Get-Module -ListAvailable | Where {$_.Name -like 'AzureRM.*'}
Foreach ($Module in $Modules) {Uninstall-Module $Module}
See: https://learn.microsoft.com/en-us/powershell/azure/uninstall-az-ps#uninstall-the-azurerm-module
Installing Az module using chocolatey
Open PowerShell Core as admin
#
# Install Az module
#
choco install az.powershell -y --params="'/core'"
choco install az.powershell -y -f --params="'/core'" # forcing
Upgrade
choco upgrade az.powershell -y --params="'/core'"
Uninstall
choco uninstall az.powershell -y --params="'/core'"
choco uninstall az.powershell -y -f --params="'/core'" # forcing
Installation check
Get-Module -Name "Az.*" -Listavailable # Az modules only
Get-Module -Name "Az*" -Listavailable # includes AzureRM modules
Installing Az module using PowerShellGet
#
# Check Az module is installed or not
#
# Get-InstalledModule -> only shows modules that are installed using PowerShellGet, does not show modules installed using other tools i.e. Chocolatey
# Get-Module -> shows all modules - either installed using PowerShellGet or other tools i.e. Chocholatey
#
Get-InstalledModule -Name Az
Get-Module -Name Az -Listavailable
Get-Module -Name "Az*" -Listavailable
Get-Module -Name "Az.*" -Listavailable
#
# Default repository is PSGallery, you can specify repository explicitly: -Repository PSGallery
#
Install-Module -Name Az
Install-Module -Name Az -Force
Install-Module -Name Az -Force -AllowClobber
Install-Module -Name Az -Force -AllowClobber -Scope AllUsers
#
# Check all versions of Az module that are installed in your PC using PowerShellGet
#
Get-InstalledModule -Name Az # Get-InstalledModule -Name Az -AllVersions -OutVariable AzVersions
Get-InstalledModule -Name "Az*"
Get-InstalledModule -Name "Az.*"
Az module in Windows PowerShell
<#
# ===================================================================================================
# Installation Using Chocolatey
# ===================================================================================================
#>
choco install az.powershell -y
#
# PowerShell script execution policy must be set to remote signed or less restrictive
# Get-ExecutionPolicy -List can be used to determine the current execution policy
#
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
#
# Using the Install-Module cmdlet is the preferred installation method for the Az PowerShell module
# Install the Az module for the current user only is the recommended installation scope
#
#Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force -AllowClobber
#
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
#
# Now uninstall AzureRM
#
Uninstall-AzureRm
VSCode integration
Prerequisites:
- Install PowerShell Core (PowerShell 7)
- Download and install VS Code (if not installed): https://code.visualstudio.com/Download
VS Code PowerShell Extension
Open VS Code and install powershell extension if not installed
Check that PowerShell core (PowerShell 7) is being used by VS Code PowerShell Extension:
- Open VS Code and press “Ctrl + Shift + `” (new terminal will be opened)
- Check PowerShell version:
$PSVersionTable.PSVersion
- If version is not PowerShell 7, then set powershell core as default integrated shell as following:
- Configure terminal settings (screenshot below)
- Search “terminal.integrated.shell”
- Shell integration: Enabled
- Default profile: Windows -> PowerShell
- Note: open VS Code as administrator to run PowerShell scripts
Visual Studio integration
PowerShell Core (PowerShell 7) in Visual Studio Terminal
- Visual Studio menu: View > Terminal (by default it’s developer powershell -> Windows PowerShell 5.1)
- Click gear icon (in terminal window) > Add
- Copy PowerShell Core location (
C:\Program Files\PowerShell\7
) - Name: PowerShell 7
- Shell location:
C:\Program Files\PowerShell\7\pwsh.exe
- Argumments”
- Set Default > Apply > Ok
- Copy PowerShell Core location (
- To change font size
- Tools > Options > Folts and Colors
- Show settings for: Terminal
- Select font and size > ok
PowerShell Tools for Visual Studio (Paid tool)
- Install PowerShell Tools for Visual Studio
- It’s a paid Visual Studio extension
- Free trial will be installed
- Open Visual as Admin
- After installing “PowerShell Tools for Visual Studio”, PowerShell script project tmeplate will be installed. Create new PowerShell script project) using that template
- For Azure PowerShell modules, make sure “Azure Development” workload is installed (Visual Studio installer > Workloads)
Menu > View => PowerShell => PowerShell Interactive Window