在if语句中运行多个命令

时间:2016-11-18 00:15:15

标签: powershell

我希望修改以下脚本,在if语句中执行两项操作:

if ($PsCmdlet.ParameterSetName -ieq "DumpCreds")
{
    $ExeArgs = "privilege::debug"

}
elseif ($PsCmdlet.ParameterSetName -ieq "DumpCerts")
{
    $ExeArgs = "crypto::cng crypto::capi `"crypto::certificates /export`" `"crypto::certificates /export /systemstore:CERT_SYSTEM_STORE_LOCAL_MACHINE`" exit"
}
else
{
    $ExeArgs = $Command
}`

它读取的行 - $exeargs = "privilege::debug",我需要运行它,我还需要运行 - $ExeArgs = "sekurlsa::logonpasswords"首先需要运行的权限,然后是logonpasswords运行权限。

如何在脚本中的1 if语句中运行2个命令?

1 个答案:

答案 0 :(得分:2)

if语句对你在其中执行的命令没有限制,所以只需执行它......

if ($PsCmdlet.ParameterSetName -ieq "DumpCreds")
{
    $ExeArgs = "privilege::debug"
    $ExeArgs = "sekurlsa::logonpasswords"    
}
elseif ($PsCmdlet.ParameterSetName -ieq "DumpCerts")
{
    $ExeArgs = "crypto::cng crypto::capi `"crypto::certificates /export`" `"crypto::certificates /export /systemstore:CERT_SYSTEM_STORE_LOCAL_MACHINE`" exit"
}
else
{
    $ExeArgs = $Command
}
相关问题