Most Windows users are familiar with the Command Prompt (CMD). It is a command-line utility used to perform various types of tasks, some of which may be very difficult to perform using the GUI of Windows. It is also one of those things that are reminiscent of the (good?) old days of DOS. Nowadays, we have several new command-line utilities that look as well as perform better than the Command Prompt. One of these utilities is Microsoft’s own Windows PowerShell. It is loaded with more power and flexibility and it grants you control over nearly every aspect of the Windows OS. Here, we’re going to help you in getting started with Windows PowerShell.
Getting Started with Windows PowerShell
Someone aptly said –
PowerShell is what you get when you give steroids to the Windows Command Prompt.
That’s true. Windows PowerShell is indeed a more powerful form of the Command Prompt. It can perform all the tasks like navigating the file system, interacting with files and modifying their properties (and so on). It also makes good use of the .NET framework to perform tasks that could not be done in the Command Prompt. However, as is the case with all good things, it has a downside – its learning curve. In other words, utilizing the full power of Windows PowerShell requires a lot of effort. But we have a suggestion for you – start using PowerShell for simple tasks and gradually you’ll feel comfortable in dealing with the advanced stuff, such as creating cmdlets (cmdlets are PowerShell commands) and using the OneGet Package Manager. Therefore, we’re going to first show you how some basic commands work in PowerShell. These commands work exactly the same way as those in Command Prompt.
Please Note that in Windows PowerShell, there are four types of commands – a) Alias, b) Cmdlet, c) Function, and d) Script
Some basic commands with their Aliases
- dir – Used for displaying the contents of the current directory. Its alias is Get-ChildItem. In other words, you can use Get-ChildItem instead of dir.
- cls – Used to clear the PowerShell window. Its alias is Clear-Host.
- md or mkdir – Used to create a new directory. It has no alias.
- rd or rmdir – Used to delete an existing directory. Its alias is Remove-Item.
- cd or chdir – Used to change the current directory. Its alias is Set-Location.
As you can see in these images, these commands work the same way as they work in the Command Prompt. Therefore, you could begin with these commands to get accustomed to the Windows PowerShell. However, the real power of PowerShell lies in its cmdlets, some of which are listed below –
Getting Started with Windows PowerShell with some useful cmdlets
- Get-Process – It shows a list containing the details of the processes that are currently running on your computer. Other related cmdlets are – Start-Process, Stop-Process, and Wait-Process. As the name suggests, Start-Process is used to start a new process. Similarly Stop-Process is used to stop an existing process. Once you get accustomed to these commands, handling processes with PowerShell would be easier than with the Task Manager.
- Get-Service – It shows a list containing the details of the services present on your computer along with their status i.e. Running or Stopped. Other related cmdlets are – Start-Service, Stop-Service, Suspend-Service, Resume-Service and Restart-Service. The tasks performed by these services are obvious from their names.
- Get-Content – It shows the contents of the file/folder whose named is specified with the cmdlet. In case of folder, it shows you the contents of that folder. In case of text file, it shows the text contained in that file. If you use the name of an image file, you get a bunch of meaningless binary data. The following image shows this cmdlet being used with a text file.
- Get-Item – It shows some basic information about the file/folder whose named is specified with the cmdlet. In the following image, it shows the file name, file size, last modification time etc.
- Get-Help – As the name suggests, this cmdlet shows some help information. If you type Get-Help and press Enter, it shows you some information about the Help System. However, to get the real “help” you need to use one of the following commands – a) Get-Help <command>, b) Get-Help <command> -Full, and c) Get-Help <command> -Example. Get-Help <command> provides a description of that command, related commands, and syntax rules when using the command. When viewing syntax rules, elements in square brackets  are optional. Get-Help <command> -Full provides more details of that particular command. Get-Help <command> -Example shows several examples of how that command can be used and what sort of output you may expect.
- Get-Command – It shows a list of all commands that are currently available to the user i.e. you. In other words, it doesn’t list every command present in PowerShell. This list is very long. Therefore, to find the command you are looking for you need to filter them. For this, you may use Get-Command -Name <name> or Get-Command -CommandType <type>. Get-Command -Name <name> shows commands with the given name. You may also use wildcards. For example, you may use Get-Command -Name *Process* to find all commands that have “Process” in their name. Get-Command -CommandType <type> is used to filter commands using their types. For example, to list only cmdlets, you may use Get-Command -CommandType Cmdlet. (As mentioned above, there are four types of commands in PowerShell).
We hope this article will help you in getting started with Windows PowerShell. We shall describe more functions of Windows PowerShell in our next article, including OneGet Package Manager, which has been introduced in Windows 10. OneGet Package Manager brings the Linux’s way of installing applications to Windows.