|

FEATURED POSTS

How to Change Outlook Password in 3 Different Ways

How to Change Outlook Password in 2 Easy Steps

Introduction Before you change your Outlook Password you have to first change it with your email provider. The reason...
spotify web player not working

Spotify Web Player Not Working [Fixed]

Introduction Spotify Web Player may stop working for you with the following error messages: "Spotify Web Player an Error...
DISM.exe /Online /Cleanup-Image /Restorehealth

DISM.exe /Online /Cleanup-Image /Restorehealth Explained

What is DISM.EXE /Online /Cleanup-image /RestoreHealth? "DISM.exe /Online /Cleanup-Image /Restorehealth" is a DISM command that repairs issue with the...
DHCP Relay agent

DHCP Relay Agent: Configuration in Windows Server 2016

What is a DHCP Relay Agent? A DHCP Relay Agent allows DHCP clients in a different network subnet to...
ForEach-Powershell

PowerShell ForEach: Syntax, Parameters, Examples

What is PowerShell ForEach? PowerShell ForEach (ForEach PowerShell) is a PowerShell construct used in iterating through values in a...

TRENDING POSTS

Remote Desktop Connection

Remote Desktop Connection an Internal Error Has Occurred [Fixed]

Introduction I recently received the error message "Remote Desktop Connection an Internal Error Has Occurred". It was strange because...

Find My Samsung: Register and Use Samsung Find my Mobile

Introduction Ever wondered how you could find your Samsung phone if you lost it? Find my Samsung or Samsung...
PowerShell vs CMD

Powershell vs CMD: Differences and Similarities Compared

Introduction This short guide compares PowerShell vs CMD (Windows command prompt). I will cover the history and nature of...
Spotify No Longer Supports this Version of Microsoft Edge

Spotify No Longer Supports this Version of Microsoft Edge [Fixed]

Introduction When you open Spotify web player on Microsoft Edge, you may receive the error message "Spotify No Longer...
Windows 10 Won't Boot

Windows 10 Won’t Boot With Black Screen? 3 Ways to Fix It

Why Won't Windows 10 Boot Up? If your Windows 10 stops with a black screen, the first question in...

BEST OF ITECHGUIDES

YouTube Music Playlist

YouTube Music Playlist: How to Create Playlists and Add Songs

Introduction A YouTube music playlist allows you to add a collection of songs or videos into a single location....
Windows Cannot Find GPEDIT.MSC or GPEDIT.MSC Not Found [Fixed]

Windows Cannot Find GPEDIT.MSC or GPEDIT.MSC Not Found [Fixed]

Introduction If you try opening gpedit.msc from Windows 10 Home you will receive the error message windows cannot find...
Dual Boot Windows 7 and 10

Dual Boot Windows 7 and 10: Step by Step Guide

Introduction Want to try Windows 10 without upgrading? One option is to dual boot windows 7 and 10. ...
How to Change Outlook Password in 3 Different Ways

How to Change Outlook Password in 2 Easy Steps

Introduction Before you change your Outlook Password you have to first change it with your email provider. The reason...

Gmail Search by Date: How to Search Gmail by Date

Introduction You can search Gmail by date for emails sent during certain time period. You could also search Gmail...

RECENT POSTS

how to merge cells in excel

How to Merge Cells in Excel in 2 Easy Ways

Introduction You can merge two Cells in Excel using CONCATENATE function or the “&” (ampersand) operator. Though Excel has...
How to Make a Pivot Table in Google Sheets

How to Make a Pivot Table in Google Sheets

Introduction You can make a Pivot Table in Google Sheets to simplify analysis of complex data. A Pivot Table...
how to make Pivot Table

How to Make a Pivot Table in Excel

Introduction A Pivot Table allows you to analyze, summarize and calculate large data to help find relationships. With a...
RAID 3 (Redundant Array of Independent Disks) Explained

RAID 3 (Redundant Array of Independent Disks) Explained

What is RAID 3? RAID 3 is a RAID implementation that uses striping with a dedicated parity disk....
RAID 5 vs RAID 6

RAID 5 vs RAID 6: Differences, Benefits and Disadvantages

What is RAID 5 vs RAID 6? RAID 5 and RAID 6 uses striping with distributed parity technique. However,...
concatenate excel

Concatenate in Excel: How to Concatenate Columns and Strings

What is Concatenate in Excel? Concatenate in Excel is joining two strings into one continuous string. You can join...

How to Add in Excel (Excel Sum) with Examples

Introduction There are different ways to add numbers in Excel. You could simply select the cells containing the data....
Excel Count

