PowerShell Basics

This is a quick reference cheat sheet covering PowerShell basics.

#Table of Contents

#Version & Host

#Check Version

$PSVersionTable.PSVersion
# Output:
# Major  Minor  Patch
# 7      5      2

#Executable Path

"C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\pwsh.exe"

#Command Structure

#Verb-Noun Pattern

Get-Command
Get-Date
Get-Service

#Filter by Noun

Get-Command -Noun Service  # Lists all commands with 'Service' noun

#Help & Aliases

#Get Help

Get-Help Get-Service        # Short help
Get-Help Get-Service -Full  # Detailed help

#Aliases & Clear Screen

Get-Alias   # List all aliases
cls         # Clear host screen

#Scripts & Policy

#Edit & Run Script

psedit .\test.ps1   # Open in editor
.\test.ps1          # Execute script

#Execution Policy

Get-ExecutionPolicy
# => RemoteSigned (local scripts allowed)

#Copying Directories

#Initial Structure

source/
  file1.txt
  file2.txt
dist/   # may or may not exist

#1. Copy folder (target does NOT exist)

Copy-Item source dist
# Result:
dist/
  file1.txt
  file2.txt

#2. Copy into existing folder

Copy-Item source dist
# Result:
dist/
  source/
    file1.txt
    file2.txt

#3. Trailing slash behavior

Copy-Item source dist/   # same as Copy-Item source dist
Copy-Item source/ dist   # same as Copy-Item source dist
# Windows ignores trailing slashes

#4. Copy only contents

Copy-Item source\* dist -Recurse
# Result:
dist/
  file1.txt
  file2.txt

#Summary

  • Trailing slashes are ignored on Windows.
  • If target exists → source copied inside it.
  • If target does NOT exist → source renamed to target.
  • Use source\* to copy contents only.