PowerShell is a powerful scripting language and command-line shell developed by Microsoft, designed primarily for task automation and configuration management.
It’s built on the .NET Framework and utilizes a versatile scripting language called PowerShell Scripting Language (PSL).
With its ease of use, flexibility, and robustness, PowerShell has become an indispensable tool for system administrators and developers alike.
Stay One Step Ahead of Cyber Threats
Why Use Powershell?
One of the main reasons you’d want to use PowerShell is its ability to seamlessly manage and automate tasks across different Microsoft platforms and services.
It can be used to interact with the Windows operating system, Active Directory, Exchange Server, Azure, and many other Microsoft technologies.
Moreover, PowerShell enables you to manage remote systems, execute commands in parallel, and perform complex tasks with just a few lines of code.
Its object-oriented nature allows for precise control over data manipulation, offering better error handling and output formatting.
History of Powershell
PowerShell was first introduced in 2006 as Windows PowerShell, a replacement for the traditional Command Prompt (cmd.exe).
It was designed to address the limitations of the Command Prompt and provide a more powerful and extensible scripting environment.
The first version of PowerShell, 1.0, was released with Windows Server 2008, and its popularity grew steadily with each subsequent release.
In 2016, Microsoft made a significant announcement: PowerShell was going open source, and a cross-platform version called PowerShell Core was being developed.
This move aimed to expand PowerShell’s reach and usability beyond the Windows ecosystem.
PowerShell Core, built on the .NET Core framework, was first released in 2018 as version 6.0, offering support for macOS and
45 Linux Commands with Their Powershell Equivalents
No. | Linux Command | PowerShell Equivalent | Linux Example | PowerShell Example |
---|---|---|---|---|
1 | ls | Get-ChildItem | ls /home/user | Get-ChildItem C:\Users\User |
2 | pwd | Get-Location | pwd | Get-Location |
3 | cd | Set-Location | cd /home/user | Set-Location C:\Users\User |
4 | mkdir | New-Item | mkdir new_directory | New-Item -ItemType Directory -Path new_directory |
5 | touch | New-Item | touch new_file.txt | New-Item -ItemType File -Path new_file.txt |
6 | cp | Copy-Item | cp file1.txt file2.txt | Copy-Item file1.txt file2.txt |
7 | mv | Move-Item | mv file1.txt dir1/ | Move-Item file1.txt dir1\ |
8 | rm | Remove-Item | rm file.txt | Remove-Item file.txt |
9 | cat | Get-Content | cat file.txt | Get-Content file.txt |
10 | grep | Select-String | grep ‘word’ file.txt | Select-String -Path file.txt -Pattern ‘word’ |
11 | echo | Write-Output | echo “Hello, World!” | Write-Output “Hello, World!” |
12 | wc | Measure-Object | wc -l file.txt | Get-Content file.txt | Measure-Object -Line |
13 | chmod | Set-Acl | chmod 755 file.txt | N/A (Permissions are set differently in Windows) |
14 | chown | Set-Owner | chown user:group file.txt | N/A (Ownership is set differently in Windows) |
15 | sudo | Start-Process | sudo apt-get update | Start-Process -Verb RunAs PowerShell |
16 | kill | Stop-Process | kill -9 12345 | Stop-Process -Id 12345 -Force |
17 | ps | Get-Process | ps | Get-Process |
18 | tail | Get-Content | tail -n 10 file.txt | Get-Content -Path file.txt -Tail 10 |
19 | sort | Sort-Object | sort file.txt | Get-Content file.txt | Sort-Object |
20 | head | Get-Content | head -n 10 file.txt | Get-Content -Path file.txt -Head 10 |
21 | date | Get-Date | date | Get-Date |
22 | uname | Get-CimInstance | uname -a | Get-CimInstance -ClassName Win32_OperatingSystem |
23 | df | Get-PSDrive | df -h | Get-PSDrive -PSProvider FileSystem |
24 | du | Get-ChildItem | du -sh /home/user | Get-ChildItem -Path C:\Users\User -Recurse -Force | Measure-Object -Property Length -Sum |
25 | tar | Compress-Archive | tar -czvf archive.tar.gz folder | Compress-Archive -Path folder -DestinationPath archive.zip |
26 | gzip | Compress-Archive | gzip file.txt | Compress-Archive -Path file.txt -DestinationPath file.txt.gz |
27 | gunzip | Expand-Archive | gunzip file.txt.gz | Expand-Archive -Path file.txt.gz -DestinationPath . |
28 | wget | Invoke-WebRequest | wget https://example.com/file.txt | Invoke-WebRequest -Uri https://example.com/file.txt -OutFile file.txt |
29 | alias | Set-Alias | alias ll=’ls -la’ | Set-Alias -Name ll -Value “Get-ChildItem -Force” |
30 | curl | Invoke-WebRequest | curl -O https://example.com/file.txt | Invoke-WebRequest -Uri https://example.com/file.txt -OutFile file.txt |
31 | env | Get-ChildItem | env | Get-ChildItem -Path Env: |
32 | export | Set-Variable | export VAR=value | Set-Variable -Name VAR -Value “value” -Scope Global |
33 | history | Get-History | history | Get-History |
34 | ifconfig | Get-NetIPAddress | ifconfig | Get-NetIPAddress |
35 | man | Get-Help | man ls | Get-Help Get-ChildItem |
36 | ping | Test-NetConnection | ping example.com | Test-NetConnection -ComputerName example.com |
37 | sed | ForEach-Object | sed ‘s/old/new/g’ file.txt | Get-Content file.txt | ForEach-Object { $_ -replace ‘old’, ‘new’ } | Set-Content file.txt |
38 | awk | ForEach-Object | awk ‘{print $1}’ file.txt | Get-Content file.txt | ForEach-Object { ($_ -split ‘\s+’)[0] } |
39 | top | Get-Process | top | Get-Process | Sort-Object -Descending CPU |
40 | crontab | Task Scheduler | crontab -e | N/A (Use Windows Task Scheduler) |
41 | scp | Copy-Item | scp file.txt user@host:/path/ | Copy-Item -Path file.txt -Destination \hostname\path\ -ToSession (New-PSSession -ComputerName hostname) |
42 | ssh | Enter-PSSession | ssh user@host | Enter-PSSession -ComputerName hostname -Credential (Get-Credential) |
43 | diff | Compare-Object | diff file1.txt file2.txt | Compare-Object (Get-Content file1.txt) (Get-Content file2.txt) |
44 | passwd | Set-LocalUser | passwd | Set-LocalUser -Name “username” -Password (Read-Host -AsSecureString) |
45 | uptime | Get-CimInstance | uptime | (Get-CimInstance -ClassName Win32 |
"Amateurs hack systems, professionals hack people."
-- Bruce Schneier, a renown computer security professional