Quick and Easy Password Generator
This is a quick and easy password/random character generator. It returns random numbers between 33 and 126 and converts the number to the corresponding ASCII character. $password = [string]::Empty 1..32 | ForEach-Object { $password += [char]$(33..126 | Get-Random) }
Parse Email Address
You can use this snippet to parse an email address and extract the different components of it. (Tip. It works for UPNs too) New-Object "System.Net.Mail.MailAddress" -ArgumentList $emailAddress
Properly Capitalize a Title Using PowerShell
Being married to someone who majored in English has made me extra conscious of my spelling and capitalization. So, for my blog posts, I’ve written a script to help me ensure my titles are properly capitalized. It is not perfect (i.e. it doesn’t do a dictionary lookup), but it follows the basic APA guidelines. I thought I would share it,...
Find Specific Word in String
[Regex]::Matches($string, '(?:^|\b)words(?:$|\b)')
Find Date in MM/DD/YYYY Pattern in String
[Regex]::Matches($string, '(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(29|30)|(0?[13578]|1[02])/31)/(19|[2-9]\d)\d{2}|0?2/29/((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))').Value
Find US Phone Number in String
[Regex]::Matches($string, '((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}').Value
Find IPv6 Address in String
[Regex]::Matches($string, '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))').Value
Find IPv4 Address in String
[Regex]::Matches($string, '(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)').Value
Find URL in String
[Regex]::Matches($string, '((https?|ftp|file):\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-](.*?)(?=\s))').Value