• Skip to primary navigation
  • Skip to main content
  • Skip to footer

Stephanos Constantinou Blog

PowerShell Scripting

  • Home
  • Blogs
    • PowerShell Tutorials
    • PowerShell Scripts
    • PowerShell Modules
      • Modules Cmdlets
    • Software Reviews
  • About
  • Contact
You are here: Home / PowerShell Tutorials / Useful PowerShell commands

Useful PowerShell commands

05/04/2018 by Stephanos 2 Comments

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-help

Get the list of all help topics on your computer

Get-Help *

Output:

get-help-asterisk

Get help information of Get-Process command from your computer

Get-Help Get-Process

Output:

get-help-get-process

Get help information of Get-Process command from TechNet Library

Get-Help Get-Process -Online

Output:

get-help-get-process-online

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-command

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:

text-file-content
get-content

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-item-directory

Get information for the current directory

Get-Item .

Output:

get-item-current-directory

Get information for a file

Get-Item C:\Scripts\testfile.txt

Output:

get-item-file

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

Get-Item C:\Scripts\*

Output:

get-item-directory-files

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-service

Get services that starts with “net”

Get-Service "net*"

Output:

get-service-net

Get services that are currently stopped

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

Output:

get-service-stopped

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-process-all

Get information about processes that start with “win”

Get-Process "win*"

Output:

Useful PowerShell commands - get-process-win

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:

Useful PowerShell commands - get-netadapter

Get all virtual and physical network adapters including hidden

Get-NetAdapter -IncludeHidden

Output:

Useful PowerShell commands - get-netadapter-includehidden

Get only physical network adapters

Get-NetAdapter -Physical

Output:

Useful PowerShell commands - get-netadapter-physical

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:

  • PowerShell Tutorials
  • Get-Help – Microsoft Docs
  • Get-Command – Microsoft Docs
  • Get-Content – Microsoft Docs
  • Get-Item – Microsoft Docs
  • Get-Service – Microsoft Docs
  • Get-Process – Microsoft Docs
  • Get-NetAdapter – Microsoft Docs
Summary
Useful PowerShell commands
Article Name
Useful PowerShell commands
Description
Useful PowerShell commands. In this tutorial we will see the first commands that we need to know when we start working with PowerShell that will help us go through the process of learning. Stephanos Constantinou Blog - PowerShell Scripting
Author
Stephanos
Publisher Name
Stephanos Constantinou Blog
Publisher Logo
Stephanos Constantinou Blog

Filed Under: PowerShell Tutorials Tagged With: Get-Command, Get-Content, Get-Help, Get-Item, Get-NetAdapter, Get-Process

Reader Interactions

Trackbacks

  1. Useful PowerShell Commands - How to Code .NET says:
    05/04/2018 at 16:09

    […] on April 4, 2018by admin submitted by /u/SConstantinou [link] [comments] No comments […]

    Reply
  2. PowerShell Comments - Stephanos Constantinou says:
    10/04/2018 at 16:37

    […] Useful PowerShell commands […]

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Footer

Recent Posts

  • ICS Cube Product Review 26/04/2019
  • PowerShell Module SysInfo v1.2.0 15/03/2019
  • PowerShell Module SysInfo v1.1.2 13/11/2018
  • PowerShell Module SysInfo 24/10/2018
  • Get-VoltageProbe 24/10/2018
  • Get-VideoController 24/10/2018
  • Get-USBController 24/10/2018
  • Get-TrackPoint 24/10/2018
  • Get-TrackBall 24/10/2018
  • Get-TouchScreen 24/10/2018
Planet PowerShell

Categories

  • Modules Cmdlets (57)
  • PowerShell Modules (5)
  • PowerShell Scripts (38)
  • PowerShell Tutorials (35)
  • Software Reviews (2)

Archives

  • April 2019 (1)
  • March 2019 (1)
  • November 2018 (1)
  • October 2018 (56)
  • September 2018 (13)
  • August 2018 (9)
  • July 2018 (6)
  • June 2018 (8)
  • May 2018 (7)
  • April 2018 (9)
  • March 2018 (4)
  • February 2018 (6)
  • January 2018 (12)
  • December 2017 (4)
Top 10 PowerShell 2018

Blogroll

  • Planet PowerShell
  • Reddit – PowerShell
  • PowerShell Magazine
  • PowerShell.org
  • PowerShell Team Blog
  • Hey, Scripting Guy! Blog
  • Mike F Robbins
  • PowerShell Explained with Kevin Marquette
  • Mike Kanakos – Network Admin
  • The Lonely Administrator
  • AskME4Tech
PowerShell Blogs Sysadmin Blogs Banners for Top 20 Programming Blogs

© 2023 · Stephanos Constantinou Blog

  • Home
  • Blogs
  • About
  • Contact