Scripting Blog

A place to learn about PowerShell and share stories of automation

PowerTip: How to use regular expressions to split a string without losing the character you split on

Summary: Cloud and Datacenter Management MVP, Thomas Rayner, shows how to split a string without losing the character you split on. I’m splitting this file name some file.txt into its name and extension by going “some file.txt” –split “.”. It’s giving me some file and txt, but I want to keep the dot and get .txt instead. How ...

PowerShell regex crash course – Part 4 of 5

Summary: Thomas Rayner, Microsoft Cloud and Datacenter Management MVP, shows the basics of working with regular expressions in PowerShell. Hello! I’m Thomas Rayner, a proud Cloud & Datacenter Management Microsoft MVP, filling in for The Scripting Guy! this week. You can find me on Twitter (@MrThomasRayner), or posting on my blog, ...

PowerTip: How to detect a valid Active Directory user name using regular expressions

Summary: Cloud and Datacenter Management MVP, Thomas Rayner, shows how use regex to detect if a string is a valid Active Directory user name. The invalid characters for an Active Directory user name are /\[:;|=,+*?<>]\ and “. How do I tell if a string is a valid Active Directory user name?   You can treat this array of ...

PowerShell regex crash course – Part 3 of 5

Summary: Thomas Rayner, Microsoft Cloud & Datacenter Management MVP, shows the basics of working with regular expressions in PowerShell. Hello! I’m Thomas Rayner, a proud Cloud & Datacenter Management Microsoft MVP, filling in for The Scripting Guy! this week. You can find me on Twitter (@MrThomasRayner), or posting on my blog, ...

PowerTip: How to detect phone numbers using regular expressions

Summary: Cloud and Datacenter Management MVP, Thomas Rayner, shows how to use regex to detect if a string is a phone number. I have an array like $phoneornot = @('780-123-4567', '780 321 6548', 'notme', 'this is 2 num'), and I need to know which array items are phone numbers. How can I do this? You can compare each item in the array with ...

Feedback usabilla icon