Ok, this is not new or rocketsurgery, but it’s handy.

You can Google right out of the cmdline :¬) Just add this to your PowerShell profile

function google{
    if(-not($args.count -eq 0)){
        $searchstring = $args -join " " 
        $url = "https://www.google.com/search?q=$searchstring"
        $url = $url -replace "\s", "%20"
        Start-Process $Url
    }
}

While I’m just a ‘young padawan’ in the great world of regex, I really enjoy its power and like using it. I mainly use it for quick fixes and string manipulation. Here are some handy snippets I use:

  1. Have a long sausage of code seperated by semi-colon (;), try this:
Find: ;
Replace: $&\n

It will put each statement ending with ‘;’ in a new line and you can actually read the scipt now

Before:
coffee;coffee;coffee;

After:
coffee;
coffee;
coffee;
  1. Have a list and need to wrap it in quotes (“ “)? Easy.
Find: (.+)
Replace: "$1" # or '$1' if you need single quotes

It’ll basically wrap your strings with whatever you specify

Before:
coffee
coffee
coffee

After:
"coffee"
"coffee"
"coffee"
  1. Now let’s say you need those joint by comma in a line again
Find: \n
Replace: , # or whatever you need it to be separated with

It will join the lines back into one line separated by comma

Before:
"coffee"
"coffee"
"coffee"

After:
"coffee","coffee","coffee"
  1. How about them pesky blank lines? I gatchu fam
Find: ^(?:[\t ]*(?:\r?\n|\r))+
Replace: <blank>

Now stick with me, that’s where regex shows its true power and its crazy complexity Let’s look at the results.

Before:
"coffee"

"coffee"

"coffee"

After:
"coffee"
"coffee"
"coffee"

It does not look like much but if you have a larger script with hundrets of random blank lines in the code, it bothers me, this will fix it.

RegEx is stupid powerful, but with great power comes great resposibility.

Yes it’s complex and quite a beast to master but totally worth it and a great ROI I barely scratched the surface of what all Regular Expressions can do, but I love using it for small quick fixes as I just posted about. They used to take quite a lot of time, cleaning lists and stuff up before you can use them. I now I can spend more time on the actual code, rather than cleaning ‘dirty’ input up!

dotnet regular expression quick reference


It’s so sad, true and funny!

YT - Let's deply in production


We all know VSCode is super powerful and going forwward the new standard for PowerShell (and other things) development as it’s light weight, open source and works across pretty much all platforms.

The base feature set is already amazing, but there are extensions that make VS Code even more powerful. I’m going to list here a few of the extensions I use

You can easily see what you have installed by either

  • In VSCode go to the Extension Tab and enter @installed
  • or run code --list-extensions
  1. ms-vscode.powershell or just PowerShell
    This is the official Microsoft PowerShell extensions, that enable VS Code to do all sorts PowerShell
  2. CoenraadS.bracket-pair-colorizer or just Bracket Pair Colorizer
    As the name implies, it colorizes brackets and thus makes it easier tofind the corresponding open / closed / missing bracket
  3. DavidAnson.vscode-markdownlint or just markdownlint
    I write a lot of documentation and readme files in MarkDown, so this liter is super helpful in writing MarkDown. Also the build in MarkDown preview in VS Code helps seeing issues quickly with the formatting, or the lack there of.
  4. yzane.markdown-pdf or just Markdown PDF
    This goes along with the MarkDown documentation and creates a pretty PDF out of your MarkDown file. Pretty handy!
  5. eamodio.gitlens or just GitLens - Git supercharged
    This fantastic extension add a bunch of Git support and capability, very handy if you work a lot with Git.
  6. johnpapa.vscode-peacock or just Peacock
    Ever accidentally entered the wrong Workspace, let’s say PROD instead of Dev? With Peacock you can assign a color to your Workspaces (e.g. red for PROD and green for DEV), so you’ll notice immediately that you are in the wrong workspace.
  7. Shan.code-settings-sync or just Settings Sync
    Settings Sync creates a GIST that syncs your settings.json file. So if you run VS Code on multiple machines, your settings can always stay the same.

Image of Sysadminday