Skip to main content
< All Topics

Handy Powershell snippits

Short and Handy to know

Aliassen and special characters

  • % alias foreach
  • ? alias where-object
  • @ hashtable
  • gsv alias Get-Service

Alias to see them all

Hashtables and Herestring (String literal)

Powershell: Everything you wanted to know about arrays (powershellexplained.com)

Search in a List

For example, consider this $list:

UserPrincipalNameDisplayName
a.jansen@domein.comArjen Jansen
p.pietersen@domein.comPeter Pietersen

If you want to check whether a particular UPN exists in this list, and if so, determine its position
(row number), you can do the following:

$idx = $List.UserPrincipalName.IndexOf("p.pietersen@domein.com")

The variable $idx will contain either -1, which means the UPN was not found, or the row position (starting at 0). If you want to retrieve all the data for that row, you can use $idx like this:

$RowData = $List[$idx]

To display the UserPrincipalName of that row, use:

Write-host $RowData.UserPrincipalName

This will output p.pietersen@domein.com.

Hashtable / Name / Value pair

$params = @{“VMName”=”WSVMClassic”;”resourceGroupeName”=”WSVMClassicSG”}

$params.resourceGroupeName
$params.Keys
$params.Values

Testing for empty string or null value

Hashtables and Herestring (String literal)

Hashtable

Documentation

Herstring

Documentation

Function example

Working With data in Powershell

Pluralsight Working with Data in Powershell

Introduction · Chart.js documentation (chartjs.org)

Export-csv

Best powershell websites

PowerShell Explained

Was this article helpful?
0 out of 5 stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
5
Please Share Your Feedback
How Can We Improve This Article?
Table of Contents