PowerShell Parameters

What are PowerShell Parameters?

PowerShell parameters are input values you define for functions, scripts, or cmdlets. They allow you to pass dynamic values to your code instead of hardcoding them. Parameters make scripts reusable, flexible, and easier to maintain—especially when automating Microsoft 365 administration tasks.

nstead of writing the same logic multiple times for different inputs, you can use parameters to change only the values being processed, like user names, email addresses, or license types.


How PowerShell Parameters Operate?

Parameters are declared using the param() block inside a function or script. When the function is called, you provide the values, and PowerShell assigns them to the corresponding variables.

Basic syntax:

function FunctionName {
    param (
        [type]$Parameter1,
        [type]$Parameter2
    )
    # code that uses $Parameter1 and $Parameter2
}
  • [type] ensures that the correct data type is passed (e.g., [string], [int], [bool]).
  • Parameters can also be made mandatory or have default values using advanced parameter features.

Using parameters helps modularize your scripts and enables administrators to manage tasks like user creation, group updates, or report generation with ease.

Usage Example

Here’s a function that accepts UserPrincipalName and DisplayName as parameters to create a new Microsoft 365 user:

function Create-M365User {
param (
    [string]$UserPrincipalName,
    [string]$DisplayName
)
                                          
New-MgUser -UserPrincipalName $UserPrincipalName `
-DisplayName $DisplayName `
-MailNickname ($DisplayName -replace '\s','') `
-AccountEnabled `
-PasswordProfile @{ ForceChangePasswordNextSignIn = $true; Password = "TempP@ssw0rd!" }
                                          }
                                        

To use the function:

Create-M365User -UserPrincipalName "jane.doe@yourtenant.com" -DisplayName "Jane Doe"

✅ This dynamic approach allows you to reuse the function for any number of user accounts—ideal for bulk user provisioning via script automation.

PowerShell parameters empower administrators to write smarter, cleaner, and more flexible scripts for managing Microsoft 365.


Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.

Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.

© Your Site Name. All Rights Reserved. Design by HTML Codex