How do I pass multiple string parameters to a PowerShell script? How do I pass multiple string parameters to a PowerShell script? powershell powershell

How do I pass multiple string parameters to a PowerShell script?


Lose the parentheses and commas.

Calling your function as:

$s = CreateAppPoolScript "name" "user" "pass"

gives:

cscript adsutil.vbs CREATE "w3svc/AppPools/name" IIsApplicationPoolcscript adsutil.vbs SET "w3svc/AppPools/name/WamUserName" "user"cscript adsutil.vbs SET "w3svc/AppPools/name/WamUserPass" "pass"cscript adsutil.vbs SET "w3svc/AppPools/name/AppPoolIdentityType" 3


By the way, using a PowerShell here-string might make your function a little easier to read as well, since you won't need to double up all the "-marks:

function CreateAppPoolScript([string]$AppPoolName, [string]$AppPoolUser, [string]$AppPoolPass){  # Command to create an IIS application pool  return @"cscript adsutil.vbs CREATE "w3svc/AppPools/$AppPoolName" IIsApplicationPoolcscript adsutil.vbs SET "w3svc/AppPools/$AppPoolName/WamUserName" "$AppPoolUser"cscript adsutil.vbs SET "w3svc/AppPools/$AppPoolName/WamUserPass" "$AppPoolPass"cscript adsutil.vbs SET "w3svc/AppPools/$AppPoolName/AppPoolIdentityType" 3"@}


Paul's right.
In PowerShell, function parameters are not enclosed in parenthesis. (Method parameters still are.)
Your initial call was just passing one big array to the function, rather than the three separate parameters you wanted.