Excel Count: How to Count in Excel With Examples

Introduction Excel COUNT Function is used for counting items in a worksheet. Excel COUNT also has the conditional function,...
powershell.exe -command

Powershell.exe Command: Syntax, Parameters and Examples

Introduction You may be wondering why write on Powershell.exe Command. Are there special commands for Powershell.exe? Yes! When you...
how to move columns in excel

How to Move Columns to Rows and Rows to Columns in Excel

Introduction If you receive some Excel data in columns, you can easily move the columns to rows in Excel...

MUST READ

SysWOW64 and File System Redirector Explained

SysWOW64 and File System Redirector Explained

Introduction A Windows 64-bits OS has a SysWOW64 folder. It also has a System32 folder. These folders contain OS...

How to Add in Excel (Excel Sum) with Examples

Introduction There are different ways to add numbers in Excel. You could simply select the cells containing the data....
PortalOffice365

Portal Office 365: Your Ultimate Guide to Office 365 Admin Portal

What is PortalOffice365? PortalOffice365 (portal.office.com) is a Microsoft cloud-based portal that allows administrators to create and manage users and...

Windows 7 Safe Mode: How to Start Windows 7 in Safe Mode

Introduction If need to perform some advanced troubleshooting on Windows 7, then you may need to start Windows 7...
How to Check Windows 10 Version

How to Check Windows 10 Version in 4 Easy Ways

Introduction Wondering how you can check your version of Windows 10? Here are 4 easy ways for you -...

18 Most Useful Powershell Commands for Windows Admins

-

Introduction

This guide will cover 18 most useful powershell commands for sys admins.

PowerShell commands, usually in Verb-Noun format are Cmdlets ( “command lets”) used to automate tasks in Windows. In this tutorial I will share commands required to perform common tasks in Windows. Most Windows administrator will find this tutorial both useful and handy. Let’s do it!

In this tutorial, I will use PowerShell Commands, PS, PowerShell Cmdlets and Cmdlets interchangeably.

Most Useful Powershell Commands to Find and Get Help with Cmdlets

You cannot talk about the most useful powershell commands without learning how to find them. Below are the PowerShell commands that will help you find Cmdlets.

Get-Command

The Get-Command Cmdlet is the first and most important PS a PowerShell newbie should learn and know how to use. Why? It helps you find other PowerShell Cmdlets. What command can be more important than a command that can do this?

To find all PS Commands in your computer, simply execute this command below:

Get-Command
powershell commands

Sponsored Content


Understanding the Results of the Get-Command Cmdlet

There are four columns in the results of the Get-Command Output

  1. CommandType: This tells you whether command is an Alias, a Cmdlet, or a Function.
  2. Name: The name is the actual command you execute.
  3. Version: This is the PowerShell version
  4. Source: The module of the PS command.

With this information, you can filter the results from Get-Command. Say you want to see PowerShell commands containing the word “EventLog”, running the command below will get the job done:

Get-Command -Name *EventLog

Notice where I added the asterisks. This is because I am aware that
“EventLog” is the “Noun” part of the Cmdlets. However, if you don’t even know you could try adding the asterisks at the beginning then try the end.

Below is the result of the pervious command.

Get-Command Parameters

Lastly, before we move on, lets discuss the parameters of the Get-Command Cmdlet.

To get all the parameters and information about the Get-Command command, execute this command below:

Get-Help Get-Command -Full

This will give you all the information regarding the Get-Command Cmdlet.

I will discuss the Get-Help Cmdlet next.

Get-Help

While the Get-Command Cmdlet finds the Cmdlet you need the Get-Help PowerShell command gives you the information you need to run the command.

The easiest wat to use the Get-Help Cmdlet is to enter Get-Help followed by the command you want information on. To find more information about the Get-EventLog Cmdlet, run the command below:

Get-Help Get-EventLog

This will give you the basic information about Get-EventLog PowerShell Command. See result below:

Some Important Parameters of the Get-Help Command

Like any other PowerShell Cmdlet, the Get-Help Cmdlet has a number of parameters. Below are the most important parameters you will need.

  1. -Detailed: The Detailed parameter gives you the command SYNTAX, PARAMTERS, ALIASES, and REMARKS.
  2. -Full: The Full gives similar information provided by the Detailed parameter with more information about each parameter
  3. -Examples: Gives examples of how to use the Cmdlet. This can be very useful if you have never used the Cmdlet before and at a loss how to proceed.
  4. -Online: Opens the online help page of the Cmdlet.
To see the parameters of a PS Cmdlet, type the Cmdlet in PS, hit the space key, type hyphen “-” followed by the tab key. As you press the tab key you will scroll through available parameters.

