PowerShell CheatSheet – CMD > PS
Here’s some common and usefull CMD to PS equivalents
MS-DOS command | PowerShell Equivalent | Explanation |
---|---|---|
xxx /? | Get-Help xxx –full | Displays the help for the ‘xxx’ command |
cacls xxx /E /G user:F | $ACL = Get-Acl xxx $TempACL = New-Object SSAF1 $ACL.SetAccessRule($TempACL) Set-Acl XXX $Acl | Modifys Access Control Lists (ACLs) for the ‘xxx’ file |
cd | Get-Location | Displays the name of the current directory |
cd xxx | Set-Location xxx | Changes the current directory for the ‘xxx’ directory |
cd /d x:\xxx | Set-Location x:\xxx | Changes current drive in addition to changing current directory (‘x:\xxx’) |
copy xxx PATH | Copy-Item xxx PATH | Copies the ‘xxx’ files to another location (‘PATH’) |
cls | Clear-Host | Clears the screen |
del xxx yyy | Remove-Item xxx yyy | Deletes the ‘xxx’ and ‘yyy’ files |
del /f /s /p xxx yyy | Remove-Item xxx yyy –Force –Recurse -Confirm | Deletes the ‘xxx’ and ‘yyy’ files from all subdirectories, even if it’s read-only files. Ask for confirmation for each file |
dir | Get-ChildItem | Displays a list of files and subdirectories in a directory |
dir /s | Get-ChildItem -Recurse | Displays files in specified directory and all subdirectories |
dir /ad | Get-ChildItem | Where {$_.PSIsContainer} | Displays files with specified attributes, directories only |
dir /a:-d | Get-ChildItem | Where {!($_.PSIsContainer)} | Displays files with specified attributes, files only |
fc file1 file2 | Compare-Object $(Get-Content File1) $(Get-Content File2) | Compares two files and displays the differences between them |
find “xxx” yyy /N | Select-String -Pattern xxx -Path yyy | Search for the ‘xxx’ string in the ‘yyy’ file and display the line(s) number(s) if found |
help | Get-Command | Gets the available commands/cmdlets |
hostname | $env:computername | Displays the computer’s hostname |
net share | Get-WmiObject Win32_Share | Gets the current network and administrative shares |
net time | Get-Date | Gets the current date and time |
net start | Get-Service | Where {$_.Status -eq “Running”} | Displays the list of running services |
net start xxx | Start-Service xxx | Starts the ‘xxx’ service |
ren xxx yyy | Rename-Item xxx yyy | Rename a file |
set | Get-ChildItem env: | Displays CMD environment variables |
set x= | Clear-Item $x | Deletes the contents of the ‘x’/’$x’ variable |
set x=value | $x=value | Affect ‘value’ to the ‘x’/’$x’ variable |
start xxx | Invoke-Item xxx | Invoke the (provider-specific) default action on the ‘xxx’ item |
tasklist | Get-Process | Gets the processes that are running on the local computer or a remote computer |
tasklist /FI “PID eq xxx” | Get-Process –Id xxx | Gets the process info with Process Id xxx |
tasklist /S \\XXX | Get-Process –ComputerName XXX | Gets the processes that are running on the remote computer XXX |
To Be Enriched…
1 SSAF: System.Security.AccessControl.FileSystemAccessRule(“user”,”FullControl”,”Allow”)