我想做一些字符串連接/格式化,但它將所有參數放入第一個佔位符。如何將多個字符串參數傳遞給PowerShell腳本?
代碼
function CreateAppPoolScript([string]$AppPoolName, [string]$AppPoolUser, [string]$AppPoolPass)
{
# Command to create an IIS application pool
$AppPoolScript = "cscript adsutil.vbs CREATE ""w3svc/AppPools/$AppPoolName"" IIsApplicationPool`n"
$AppPoolScript += "cscript adsutil.vbs SET ""w3svc/AppPools/$AppPoolName/WamUserName"" ""$AppPoolUser""`n"
$AppPoolScript += "cscript adsutil.vbs SET ""w3svc/AppPools/$AppPoolName/WamUserPass"" ""$AppPoolPass""`n"
$AppPoolScript += "cscript adsutil.vbs SET ""w3svc/AppPools/$AppPoolName/AppPoolIdentityType"" 3"
return $AppPoolScript
}
$s = CreateAppPoolScript("name", "user", "pass")
write-host $s
輸出
cscript adsutil.vbs CREATE "w3svc/AppPools/name user pass" IIsApplicationPool
cscript adsutil.vbs SET "w3svc/AppPools/name user pass/WamUserName" ""
cscript adsutil.vbs SET "w3svc/AppPools/name user pass/WamUserPass" ""
cscript adsutil.vbs SET "w3svc/AppPools/name user pass/AppPoolIdentityType" 3
這是,巧合的是,相當數量的編程語言如何工作(O'Caml,Haskell)。 – yfeldblum 2009-06-05 00:36:06