Scripting Blog [archived]

Formerly known as the "Hey, Scripting Guy!" blog

PowerTip: Capture error code of a PowerShell session in Linux or macOS

Summary: Capture the status code of a PowerShell session in Linux or macOS. (image) Could you show me how to run a PowerShell script in Linux or macOS and capture the status of whether that script succeeded or failed? (image) No problem, my friend. Just run the PowerShell session, and start the script as in the following example. You can ...

PowerTip: Know the difference between the .split() method and ‘-split’

Summary: Cloud and Datacenter Management MVP, Thomas Rayner, shows how to split a string by using a string instead of just a character. (image) I am trying to split the string “this is my amazing string” on the pattern “my” by using “this is my amazing string”.split(“my”) but it’s giving me a bunch of garbled stuff back. ...

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. (image) 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...