Useful PowerShell commands

As a first post we will see the basic commands that will help us get familiar with PowerShell. The commands that we will see below will help you understand better how to get information needed and perform basic tasks. These useful PowerShell commands is the beginning of a new journey of learning.

Get-Help

This command provides us with the help information of any of the below:

Commands Lets

Functions

CIMCommands

Scripts

Workflows

Aliases

The Get-Help cmdlet will provide you the information that is already included in the help files on your computer. If there is no help file on your computer for the specific request, then nothing will be shown. Note here that the help files on your computer might be outdated, therefore your will receive only the information you already have. The good thing is that you can get the help information directly from from TechNet Library by using the -Online option. It will redirect you directly on the related TechNet Library page. Below are some examples on how you can use the Get-Help command.

Get information about Windows PowerShell help system

Get-Help

Output:

Get the list of all help topics on your computer

Get-Help *

Output:

Get help information of Get-Process command from your computer

Get-Help Get-Process

Output:

Get help information of Get-Process command from TechNet Library

Get-Help Get-Process -Online

Output:

Get-Command

This cmdlet will provide you all commands that are available to you at a specific time based on the modules that are loaded at that time. The list of commands also includes functions, aliases, scripts and workflows. The list is extensive and you might find it difficult to read directly on console. By using the Out-Grid view will provide you the outcome in GUI mode and it will be easier to read. Although I will not discuss output formats in this post, I will have another post to discuss only about the way of output the results.

Get-Command

Output:

Get-Content

This cmdlet will provide you the content of a specified file that you will provide in -Path parameter. The command works similar to cat in Linux. There are also parameters that you can use to limit the content that it can be shown but we will check it at a later stage.

Get content of the file saved under C:\Scripts

Get-Content -Path C:\Scripts\testfile.txt

Output:

Get-Item

The Get-Item command will get the current items of a specified directory. Get-Item will not provide you the content of the directory unless you specify to. Even if you specify to see the items of a directory it will provide you only the items that are directly under that directory. There is another command to get all items under a directory like Get-ChildItem. We will go through that command on another post. If you use the command against a directory will provide you only the directory and the details of it. If you use it against a file, it will not provide the content of the file but only the directory of the file and the details of the file. See below some examples.

Get information for a directory

Get-Item C:\Scripts

Output:

Get information for the current directory

Get-Item .

Output:

Get information for a file

Get-Item C:\Scripts\testfile.txt

Output:

Get information about a directory and files/folders directly under the directory

Get-Item C:\Scripts\*

Output:

Get-Service

With Get-Service command, you are able to get information about services. When you will get use it, and you know the service that you are looking for, it will be much easier to do it directly from PowerShell and find the information you need, than trying to check it from GUI. Through some filtering you will be able to get only the services that you want. Let see below some examples.

Get all running and stopped services on a computer/server

Get-Service

Output:

Get services that starts with “net”

Get-Service "net*"

Output:

Get services that are currently stopped

Get-Service | Where-Object {$_.Status -eq "Stopped"}

Output:

Along with Get-Service command there are related commands that you can use when working with services. We will only mention the commands now, but we will discuss in another post only for services. Those commands are:

Set-Service

New-Service

Stop-Service

Start-Service

Resume-Service

Suspend-Service

Restart-Service

Get-Process

Similar to Get-Service, the Get-Process command will provide you information about current processes on a computer/server. Again, with filtering, you will be able to limit the results for easier troubleshooting and to get only the information you need.

Get information for all processes

Get-Process

Output:

Get information about processes that start with “win”

Get-Process "win*"

Output:

Get-NetAdapter

Get-NetAdapter will provide you basic information about virtual, hidden and physical network adapters of a computer. The main command will not provide us the hidden adapters that are in the system. In order to limit the results, we can use some filtering, so we will get the information that we need only. Below are some examples on how you can use the command.

Get all visible physical and virtual network adapters

Get-NetAdapter

Output:

Get all virtual and physical network adapters including hidden

Get-NetAdapter -IncludeHidden

Output:

Get only physical network adapters

Get-NetAdapter -Physical

Output:

Summary

The above commands are useful commands that will let you start working with PowerShell. These are not the only commands that you will use most of the times as a system administrator. These commands will help you get the information that you needs easily, they are used widely and they help you understand better what you are doing. At the end, you will explore more commands by yourself and you will see that you can do almost anything in PowerShell in an easy way. You may not use GUI again as soon as you learn how to do things with PowerShell.

I hope you like it. More will come.

Let m know your thought and comments. You feedback is really appreciated.

Related Links: