PowerShell versus CMD

If you are new to coding, PowerShell can be daunting if you are in operations. PowerShell is a mixture of standard command statements from DOS days and some.NET-style syntax.
The problem is that even a.NET programmer will need to take some time to master PowerShell syntax. It’s not like any Windows programming or command statements.
These are just a few of the ways PowerShell differs from standard command line statements.
Cmdlets versus Command statements
Learn how to become a security expert with SPOTO’s Cybersecurity Training
TrainingPowerShell is not just about command statements. PowerShell uses functions called cmdlets. These cmdlets can perform more complex queries and produce better output than the Windows command line.
Let’s look at how to get an IP address. You can use the Windows command line’s ipconfig statement. This will give you the IP address. You can use ipconfig/all to get all the parameters about the server, including DNS, subnet mask and adapter.
PowerShell allows you to use many more input parameters, which can give you a different level output. This is not necessary if your server is simple, but PowerShell can be a great operation for servers with high-level operations. You can see IP configuration for IPv4 or IPv6 as well as any associated interface using the Get-NetIPAddress cmdlet. You can either output it to a list or use the Format-Table option.
This is the main difference between the two IDEs. You will need to know cmdlets. There are more cmdlets than command statements.
PowerShell – Piping Output
PowerShell has a significant advantage over the command-line: the piping mechanism. You can pipe output to other commands.
Let’s look at the Get-Service cmdlet. This command displays the list of services currently running on a computer. This output is identical to what you would see under the Services tab in the Windows Control Panel.
To see more information about the services, you can pipe the output from this cmdlet into a secondary cmdlet. The Get-Member cmdlet is a great example.
Enter the following into PowerShell
Get-Service | Get-Member
This command outputs the Get-Service results for the Get-Member cmdlet. Notice how the output looks completely different when you type the cmdlets. It will give you the member type as well as the definition of the service.
Advanced Commands in PowerShell
You can type commands in the Windows command line and see the output. PowerShell allows you to type a command, then use advanced parameters for filtering and searching the output. This is done using the Where-Object parameter.
Let’s take as an example the Get-Process cmdlet. This command displays all processes currently running on a Windows computer. It is the same output you would see if your looked at Windows Task Manager’s list of processes.
To see the output, type Get-Process
You’ll see a long list process. A Windows server can host several dozen processes. It can be difficult to find one process if you want to search for them all. The Where-Object cmdlet parameter can be used to determine if a particular process is running.
Enter the following cmdlet in PowerShell
Get-Process | Where-Object $_.Name -eq “chrome”
This command creates a list of processes on the server, and then pipes the output to WHere Object cmdlet. This cmdlet allows you to search using boolean logic. In this example, the property named “Name” must equal (-eq), “chrome”. This will display all instances of Chrome browser on the machine.
PowerShell can automate many of your daily tasks on a Windows Server. It can also be used to automate file transfers and send analysis reports about server resources. It takes only a few minutes to understand the concept.