powershell - 单行 PowerShell 脚本

标签 powershell

我已经创建了这个基本的单行 PowerShell 脚本,如果我运行 ad 就会执行该脚本。 AD 的 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'}}"

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

最佳答案

答案是转义双引号:

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'}"

基本上,我从 SQL 运行它来更新一个无法通过 DSADD 访问的 ActiveDirectory 属性。

关于powershell - 单行 PowerShell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10391613/

相关文章:

powershell - 什么是 ShellId?为什么我需要它?

azure - 安装 powershell 模块使 Azure Functions 无法正常工作

Powershell 错误复制项无法将参数绑定(bind)到参数 'path',因为它为空

windows - Read-Host 总是以冒号结尾

powershell - 带有特殊字符的 ConvertTo-Json 和 ConvertFrom-Json

sorting - 使用自定义排序表达式进行 Powershell 排序

azure - 如何使用 PowerShell 将标签添加到现有的 azure 资源

powershell - PowerShell 中的管道输入问题

powershell - AAD 应用程序客户端 key

PowerShell - 向 while 循环添加计数器