What are the Basic PowerShell Commands you need to know?

January 2, 2023
PowerShell

The PowerShell cmdlets you should know in 2023!

Command Discription
Set-Location Cange direcotry. Directly after "cd, sl, chdir" you can specify where you want to go.
Example: Back to the drive letter cd / or a specific path cd C:\Program Files\Microsoft with cd .. you can jump back one directory.
Get-Help The Get-Help cmdlet displays information about PowerShell concepts and commands, including cmdlets, functions, Common Information Model (CIM) commands, workflows, providers, aliases, and scripts.
Example: Get-Help Set-Location
Get-Process Shows a list of all active system proceses with their Id. It is an alternative to Windows Task Manager to view system processes
Example: Get-Process or for stopping Get-Process -ID 832 | Stop-Process ID = 832 is the cmd process
Start-Process To start one or multiple processes on your local computer. Example: Start Microsoft Edge Start-Process msedge or Start-Process -FilePath "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" -Verb runAs -Verb runAs runs the process as an administrator.
Clear-Host With Clear-Host or simply cls you remove all text, including commands and thier output from the current PowerShell display. It affects only the current display.
Get-Service To get a list of all the services installed on the Windows operating systems, their status, and startup type. To specify use the parameters e.g. -Name "WinDefend"
Get-Service or Get-Service -Name IP*
Get-ChildItem Lists all files in your current directory. So it's like the File Explorer. Get-ChildItem -Path "C:\Program Files" for a specific directory or only Get-ChildItem for the current working directory. Instead of Get-ChildItem you can also use ls as a shorter version.
New-Item To create a file in PowerShell, you can use the New-Item cmdlet (ni). By changing the file extension, you can create any type of file, such as a text or word document.
ni test.txt or ni -Path "V:\Folder\file.txt"
Copy-Item To copy files, folders and thier content to another directory. After Copy-Item or cp enter the path to copy and with the parameter -Destination destination directory. cp "C:\Program Files\PuTTy" -Destination 'V:\DestinationFolder' -Recurse -Recurse makes sure to move all the folder contents, otherwise PowerShell will only copy the top-level folder in my example PuTTY.
Move-Item For moving an item. To move folders, files, sub-folders and all content to another destination. mv -Path "V:\Folder" -Destination "V:\DestinationFolder" This command moves the folder "Folder" and all its contents to the DestinationFolder.
Remove-Item With the Remove-Item cmdlet (rm) you can delete files, folders, functions and ohter data types form a specific direcotry. rm V:\DestinationFolder
Get-Content The Get-Content cmdlet shows you the content of an item without using a texteditor. Get-Content "V:\Folder\file.txt
Clear-Content With the Clear-Content cmdlet you can delete the contents of a specififed file without deleting the file itself.
Clear-Content -Path "V:\Folder\file.txt" now thê file.txt is empty but still exists.
Set-ExecutionPolicy PowerShell execution policies are a security mechanism to protect your system from running malicious scripts. Execution policies don’t prevent you from running PowerShell code in the console as a shell but script execution. To know you current execution policy type: Get-ExecutionPolicy for executing unsigned scripts type: Get-ExecutionPolicy
Get-History You can use the Get-History cmdlet instead of using the up and down arrow keys to scroll through recent commands. Get-History or h 4 | fl this will show you detailed information about the command with Id 4.


I hope it will help you as a little cheat sheet.
To learn PowerShell properly you just need to do some projects. Because here it's really learning by doing. If you feel like it, you can take a look at one of my projects: Manage ADDS with PowerShell