Author : HASSAN MD TAREQ | Updated : 2021/12/01
Chocholatey
- Chocolatey is a package manager for windows
- Similar to homebrew in Mac or yum in Linux
Installing chocholatey using Windows PowerShell (PowerShell 5.1 comes with Windows by default)
- Open Windows PowerShell (PowerShell 5.1) as administrator
- Run command (given below) into Powershell > Answer ‘Yes’ if prompted
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
Installing chocholatey using other methods
- cmd:
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
- Details: https://docs.chocolatey.org/en-us/choco/setup
Upgrade Chocholatey
choco upgrade chocolatey -y
Check Chocholatey version
choco upgrade --noop
Uninstalling: https://community.chocolatey.org/courses/installation/uninstalling
PowerShell Core
“PowerShell (or PowerShell Core or PowerShell 7)” vs “Windows PowerShell”
- “PowerShell” or “PowerShell Core” (also known as PowerShell 7) is an open source, cross platform tool
- “Windows PowerShell” is Windows specific tool (version 5.1)
Check PowerShell Core is installed or not
- Taskbar search > type “powershell”
- “PowerShell 7 (x64)” with black icon will show up if PowerShell Core or PowerShell 7 is installed
Installing PowerShell Core using chocolatey (open cmd as administrator, unattended installation)
choco install powershell-core -y
choco upgrade powershell-core -y
choco uninstall powershell-core -y
choco uninstall powershell-core -y -f
Installing PowerShell Core using cmd (open cmd as administrator, unattended installation, check latest version here)
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
Installing PowerShell Core using Windows PowerShell (open Windows PowerShell as administrator, installation wizard will show up)
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"
# Long version of above command: Invoke-Expression "& { $(Invoke-Restmethod https://aka.ms/install-powershell.ps1) } -UseMSI"
Restart PC and check PowerShell Core or PowerShell 7 is installed properly
- Taskbar search > type “powershell”
- “PowerShell 7 (x64)” with black icon will show up > Run as administrator
- Check version:
$PSVersionTable.PSVersion
PowerShellGet
PowerShellGet is the module maanger 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
PowerShell in VS Code
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
PowerShell in Visual Studio
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
PowerShell Azure Module
Azure ‘Az’ module in PowerShell Core
<#
# ===================================================================================================
# Installation Using Chocolatey
# ===================================================================================================
#>
choco install az.powershell -y --params="'/core'"
choco install az.powershell -y -f --params="'/core'" # forcing
choco upgrade az.powershell -y --params="'/core'"
choco uninstall az.powershell -y --params="'/core'"
choco uninstall az.powershell -y -f --params="'/core'"
<#
# ===================================================================================================
# Installation 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
#
Get-InstalledModule -Name Az # Get-InstalledModule -Name Az -AllVersions -OutVariable AzVersions
Get-InstalledModule -Name "Az*"
Get-InstalledModule -Name "Az.*"
#
# Now uninstall AzureRM
#
Uninstall-AzureRm -Force
Azure ‘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
Using Latest PowerShell in PowerShell ISE
- Execute the command (below) and workaround mentioned here: https://old.ironmansoftware.com/using-powershell-core-6-and-7-in-the-windows-powershell-ise
- Click Add-ons > Select PowerShell 7 (or current latest version)
- Check version again, you will se latest version is being use
- Caveat:
- As of July, 2021, it’s a workaround until Microsoft provides latest PowerShell for PowerShell ISE
- You might need to do it every time you open PowerShell ISE
- Error message might be shown (ignore it)
#
# 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 use PowerShell command (below)
- See: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows
PowerShell command to Install Azure CLI
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; rm .\AzureCLI.msi
Upgrade Azure CLI
az upgrade
Check version
az --version
Azure CloudShell
- Azure Cloud Shell is an interactive, authenticated, browser-accessible shell for managing Azure resources
- It provides the flexibility of choosing the shell experience that best suits the way you work - either Bash or PowerShell
- Pricing: The machine hosting Cloud Shell is free, with a pre-requisite of a mounted Azure Files share. Regular storage costs apply
Accessing Cloudshell
- Direct link: https://shell.azure.com
- Azure portal: Select the Cloud Shell icon on the Azure portal (top right corner)
Initial Setup
- Cloushell requires Azure Storage Account file share
- Create Storage Account > Launch cloudshell > set it up
How to Use Manifest File in Command (i.e. to deploy K8s workload)
- Open cloudshell and expand the window
- Open code editor by either of the following ways:
- Click ‘
{ }
’- need to save file with extension to get code highlights (click top right elipses > save)
- shows files on left side
- Run: ‘
code xyz.yaml
’ (or ‘code xyz.json
’) -> does not show files on left side
- Click ‘
- Copy paste or write yaml or json content > save
- Refer file with flag in kubectl command: ‘
kubectl apply -f xyz.yaml
’
Re-mount fileshare
- Create new fileshare in target storage account if needed & copy the name of the fileshare (i.e. ‘xxx-fs’)
- Open cloudshell (Azure portal > top right icon)
clouddrive unmount
(session will be terminated and cloudshell will be re-started)- Select subscription and click “Show Advanced settings”
- Select location
- Select resource group, select storage account, paste fileshare name (i.e. ‘xxx-fs’)
Connecting and running cloudsehll in VS Code
- Download and install nodejs: https://nodejs.org/en/download/current/
- Download and install VS Code: https://code.visualstudio.com/download
- Install “Azure Account” extension: https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account
- Press “F1” > write “> Azure: Open PowerShell”
- Login to Azure (default browser will open)
- Cloud shell is connected
Running Azure CloudShell Locally
- Azure CloudShell has “20 minutes” session timeout. Sometimes it’s annoying and therefore you might want to run CloudShell locally
- CloudShell Github repo: https://github.com/Azure/CloudShell
- PowerShell Script Courtesy: https://thewindowsupdate.com/2020/11/10/how-to-setup-and-run-azure-cloud-shell-locally/
PowerShell launcher script
- Create a folder in C drive named “az-cloudshell” (
C:\az-cloudshell
) - Create a PowerShell script named “
cloudshell-launcer.ps1
” (C:\az-cloudshell\cloudshell-launcer.ps1
) - Create a folder named “scripts” (
C:\az-cloudshell\scrips
) - All of your scripts should be in “
C:\az-cloudshell\scrips
” folder and those scripts would be available in the mounted folder (/usr/cloudshell
) in container
C:\az-cloudshell\cloudshell-launcer.ps1
$startShellType = "/usr/bin/pwsh" # PowerShell, for bash -> "/bin/bash"
$cloudshellImageName = "mcr.microsoft.com/azure-cloudshell"
$sourceScriptFolder = "`"C:\az-cloudshell\scripts`"" # the folder where your local scrips are located, double quote is required ('`' to escape double quote)
$targetScriptFolder = "/usr/cloudshell" # mounted folder in container
$container = $(docker ps -q --filter ancestor=$cloudshellImageName)
$containerIsRunning = ($container -ne $null)
if ($containerIsRunning) {
Write-Host "Container is running. Connecting to container..."
docker exec -it $container $startShellType
} else {
Write-Host "Container is not running. Updating container image..."
docker pull "$($cloudshellImageName):latest"
Write-Host "Mapping '$($sourceScriptFolder)' to '$($targetScriptFolder)'. Connecting to cloudshell (interactive)... `r`n`r`n"
$volumeMount = "$($sourceScriptFolder):$($targetScriptFolder)"
docker run -it -v $volumeMount mcr.microsoft.com/azure-cloudshell $startShellType
}
Create shortcut with following
"C:\Program Files\PowerShell\7\pwsh.exe" -ExecutionPolicy Bypass -File "C:\az-cloudshell\cloudshell-launcer.ps1"
Now right click on shortcut and run (as “Admin” if required)
To connect azure account, use Device Authentication: DeviceAuthentication - Connect Azure Account in CloudShell when MFA is Enabled
Docker Desktop
Windows Subsystem for Linus 2 (WSL2)
- “Docker Desktop for Windows” uses WSL2
- Docker desktop will install it as a prerequisite
Window 10
- Download and install: https://www.docker.com/products/docker-desktop
- After installing docker desktop, you might need to restart
Windows VM
- Window Server 2022 VM
- WSL2 is not supported
- Github issue: https://github.com/microsoft/WSL/issues/6301#issuecomment-858816891
- Windows Server 2019 VM
- Open PowerShell as Admin and execute commands
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
- Download and install:** https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
- Reboot VM
- Open PowerShell as Admin and execute commands
- Courtesy: https://petri.com/how-to-install-wsl-on-windows-server
wsl commnads
wsl -l -v
wsl --list --online
wsl --install -d ubuntu
wsl --update
wsl --status
wsl --set-version <distro name> 2
wsl --set-version Ubuntu 2
Links
- https://www.thomasmaurer.ch/2019/08/how-to-install-wsl-2-on-windows-server/
- https://www.thomasmaurer.ch/2015/11/nested-virtualization-in-windows-server-2016-and-windows-10/
Pulumi
Install pulumi using chocolatey
choco install pulumi -y
Check version
pulumi version
Cmder
Install cmder using chocolatey
choco install cmder -y
# choco upgrade cmder
Open Cmder
- Location: ‘
C:\tools\Cmder
’ - Open ‘cmd’ > write “cmder” > enter
- Open ‘Run’ > cmder > enter
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
Upgrade Helm
choco upgrade kubernetes-helm -f -y
Add Helm to ‘Path’ environment variable
- In Windows 10 (64-bit), helm will be installed (by chocolatey) in the folder:
C:\ProgramData\chocolatey\lib\kubernetes-helm\tools\windows-amd64
- Search taskbar “environment” > Edit the system environment variables
- Environment variables > System variables > select “Path” > Edit
- New > Add path > Ok
Check if Helm was istalled successfully (open PowerShell or cmd)
# you might need to restart your cmd/Cmder/Git Bash/PowerShell
helm version
Connect Cmder to Azure
Login to Azure
- Taskbar > Search: “default apps” > Set the browser which you used to login to Azure
- Cmder >
az login
- Default browser will open > login to Azure portal
- Cmder is now connected to Azure portal
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
- Cluster configuration
- RBAC is enabled
- AKS-managed Azure Active Directory is enabled
- If you try to execute kubctl command, it will ask you to authenticate (cluster level authentication)
- Execute ‘
kubectl get pods --namespace xyz
’ - Reply in console form AKS cluster: ‘To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code XYZABC to authenticate’
- Go to: https://microsoft.com/devicelogin and enter the code (i.e. XYZABC from reply in console) to authenticate
- Execute ‘
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
- Chocholatey
- Check compatibility nodejs depending on your target angular version
- Compatibility matrix: https://gist.github.com/LayZeeDK/c822cc812f75bb07b7c55d07ba2719b3
- nodejs releases: https://nodejs.org/download/release/
Check if nodejs is laready installed or not
node -v
Install
# Open Git bash or PowerShell as Admin
choco install nodejs-lts -y
choco install nodejs-lts -y --force
Install specific version
# Open Git bash or PowerShell as Admin
choco install nodejs-lts --version=12.22.9 -y
Update
# Update to if already installed
choco upgrade nodejs-lts
Uninstall (you might want to install specific version)
choco uninstall nodejs-lts
choco uninstall nodejs
choco uninstall nodejs --version=17.2.0
Check correct nodejs version is installed
node -v
Install npm
# check version
npm -v
# install
npm i -g npm
# check version
npm -v
Installing Angular CLI
Prerequisites
- Chocholatey (to install NodeJS)
- NodeJS and NPM
Global installation
npm uninstall -g @angular/cli
npm cache clean --force
npm cache verify
npm install -g @angular/cli@latest
Local installation: Go to the priject folder and install local with --save-dev
rm -rf node_modules dist
npm install --save-dev @angular/cli@latest
npm i
ng update @angular/cli
ng update @angular/core
npm install --save-dev @angular-devkit/build-angular
Install specific version
npm install -g @angular/cli@11.2.14
npm install --save-dev @angular/cli@11.2.14
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
Openssl
#
# Check if already installed
#
openssl version
#
# Install
#
choco install openssl
Ruby and Jekyll
Install Ruby and DevKit
- Download and install: https://rubyinstaller.org/downloads/
- Install Ruby only (no DevKit)
- After installing Ruby, install DevKit (MSYS2 and Mingw toolchain):
- Open cmd as admin
- Command:
ridk install 3 2
Install Jekyll
gem install jekyll bundler
jekyll -v
Create a Jekyll site:
jekyll new xxx-blog
cd xxx-blog
- Open Gemfile, edit and save (don’t forget to add
gem "webrick", "~> 1.7"
in plugin section)
Gemfile
# This will help ensure the proper Jekyll version is running.
gem 'jekyll'
# This is the default theme for new Jekyll sites. You may change this to anything you like.
# gem "minima", "~> 2.0"
# If you want to use GitHub Pages, remove the uncomment "gem jekyll" above and
# uncomment the line below. To upgrade, run `bundle update github-pages`.
gem "github-pages", group: :jekyll_plugins
gem 'jekyll-theme-cayman', '~> 0.0.3'
# If you have any plugins, put them here!
# gem 'jekyll-analytics'
group :jekyll_plugins do
gem "jekyll-feed", "~> 0.6"
gem "jekyll-seo-tag"
gem 'jekyll-toc', "<= 0.12.2"
gem 'jekyll-commonmark-ghpages'
gem "webrick", "~> 1.7"
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]
# Performance-booster for watching directories on Windows
gem "wdm", "~> 0.1.0" if Gem.win_platform?
Install and update gems:
bundle install
bundle update
bundle update github-pages
Run locally:
bundle exec jekyll serve
bundle exec jekyll serve --livereload
bundle exec jekyll serve --incremental