Sponsored Content


Most Useful Powershell Commands to Manage Files and Folders

Now that you know how to find PowerShell commands, lets get you in the hood. The next set of the most useful powershell commands are Cmdlets to help you manage files and folders.

Get-ChildItem

Gets items in a specified location. To list the folders in my drive C, I will run the command below:

Get-ChildItem c:/

This will list all the top level folders. To list all files, folders include sub-folders use the –Recurse parameter.

Pro Tip
You can combine the Get-ChildItem Cmdlet let with other Cmdlet to calculate the size of each folder in a specified directory.

Copy-Item and Move-Item

You could use the Get-ChildItem Cmdlet to list items in a folder, then pipe the result to Copy-Item Cmdlet to copy the items to a new location. The command below will do the job:

Get-ChildItem C:\Dropbox | Copy-Item -Destination C:\NewFolder
The above powershell command will only copy the top level folders and files – it will NOT copy sub-folders and files. To copy all files and folders including sub-folders, include the –Recurse parameter in the Get-ChildItem command as shown below:
Get-ChildItem C:\Dropbox -Recurse | Copy-Item -Destination C:\NewFolder

While the Copy-Item Cmdlet copies items from one location to another the Move-Item Cmdlet moves the item.

Remove-Item

This Cmdlet deletes specified items. Like the Copy-Item and Move-Item Cmdlets you could pipe the output of Get-ChildItem to Remove-Item.

Use the Remove-Item Cmdlet with caution as it can delete all files and folders in your computer including Windows files!
Pro Tip
By piping the output of Get-ChildItem to Remove-Item, you could create a simple script that will delete some log files on regular bases. You could schedule the PS script to run at specified time using Windows Scheduler.

Most Useful Powershell Commands for Reporting

There are 3 sets of PowerShell commands that you can use to export items to CVS, export to text file and to HTML files. We will discuss these 3 next.

Export-Csv

Export-Csv converts a set of string into CSV and saves in a file. This Cmdlet is very important in reporting.

To demonstrate the use of Export-CSV, run the command below:

Get-Command -Verb Export

Here is the result of the command.

most useful powershell commands

You can pipe the output of the previous command into Export-CSV to create a CVS report of the results shown in the previous image.

Here is the command to accomplish this task.

Get-Command -Verb Export | Select-Object CommandType, Name, Version, Source | Export-Csv -NoTypeInformation -Path C:\NewFolder\ExportCommands.CSV

Note that I had to include the CSV file name to the path. I also have another parameter -NoTypeInformation. To learn more about -NoTypeInformation, read this article PowerShell NoTypeInformation: Applications and Uses.

There is another Cmdlet in the previous command, Select-Object. This Cmdlet was used to specify the columns to return and export to CSV. If I excluded Select-Object the output of the CSV will contain a lot of unwanted data. Later in this tutorial, I will cover Select-Object.

For your reference, below is the output of the CSV file.

powershell commands

While this report is very similar to the output shown in the previous image, it is more useful as a report. You could send the CSV file to your boss!

Out-File

The Out-file Cmdlet sends output to a text file

The command below will export the out of the Get-Command PowerShell Cmdlet to a text file instead of a CSV:

Get-Command -Verb Export | Select-Object CommandType, Name, Version, Source | Out-File C:\NewFolder\ExportCommands.txt

Here is the result in a text file: The same report, now in a text file! How good is that!

powershell commands

What if you run this report daily and do not want to over-right the content from the previous day but rather append. This command will do the job.

Get-Command -Verb Export | Select-Object CommandType, Name, Version, Source | Out-File C:\NewFolder\ExportCommands.txt -Append

Sponsored Content


Most Useful Powershell Commands to Manage Processes

Another set of set of most useful powershell commands for Windows administrators are Cmdlets to manage Windows processes. Let look at them.

Get-Process

This PowerShell Cmdlet list all the processes running on a local computer . It could also get the processes running on a remote computer – with the –ComputerName parameter.

However, when you run the Get-Process PowerShell Cmdlet without any parameter, it returns all processes running on the local computer. To try this, execute the command below. The result is shown in the image below.

Get-Process

Start-Process and Stop-Process PowerShell Commands

The Get-Process PowerShell Command can work with the Start-Process and Stop-Process PowerShell Cmdlets to start or stop a process or set of processes.

Let’s say you executed the Get-Process PowerShell command but you wish to stop a process with a specific process ID 10500, the command below will do the job.

