PowerShell is Microsoft’s alternative to their own Command Prompt. Earlier, Microsoft announced that they will be open sourcing PowerShell and will be bringing it to recent versions of different Linux flavors like Ubuntu, CentOS, Red Hat Enterprise Linux, OpenSUSE, Fedora and macOS. They also released PowerShell Core which offered far more features than the earlier edition of Powershell that was shipped along with Windows. It was built for System Administrators and meant to become an alternative the Command Prompt. With this cross-platform expansion of PowerShell, the users will gain benefits to work on different operating systems and environments.
Along the years, PowerShell has been worked on and upgraded to support more cmdlets or PowerShell commands just to enable it to be flexible enough to manage a variety of tasks. For organizations that run Windows-only software and services, Microsoft has been building their services like Windows Server, Azure Active Directory, and Exchange to be able to be managed by using PowerShell. This results in better usage of the services, rather than using GUI based configuration managers, and that helps in saving a lot of logistical costs in the long term.
Equivalent CMD commands that can be executed on PowerShell
Today, we will be talking about some basic commands for CMD that can be executed using PowerShell command line too.
1] If you want to navigate to any location in the command line it is really simple. Where you use cd in Command Prompt, you can use
Set-Location "<PATH>"
for the same thing inside PowerShell.
2] Listing all the contents of a folder is no biggie if will help you in navigating through a tree of directories. For the Command Prompt, we used dir, but when you use PowerShell, you can just use
Get-ChildItem
to list all the files and directories inside of a directory.
3] Renaming is something that we take for granted on our 100% GUI centric operating systems. But when one has to rename a file or a folder on a remote system, one had to rely on the rename command while using the Command Prompt but in PowerShell, they can use
Rename-Item "Path/of/the/file.txt" - NewName "NewNameOfTheFile.csv"
Using this, the user can change the name as well as the extension of the particular file.
4] If you know a command and are not sure what it is about, the /? command on the Command Prompt command line used to be a great help. Fortunately, PowerShell does not lack this feature. You can use
Get-Help "CMDLET NAME"
to check what a CMDLET on PowerShell does.
5] Even to stop a running process you do not need to rely on some sorts of Task Manager when you have PowerShell. taskkill is a reliable command on the Command Prompt, but with PowerShell, you can use
Stop-Process -Name "ApplicationName.exe"
6] This command that we are going to discuss is something that I have personally seen being used in Schools very often. It is a very useful command. It can be used to Shut down a remote computer or a server session. On the Command Prompt, shutdown -s can be used but for PowerShell,
Stop-Computer -ComputerName "HostName1","HostName2","Gateway or Address"
can be used to shut down a remote computer.
7] Similar to shutting down a computer, the Command Prompt command shutdown -r, the
Restart-Computer -ComputerName "HostNameNew", Gateway or Address"
can be used with PowerShell to do the same thing.
8] If some new changes are made to the Group Policy of a System and to see the changes, you need to force refresh the Group Policy, one used gpupdate /force on the Command Prompt. But on PowerShell, one can use
Invoke-GPUpdate -Computer "Name of the Host" -Force
can be used flawlessly.
9] To set Variables, in the Command Prompt command line, one could use
SET VariableName = "Value of the Variable"
, but on PowerShell, the $ takes care of everything. You can just use this command to do the needful,
$VariableName="Value of the Variable".
10] If you wish to join a computer to a domain, it is pretty straightforward too. In the Command Prompt, one could use this command:
netdom /domain:domainName /user:userName /password:passwordForTheDomain member hostname /add
but when you use PowerShell, you can leverage the use of
Add-Computer -DomainName "Domain" -Credential "Domain\Username" -Restart
If we observe carefully, the basic Command Prompt commands become a bit complicated when executed similarly with PowerShell. But when we talk about complex commands like the Domain joining command that we used in both Command Prompt and PowerShell, and when we observe, the one used in Command Prompt is much more complex than the PowerShell counterpart.
Hence, we can say that the implementation of PowerShell over the Command Prompt counterpart is better. This also comprises of the fact that it is available on other platforms and environments too.
We believe that Microsoft will be more aggressively working to make PowerShell better than the Command Prompt and not forcing users by replacing the Command Prompt with it.