# Useful PowerShell commands

Hello. Today I would like to share with you guys some useful PowerShell commands. These are more complex. Why PowerShell? Because it’s easy and much faster than some GUI operations. I will keep this post up to date, so if I will use something new and cool I add it here.

If you want to know more about PowerShell check official PowerShell website, PowerShell Github repo and awesome PowerShell Survival Guide.

## Count folder size

Sometimes checking size of folder in Explorer can take ages, especially when there is a lot of small files. Don’t wait! Just use open PowerShell, provide location you want to check and use command:

To see results in GB:

## Mass extension change

If you want to change extension for many files in folder use this:

In this example all files with tiff extension will be changed to tif.

## Display specified number of lines

To get the first 10 lines:

To get the last 10 lines:

## Run Active Directory as different user

Use runas command to run application or other command as different user

In this case Active Directory Users and Computers snap-in. Provide your user name and domain.

## Search in file content

Linux Grep alternative.

or

## Network statistics

Some useful commands to gather network statistics

TCP stats:

PowerShell offers the ability to run commands encoded as base64. To do this, you must encode the contents of the file and pass the resulting string to the -EncodedCommand switch of PowerShell.