Worth a direct correction before anything else: `Get-WmiObject`, the cmdlet most PowerShell cheat sheets still lead with for system info, was removed entirely from PowerShell 7 — not deprecated, genuinely absent, so a script built around it fails outright on anything but Windows PowerShell 5.1. This is a trimmed, corrected reference: real, current commands grouped by task, with the specific gotchas worth knowing before running each one — not a “what is PowerShell” essay.
In this post: Setup: modules and execution policy · Basics and discovery · File and folder operations · System information, the corrected way · User, permission, and process management · Network commands · Remote management · PowerShell for SharePoint · A real bulk-user-creation script, with the caveat fixed · Error handling that actually helps · Related reading
Setup: modules and execution policy
# Install core modules
Install-Module -Name PowerShellGet -Force -AllowClobber
Install-Module -Name Az -Repository PSGallery -Force
# Allow local scripts to run for the current session only
Set-ExecutionPolicy RemoteSigned -Scope Process
`-Scope Process` scopes the policy change to the current PowerShell session only — worth using this over `-Scope CurrentUser` or `-Scope LocalMachine` for anything that isn’t a deliberate, permanent security-posture decision, since a process-scoped change reverts automatically when the session closes rather than persisting silently.
Basics and discovery
# Check version -- worth confirming before assuming a cmdlet exists
$PSVersionTable.PSVersion
# List every available command
Get-Command
# Get real, current help for a specific command
Get-Help Get-Process -Full
Checking `$PSVersionTable.PSVersion` first is worth making a habit rather than an afterthought — several commands in this list (flagged individually below) behave differently or don’t exist at all depending on whether the session is Windows PowerShell 5.1 or PowerShell 7+.
File and folder operations
New-Item -ItemType File -Path "C:\Temp\test.txt"
Copy-Item -Path "C:\Temp\test.txt" -Destination "C:\Backup\"
Remove-Item -Path "C:\Temp\test.txt"
Get-WmiObject isn’t deprecated in the usual sense — it’s genuinely gone from PowerShell 7. Get-CimInstance is the current replacement, uses WinRM instead of the more firewall-hostile DCOM protocol, and actually works cross-platform.
System information, the corrected way
# Current: Get-CimInstance, not Get-WmiObject
Get-CimInstance -ClassName Win32_OperatingSystem
# System uptime
(Get-CimInstance Win32_OperatingSystem).LastBootUpTime
The class name and most property names carry over directly from the old `Get-WmiObject` syntax — the migration is close to a straight cmdlet swap in most existing scripts, not a rewrite. Worth making it anyway rather than leaving `Get-WmiObject` in place: beyond the outright removal in PowerShell 7, `Get-CimInstance` uses WS-Man/WinRM for remote queries instead of DCOM, which needs a single firewall port (5985/5986) rather than the wide, harder-to-secure port range DCOM requires.
User, permission, and process management
Get-LocalUser
Get-Process
Stop-Process -Name "notepad"
Get-Service
Worth a direct correction on `Add-NTFSAccess`, which shows up in a lot of examples of this pattern presented as if it were built in: it isn’t. It ships in the third-party `NTFSSecurity` module and needs `Install-Module NTFSSecurity` first — the built-in equivalent, with no extra module required, is `icacls` (still the current tool for this on Windows) or `Set-Acl`/`Get-Acl` for a fully PowerShell-native approach:
$acl = Get-Acl "C:\Data"
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Domain\User", "FullControl", "Allow")
$acl.SetAccessRule($rule)
Set-Acl "C:\Data" $acl
Network commands
Get-NetIPAddress
Test-NetConnection google.com -TraceRoute
Get-NetAdapter
Worth knowing these three are genuinely Windows-only — unlike the file/process/service cmdlets above, which work identically in PowerShell 7 on Linux and macOS, the `NetTCPIP` module these come from has no cross-platform equivalent; a script that needs to run the same network check on Linux needs a different approach entirely (`Get-NetRoute`’s rough Linux equivalent is parsing `ip route`, not a PowerShell cmdlet).
PowerShell for SharePoint
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com" -Interactive
Get-PnPList | Where-Object { $_.BaseType -eq "DocumentLibrary" }
New-PnPSite -Type TeamSite -Title "Demo Site" -Alias "DemoSite" -Owner "user@tenant.onmicrosoft.com"
`-Interactive` is correct and current here — worth confirming against any older example still showing `-UseWebLogin`, which has been removed from `Connect-PnPOnline` entirely, not merely deprecated.
A real bulk-user-creation script, with the caveat fixed
Worth flagging directly: a version of this script that reads passwords straight out of a plain CSV column is a genuine, common security mistake, not a stylistic nitpick — anyone with read access to the CSV has every generated password in plain text, and the file often ends up sitting in a shared folder or an email attachment long after the accounts are created:
$users = Import-Csv "C:\Users.csv"
foreach ($user in $users) {
$tempPassword = ConvertTo-SecureString ([System.Web.Security.Membership]::GeneratePassword(16, 4)) -AsPlainText -Force
New-LocalUser -Name $user.Name -Password $tempPassword -MustChangePasswordAtNextLogon
}
Generating a random password per user and forcing a change at next logon removes the plain-text-CSV exposure entirely — the CSV only needs to supply the username, not a secret that then sits in a file. Worth using this pattern by default for any bulk-provisioning script, not just when a compliance requirement specifically demands it.
Error handling that actually helps
try {
Get-Content "C:\InvalidPath.txt" -ErrorAction Stop
} catch {
Write-Host "File not found: $($_.Exception.Message)"
}
`-ErrorAction Stop` is worth including explicitly on the command inside the `try` block — without it, many cmdlets emit a non-terminating error by default, which the `catch` block never sees at all, so the script continues past the failure silently instead of handling it the way the code visually suggests it will.
Remote management
Worth including the actual remoting commands, since “PowerShell can manage remote machines” gets repeated often without a real example attached. `Invoke-Command` runs a script block against one or many machines at once and returns the results to the local session — worth using over `Enter-PSSession` (an interactive single-machine remote shell) for anything that needs to run against more than one target or needs its output captured programmatically:
$servers = "Server01", "Server02", "Server03"
Invoke-Command -ComputerName $servers -ScriptBlock {
Get-Service -Name "Spooler"
} -Credential (Get-Credential)
Both cmdlets need WinRM enabled and listening on the target machines (`Enable-PSRemoting` sets this up) and, by default, need the connecting account to already be a local administrator on each target — worth checking both before assuming a remoting failure is a scripting bug rather than an environment prerequisite that was never set up.
Related reading
- How to Export SharePoint Site Users to an Excel Spreadsheet — a full worked example of the PnP PowerShell pattern shown above.
- SharePoint Permission Roles Quick Overview — the SharePoint-specific side of the permission-management commands covered here.
Most of these commands haven’t changed in years — the corrections worth internalizing are the ones that quietly did: `Get-WmiObject` is gone in PowerShell 7, plain-text passwords in a provisioning CSV are a real exposure worth designing around by default, and `-ErrorAction Stop` is the difference between a `try/catch` block that actually catches something and one that just looks like it does.
App Catalog Authentication Automation Backup Compliance Content Type CSS Flows Google Javascript Limitations List Metadata MFA Microsoft Node NodeJs O365 OneDrive Permissions PnP PnPJS Policy PowerApps Power Automate PowerAutomate PowerPlatform PowerShell React ReactJs Rest API Rest Endpoint Security Send an HTTP Request to SharePoint SharePoint SharePoint List SharePoint Modern SharePoint Online SPFX SPO Sync Tags Teams Termstore Versioning


