Categories
PowerShell Reference

Learning PowerShell

Getting started with PowerShell

Main

Grammar

Important Topics, Language quirks

For( ;; ) vs ForEach vs ForEach-Object

It’s first argument is a ScriptBlock so it appears like a control loop.

Notice return verses break in ForEach-Object . Remember that the { ... stuff ... } in this case is an anonymous function , not a language control statement
It is a parameter to the ForEach-Object . When not specified, it’s the -Process Parameter

Flow Control with language Keywords

Attributes for validation

Best Practices

Naming

Categories
PowerShell Quick Tips Regex

Using Case-Sensitive Regular expressions in PowerShell – Tips

Say you want to find functions that uses parameters named like:
-AsString, -AsHashTable, or -AsByteStream

Using Find-Member makes it easy.

> Find-Member -Name 'As*'

That’s close, but I want it to start with a capital letter, to skip matches like:
Assembly or Asin

Converting Like to a Regex

The -like pattern As* is the same as the regex ^As
To start with a capital letter you could use: ^As[A-Z]

Disabling Case-Sensitive matches

Because PowerShell defaults to case-insensitive matches
You need to remove the i insensitive flag using the syntax (?-i)

Solution

> Find-Member -Name '(?-i)^As[A-Z]' -RegularExpression

The final pattern is (?-i)^As[A-Z]
Making it case-sensitive narrowed down the matches from 113 to 43 !

See More

Categories
Uncategorized

Protected: Syntax Test

This content is password protected. To view it please enter your password below: