Skip to content

Powershell

September 29, 2023
May 19, 2023

PowerShell Documentation - PowerShell | Microsoft Learn
What is PowerShell? - PowerShell | Microsoft Docs
Differences between Windows PowerShell 5.1 and PowerShell 7.x - PowerShell | Microsoft Docs

Introduction - PowerShell | Microsoft Learn

PoshCode/poshcode.github.io: github pages
About this Guide - PowerShell Practice and Style
PoshCode/PowerShellPracticeAndStyle: The Unofficial PowerShell Best Practices and Style Guide

Awesome Rank for janikvonrotz/awesome-powershell

# allow scripts
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Use "`" to escape ";" (like "" in Linux)

Powershell Tutorial - Tutorialspoint
Getting Started with PowerShell
Learning PowerShell: The basics | Computerworld PowerShell primers series
PowerShell Tutorials - Stephanos Constantinou Blog
PowerShell - Simple Talk

Initial page - PowerShell FAQ
PowerShell commands - PowerShell - SS64.com
PowerShell Core Commands - Stephanos Constantinou Blog
The 16 Best PowerShell Commands (Cmdlets) You Must Know
powershell Archives - ShellHacks

lextm/windowsterminal-shell: Install/uninstall scripts for Windows Terminal context menu items
Hosting PowerShell in a Python script - PowerShell Team

How to Debug a PowerShell Script – CloudSavvy IT

Profile

about Profiles - PowerShell | Microsoft Learn
Understanding the Six PowerShell Profiles - Scripting Blog

~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
~\OneDrive\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 if OneDrive is setup

Providers

about_Providers - PowerShell | Microsoft Docs
PowerShell Providers - Stephanos Constantinou Blog
All about PowerShell providers and modules | Computerworldv

Alias - Windows PowerShell aliases {Alias}
Certificate - X509 certificates for digital signatures {cert}
Environment - Windows environment variables {Env}
FileSystem - File system drives, directories and files {filesystem}
Function - Windows PowerShell functions {Function}
Registry - Windows registry {HKLM, HKCU}
Variable - Windows PowerShell variables {Variable}

Environment Variables

Use PowerShell to Set Environment Variables
Windows Environment variables - PowerShell - SS64.com

# show environment variables
Get-Childitem env: | sort name
ls env:
echo $Env:PATH
echo $Env:USERPROFILE

# using variable
ls $Env:USERPROFILE

# set variable
$env:Variable = 'value'

Persist Environment Variables

# scoped to the User
[System.Environment]::SetEnvironmentVariable('Variable','value',[System.EnvironmentVariableTarget]::User)
# scoped to the Machine
[System.Environment]::SetEnvironmentVariable('Variable','value',[System.EnvironmentVariableTarget]::Machine)

Unix command equivalents

PowerShell equivalents for common Linux/bash commands - TheShellNut
Get-Command (Microsoft.PowerShell.Core) - PowerShell | Microsoft Learn gcm shows all commands adn
Windows: Grep Equivalent - CMD & PowerShell - ShellHacks

UnixPowershell
pwdGet-Location
lsGet-Childitem/ls
test -eTest-Path
which/typeGet-Command
xdg-openStart-Process
grepfindstr/Select-String
find . -type f -iname <filter>Get-ChildItem -Filter <filter> -Recurse -File
cpCopy-Item/cp
rmRemove-Item/rm
touchNew-Item
catGet-Content/type
manGet-Help/help

CmdletBinding

about_Functions_CmdletBindingAttribute - PowerShell | Microsoft Docs
about_Functions_Advanced_Parameters - PowerShell | Microsoft Docs
about_Functions_CmdletBindingAttribute - PowerShell | Microsoft Docs
PowerShell advanced functions – The CmdletBinding and Parameter attribute – 4sysops

# parsing argument
[CmdletBinding()]
param()

Session Manager

Poor-man's Tmux

# script to setup a tmux-like environment
# $workspace_root = $env:USERPROFILE\src\project
$workspace_root = C:\src\project

$commands = @"
  nt -d $workspace_root --title Project `;
  nt -d $workspace_root --title Project `;
  nt -d $env:APPDATA\ --title "App data"
"@

# echo "wt $command_arr"
Start-Process wt -ArgumentList $command_arr