gpt4 book ai didi

string - 如何将多个字符串参数传递给 PowerShell 脚本?

转载 作者:行者123 更新时间:2023-12-03 07:57:30 30 4
gpt4 key购买 nike

我正在尝试进行一些字符串连接/格式化,但它将所有参数放入第一个占位符。

代码

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

最佳答案

去掉括号和逗号。

将您的函数称为:

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

给出:

cscript adsutil.vbs CREATE "w3svc/AppPools/name" IIsApplicationPool
cscript 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

关于string - 如何将多个字符串参数传递给 PowerShell 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22732/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com