ps1

Changing GPO Description/Comment

GroupPolicy Module When you create a new Group Policy, you can set a comment (or description). There is no apparent way, however, to change the...

Pinging via IPv4

All PowerShell versions You can use ping.exe just like any other command inside PowerShell scripts. By adding “-4” to the command line,...

Finding Minimum and Maximum Values

All PowerShell Versions To find the smallest and largest item in a range of numbers, use Measure-Object: $list = 1,4,3,1,3,12,990 $result = $list |...

Testing UNC Paths

Test-Path can test whether or not a given file or folder exists. This works fine for paths that use a drive letter, but can fail with pure UNC...

Use $PSScriptRoot to Load Resources

Beginning in PowerShell 3.0, there is a new automatic variable available called $PSScriptRoot. This variable previously was only available within...

Converting Binary SID to String SID

Converting SID from Binary to String Active Directory accounts contain the SID in binary form. To convert the byte array into a string...

Converting Excel CSV to UTF8

When you export Microsoft Excel spreadsheets to CSV files, Excel by default saves CSV files in ANSI encoding. That's bad because special characters...

Change Order of CSV Columns

If you have a CSV file and would like to change the order of columns, simply import it into PowerShell, use Select-Object to change the order, and...

Check Windows License Status

In a previous tip we explained how you can use slmgr, a built-in VBScript, to check Windows licensing state. Accessing the Raw Licensing Data in...

Stripping Decimals Without Rounding

Extracting the Integer Part of a Division Result When you divide numbers and just want the decimals before the decimal point, you could cast the...

Removing Multiple White Spaces

Removing multiple white spaces from text is easy in PowerShell. -replace operator Simply use -replace operator and look for whitespaces ("\s") that...

Sending Emails with Special Characters

Send Emails with PowerShell Using Send-MailMessage PowerShell has built-in support for sending emails: Send-MailMessage! All you need is an SMTP...

Ignoring Empty Lines

Reading Text Files and Skipping Blank Lines To read in a text file and skip blank lines, try this: $file = 'c:\sometextfile.txt' Get-Content $file |...

Writing Registry Key Default Values

Set the default value for a registry key If you need to set the default value for a registry key, you can use either of these approaches:...

HTML-Scraping with RegEx

Scraping Website Data with PowerShell To scrape valuable information from websites with PowerShell you can download the HTML code and then use...

Case-Sensitive Hash Tables

PowerShell hash tables PowerShell hash tables are, by default, not case sensitive: PS > $hash = @{} PS > $hash.Key = 1 PS > $hash.keY = 2...

Getting Process Based On Window Title

Identifying a Process by Window Title It isn't always easy to pick the right process because the process ID or process name may not be known or...

List Hidden Files

Did you notice that Dir, ls or Get-ChildItem do not return hidden files? Use the -Force Parameter to Reveal Hidden Files To see hidden files, you...

Calling VBScript From PowerShell

Sometimes, you may have an existing VBScript that already does just what you want. You can easily incorporate any VBScript into PowerShell because...

Encrypting PowerShell Scripts

Why Hide PowerShell Script Code? Sometimes, you may want to hide the code of your PowerShell script in order to protect passwords contained within...