Q. How can I modify a script to accept a parameter?

A. Enabling a script to accept a parameter requires only a single line to added to script:

                              Param([Parameter(ValuefromPipeline=$true,Mandatory=$true)][string]$user)

In this example the value passed to the script is stored in variable $user and must be passed and can also be passed along the pipeline. Below is an example use:

                              
Param([Parameter(ValuefromPipeline=$true,Mandatory=$true)][string]$user)
$AdObj = New-Object System.Security.Principal.NTAccount($user)
$strSID = $AdObj.Translate([System.Security.Principal.SecurityIdentifier])
$strSID.Value

Once saved as FindADUserSID.ps1 it can be used in a number of ways:

                              
PS C:\Users\Administrator\Documents> 'john@savilltech.net' | .\FindADUserSID.ps1
S-1-5-21-218700803-3075295566-3609972863-1109

PS C:\Users\Administrator\Documents> .\FindADUserSID.ps1 honeypot@savilltech.net
S-1-5-21-218700803-3075295566-3609972863-3228

PS C:\Users\Administrator\Documents> .\FindADUserSID.ps1
cmdlet FindADUserSID.ps1 at command pipeline position 1
Supply values for the following parameters:
user: john@savilltech.net
S-1-5-21-218700803-3075295566-3609972863-1109