PowerShell - 如何使用 && 类型语句
PowerShell - How to use && type statement
使用下面的命令,我能够获取组策略设置的值:
secedit.exe /export /cfg C:\test\secedit.txt && type C:\test\secedit.txt | findstr "SeEnableDelegationPrivilege"
我需要能够在 PowerShell 上使用相同的命令,但我在将 && 语句转换为在 PowerShell 上工作时遇到了问题。我尝试使用这种格式 () -and (),但是没有用,有谁知道让 && 语句在 PS 上工作的方法吗?
如果您想在 PowerShell 中模拟该命令的作用,只需将 &&
更改为 ;
:
secedit.exe /export /cfg C:\test\secedit.txt; type C:\test\secedit.txt | findstr "SeEnableDelegationPrivilege"
我会在第一个命令后添加1>$null
以避免输出The task has completed successfully.....
编辑
我理解 ;
和 &&
或 ||
在 PS 5.1 及以下版本中不是同一回事,但这是我能想象到的最接近的东西OP在做。
他可以尝试的另一件事是:
secedit.exe /export /cfg C:\test\secedit.txt;if($?){type C:\test\secedit.txt | findstr "SeEnableDelegationPrivilege"}
我会 link this helpful answer 这比我解释得更好。
使用下面的命令,我能够获取组策略设置的值:
secedit.exe /export /cfg C:\test\secedit.txt && type C:\test\secedit.txt | findstr "SeEnableDelegationPrivilege"
我需要能够在 PowerShell 上使用相同的命令,但我在将 && 语句转换为在 PowerShell 上工作时遇到了问题。我尝试使用这种格式 () -and (),但是没有用,有谁知道让 && 语句在 PS 上工作的方法吗?
如果您想在 PowerShell 中模拟该命令的作用,只需将 &&
更改为 ;
:
secedit.exe /export /cfg C:\test\secedit.txt; type C:\test\secedit.txt | findstr "SeEnableDelegationPrivilege"
我会在第一个命令后添加1>$null
以避免输出The task has completed successfully.....
编辑
我理解 ;
和 &&
或 ||
在 PS 5.1 及以下版本中不是同一回事,但这是我能想象到的最接近的东西OP在做。
他可以尝试的另一件事是:
secedit.exe /export /cfg C:\test\secedit.txt;if($?){type C:\test\secedit.txt | findstr "SeEnableDelegationPrivilege"}
我会 link this helpful answer 这比我解释得更好。