Author : HASSAN MD TAREQ | Updated : 2021/04/27

PowerShell

“PowerShell” vs “Windows PowerShell”

Check PowerShell is intalled or not

Install Latest Version of PowerShell (not “Windows PowerShell”):

#
# Install latest version of PowerShell
#
# In the installation wizard, select "Do not close ..." -> you need to restart your PC
# 
Invoke-Expression "& { $(Invoke-Restmethod https://aka.ms/install-powershell.ps1) } -UseMSI"

# Short version of above command
# iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"

Latest release: https://github.com/PowerShell/powershell/releases

Restart PC and check PowerShell is installed correctly

#
# Check current version
#
$PSVersionTable.PSVersion

PowerShellGet Module

#
# 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

PowerShell Azure Module

Azure Az module in PowerShell

#
# Check Az module is installed or not
# If not installed, nothing will be retured after executing the command
#
Get-InstalledModule -Name Az # Get-Module -Name Az -Listavailable


#
# Install Az module
#
# Install-Module -Name Az -Force -AllowClobber
#
# Default repository is PSGallery
# You can specify repository explicitly: -Repository PSGallery
#
Install-Module -Name Az -Force -AllowClobber -Scope AllUsers

#
# Check all versions of Az module that are installed in your PC
#
Get-InstalledModule -Name Az # Get-InstalledModule -Name Az -AllVersions -OutVariable AzVersions
Get-InstalledModule -Name "Az.*"

#
# Now uninstall AzureRM
#
Uninstall-AzureRm

Azure Az module in “Windows PowerShell”

#
# 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

Using Latest PowerShell in PowerShell ISE

#
# Code snippet taken from: https://github.com/adamdriscoll/Presentations/blob/master/YouTube/Using%20PowerShell%207%20in%20the%20ISE/ps7.ps1
#

$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Clear()
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Switch to PowerShell 7", { 
        function New-OutOfProcRunspace {
            param($ProcessId)

            $ci = New-Object -TypeName System.Management.Automation.Runspaces.NamedPipeConnectionInfo -ArgumentList @($ProcessId)
            $tt = [System.Management.Automation.Runspaces.TypeTable]::LoadDefaultTypeFiles()

            $Runspace = [System.Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace($ci, $Host, $tt)

            $Runspace.Open()
            $Runspace
        }

        $PowerShell = Start-Process PWSH -ArgumentList @("-NoExit") -PassThru -WindowStyle Hidden
        $Runspace = New-OutOfProcRunspace -ProcessId $PowerShell.Id
        $Host.PushRunspace($Runspace)
}, "ALT+F5") | Out-Null

$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Switch to Windows PowerShell", { 
    $Host.PopRunspace()

    $Child = Get-CimInstance -ClassName win32_process | where {$_.ParentProcessId -eq $Pid}
    $Child | ForEach-Object { Stop-Process -Id $_.ProcessId }

}, "ALT+F6") | Out-Null

Azure CLI

Download and install: https://aka.ms/installazurecliwindows

Or using PowerShell command

Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; rm .\AzureCLI.msi

See: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows

Azure cloudshell

Accessing Cloudshell

Initial Setup

How to Use Manifest File in Command (i.e. to deploy K8s workload)

Chocholatey

Install chocolatey using PowerShell

# PowerShell console
Set-ExecutionPolicy Bypass -Scope Process -Force; `
  iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

# PowerShell ISE
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

Upgrade Chocholatey

choco upgrade chocolatey

Check Chocholatey version

choco upgrade pkgname --noop

Cmder

Install cmder using chocolatey

choco install cmder -y
# choco upgrade cmder

Open Cmder

Kubectl

Install kubectl using chocolatey

choco install kubernetes-cli -y
# choco upgrade kubernetes-cli

Check version

kubectl version --client

Helm

Install Helm using chocolatey

choco install kubernetes-helm -y

In Windows 10 (64-bit), helm will be installed (by chocolatey) in following folder

C:\ProgramData\chocolatey\lib\kubernetes-helm\tools\windows-amd64

Add the above folder to ‘Path’ environment variable

Check Helm was istalled successfully

# you might need to restart your cmd/Cmder/Git Bash/PowerShell
helm version

Connect Cmder to Azure

Login to Azure

az aks login

Using Cmder to Interact with AKS Cluster

# if you are not logged in yet
az aks login

# get aks credential
az aks get-credentials --resource-group xyz-rg --name xyz-aks-cluster

AKS cluster Access Control

Once authenticated into AKS cluster, now execute kubectl commands

# make sure you set the correct namespace
kubectl config view --minify | grep namespace  # check namespace, for default namespace no value (empty) might be shown
kubectl config set-context --current --namespace xyz # set namespace

# Nodes
kubectl get nodes

# Pods
kubectl get pods

# Services
kubectl get svc

Installing NodeJS and NPM

Prerequisites

Install NodeJS using chocolatey

choco install -y --force nodejs

Check version

node -v 

NPM

# install
npm i -g npm

# check version
npm -v

Installing Angular CLI

Prerequisites

Installing Angular CLI using npm

#
# Global installation
#
npm install -g @angular/cli@
npm install -g @angular/cli@latest

#
# Local installation -> don't use '-g' flag
#
npm install @angular/cli@latest

#
# install specific (target) version
# 
npm install -g @angular/cli@11.2.11

Check version

ng version

Uninstall Angular CLI

npm uninstall -g @angular/cli
npm uninstall @angular/cli
npm cache clean --force

#
# If you installed specific version
# i.e. version 11.2.11
#
npm uninstall -g @angular/cli@11.2.11
npm uninstall @angular/cli@11.2.11
npm cache clean --force

Installing jq

Make sure chocolatey is installed (see above)

choco install jq -y
# flag '-y' for accepting all