Pass Parameters to a PowerShell Script

This PowerShell blog post will show how to pass parameters to a PowerShell scripts.

Using parameters with PowerShell scripts allow us to make scripts more efficient and more reusable.

Parameters also allow us to use PowerShell with complex workflows as part of a batch processing systems.

In the following example I have a simple script that takes an Azure tenantID as a parameter.

param (
[string]$tenantId
)

write-host “TenantId is:” $tenantId
# Convert subscription name to ID
$tenantId = (Get-Azsubscription -SubscriptionName $tenantId).SubscriptionId

The scripts takes the tenatID and converts it to a tenant name.

Pass Parameter

Since my script takes a single parameter I will use the following command to pass the script a single parameter.

Scriptname.ps1 -tenantid “name of tenant”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.