单行 PowerShell 脚本 [英] One-liner PowerShell script

查看:55
本文介绍了单行 PowerShell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've created this basic one-liner PowerShell script which executes if I run the ad cmdlet for AD and then the rest of the query. But trying to run them together in line it only seems to load the cmdlet and doesn't execute the rest of the 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'}}"

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

Why doesn't it run all together like this?

推荐答案

答案是转义双引号:

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 属性.

Basically, I'm running this from SQL to update an ActiveDirectory attribute that isn't accessible with DSADD.

这篇关于单行 PowerShell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