Get-Process -Id 10500 | Stop-Process
Warning!
Use the Stop-Process PowerShell Cmdlet with caution as stopping the wrong process could make your computer unstable.

To start the process, pipe the output of the Get-Process PowerShell command to the Stop-Process PowerShell Cmdlet.

Most Useful PowerShell Commands to Manage Event logs

Event log management is one of the most important tasks for Windows Administrators. So, the next set of PowerShell commands will help you manage event logs.

Get-EventLog

The Get-EventLog PowerShell Cmdlet gets events in a specified event log. You can get events in a local or remote computer. To get events from a remote computer, use the –ComputerName parameter to specify the remote computer. However, note that you will require the right permissions to access the remote computer.

To get the last 5 events logged in the System event log, execute the command below

Get-EventLog -LogName System -Newest 5 
Pro Tip
The last command could be used for troubleshooting purposes.

Clear-EventLog

As you would expect there are more event log Cmdlets but we will cover this 2 for this tutorial.

The Clear-EventLog clears all events in the specified event log. The Cmdlet can clear event logs on both local and remote computers.

The command below clears all events with name “Windows PowerShell” from the local computer

Clear-EventLog "Windows PowerShell"
To execute the command below, you need to open PowherShell as Administrator – right-click and select Run as Administrator.

Most Useful PowerShell Commands to Get Information about your Computer

If you need to collect data about computers on your network – Computer Name, BIOS Version, RAM size, Disk Information, etc – Get-WmiObject POwerShell Cmdlet is your friend! lets explore this powerful Cmdlet, shall we.

Get-WmiObject

Get-WmiObject has a parameter called –Class this allows you to specify the WMI object you wish to access. The command below will get a list of WMI classes,
Get-WmiObject -List -Class Win32*

Once you know the name of the WMI class, you can execute Get-WmiObject to return useful information from a local or remote computer. Below is a list of the most important WMI classes you may need

  • Win32_PhysicalMemory – information about available memory
  • Win32_Processor – Processor information
  • Win32_LogicalDisk – Logical disk drive information
  • Win32_DiskDrive – Physical dis information
  • Win32_OperatingSystem – Information about the operating system

To get information about operating system, run the command below:

Get-WmiObject -Class Win32_OperatingSystem

Most Useful PowerShell Commands to Connect to Remote PowerShell Sessions

You cannot discuss PowerShell commands without talking about PS remoting. As a Windows Systems Administrator you will need to remotely connect to computers using PowerShell.

Here are the commands you will need .

Enter-PSSession and Exit-PSSession PowerShell Commands

The Enter-PSSession PowerShell command allows you to interactively start a remote PS session on a single computer. When you finish with the remote computer, end the session with the Exit-PSSession command.

To open a remote PS session with a computer called Computer1, run the command below:

Enter-PSSession Computer1

Invoke-Command

While the Enter-PSSession PowerShell Cmdlet allows you to execute commands on a single remote computer, the Invoke-Command Cmdlet allows you to execute commands on one or more remote computers.

If you wish to execute Get-Process command on Computer1, Computer2, Computer3, execute this command:

Invoke-Command -ComputerName Computer1, Computer2, Computer3, -ScriptBlock {Get-Process}

New-PSSession

The New-PSSession PowerShell Cmdlet allows you to open a persistent session with a remote computer. Because the session is persistent, it is a good idea to add the remote session in a variable.

To open a persistent remote PS session on computers Computer1, Computer2, execute the command below:

$session = New-PSSession -ComputerName Computer1, Computer2

With the PS session established and stored in the $session variable, you can execute normal PowerShell commands on the remote session using the
Invoke-Command PowerShell Cmdlet.

As a final example in remote PowerShell sessions, to execute the Get-Process on the remote computers, run the command:

Invoke-Command -Session $session {$Processes = Get-Process}
I stored the results of the Get-Process command in a variable called $Processes because there are multiple computers. Storing the result in a variable makes for easy data manipulation. You could use a ForEach loop to extract and organise the data.

References and Further Reading

  1. Export-Csv
  2. Out-file
  3. Get-ChildItem
  4. Remove-Item
  5. Copy-Item and Move-Item
  6. Get-Process
  7. Get-EventLog
  8. Clear-EventLog
  9. Get-WmiObject
  10. Running Remote Commands

Quick Links to Similar Guides

  1. Powershell NoTypeInformation: Applications and Examples
  2. Get-Command in PowerShell: Applications and Uses

Sponsored Content


YOU MAY ALSO LIKE:

LEAVE A REPLY

Please enter your comment!
Please enter your name here

By using this website you agree to accept our Privacy Policy and Terms & Conditions