Practical PowerShell Series: Part 7


Defining dynamic parameters in advanced functions or scripts significantly enhances user experience and functionality by making these functions or scripts more intuitive and user-friendly, primarily when used interactively. For instance, with tab completion, parameters are offered – or not – based on specified conditions, guiding users toward correct usage patterns. This reduces errors and improves overall script robustness by ensuring users are directed toward the appropriate options, making the script more flexible and easier to use.

The seventh part of the Practical PowerShell series covers using dynamic parameters to enhance advanced functions or scripts, discussing both Parameter Sets and DynamicParam script block.

Click here to read the full article on Practical 365.

Practical PowerShell Series: Part 6


The practicalities of producing PowerShell output and generating logging are other essential scripting elements. No administrator likes to stare at a blank screen, wondering if the command just entered is functioning or not. Also, when performing bulk operations against multiple objects, it could be wise to register the success or failure of this operation in a manner that is useful for reporting. Depending on your use case, it can also be beneficial to log these failures so that they can easily be re-used for consecutive retries after remediation of the cause.

The sixth part of the Practical PowerShell series covers these topics, talking about output streams and logging.

Click here to read the full article on Practical 365.

Practical PowerShell Series: Part 5


Writing PowerShell scripts can be a fulfilling task. After all, you write something to assist with a task or procedure so you can focus on the result, not the task itself. But what if your script tries to run an action and is unsuccessful, for example, when a user the script attempts to manipulate is invalid or the signed-in account has insufficient permissions to run a cmdlet? And do not forget the peculiarities of the online world, such as a network connection dropping or an authentication token expiring.

This is where one of the often-undervalued aspects of writing resilient and “a less optimistic version” of scripts comes into the picture: exception handling, the topic of the fifth part in the Practical PowerShell series.

Click here to read the full article on Practical 365.

Practical PowerShell Series: Part 4


In the previous article on changing the flow of PowerShell code, I wrote on looping in PowerShell, providing scenarios for when to use what. In the fourth article in the Practical PowerShell series, I talk about code branching.

Topics discussed are the If-Then-Else, Switch (albeit briefly as its use cases are extensive), and stop cmdlets such as break-continue-return-exit. On the side, I will also touch briefly on unary operators.

Click here to read the full article on Practical 365.

Practical PowerShell Series: Part 3


When working with PowerShell and objects such as User in Entra ID or mailboxes in Exchange Online, you might quickly run into scenarios where you might want to repeat a set of instructions for multiple objects. This can happen for example, when configuring mailbox properties for multiple mailboxes. This construct of flow control is called looping.

In the third installment of the Practical PowerShell series, I discuss which types of looping are available in PowerShell and what their typical application is. Topics discussed are For loops, ForEach-Object vs ForEach, and While/Do-While and Do-Until. On the side, I will also touch briefly on casting, the format operator, and running code in parallel using ForEach-Object.

Click here to read the full article on Practical 365.