单线程PowerShell脚本

IT *_*ent 5 powershell

我已经创建了这个基本的单行PowerShell脚本,如果我运行adAD 的cmdlet,然后运行查询的其余部分,则会执行该脚本.但是尝试在一起运行它们似乎只加载cmdlet并且不执行其余的cmd.

powershell.exe -command "&{Import-Module ActiveDirectory; Get-AdGroup -Server DC.Mydomain.com -filter 'name -eq "xxxx"'| set-Adgroup -Replace @{wWWHomePage='10.24.218.194'}}"
Run Code Online (Sandbox Code Playgroud)

为什么它不像这样一起运行?

IT *_*ent 7

答案是逃避双引号:

powershell.exe -noprofile -command "&Import-Module ActiveDirectory; Get-AdGroup -Server server.mydomain.com -filter 'name -eq *\"xxxx\"*'| set-Adgroup -Replace @{wWWHomePage='10.10.10.10'}"
Run Code Online (Sandbox Code Playgroud)

基本上,我是从SQL运行它来更新DSADD无法访问的ActiveDirectory属性.


Joe*_*oey 0

如果对复杂命令有疑问,您可以尝试使用 Base64 对其进行编码并使用-EncodedCommand. 请powershell /?参阅示例。

当您直接在 PowerShell 中输入该行时,该行是否按预期工作?