我有以下命令在PowerShell脚本中添加AD组,但是AD组的名称中有空格,这会引起问题。
root@n3:/tmp/pycore.50484/n3.conf# /home/osboxes/batctl-2018.0/batctl o
[B.A.T.M.A.N. adv 2017.1, MainIF/MAC: eth0/00:00:00:aa:00:00 (bat0/d6:d7:b9:d6:5c:c3 BATMAN_IV)]
Originator last-seen (#/255) Nexthop [outgoingIF]
* 00:00:00:aa:00:05 0.144s (198) 00:00:00:aa:00:01 [ eth0]
* 00:00:00:aa:00:01 0.140s (255) 00:00:00:aa:00:01 [ eth0]
* 00:00:00:aa:00:03 0.476s (221) 00:00:00:aa:00:01 [ eth0]
错误:CategoryInfo:未指定:RemoteException
+ FullyQualifiedErrorId:NativeCommandError
答案 0 :(得分:2)
用单引号将它引起来,因为它是一个没有其他任何事情的纯字符串,并在第二行中用双引号引起来(双引号是因为其中有一个变量名,PowerShell需要对其进行扩展) :
Set-Variable -Name APP_GROUP -Value 'My AD Group'
Add-LocalGroupMember -Group "Administrators" -Member "MyDomain\$APP_GROUP"
看它写起来会更典型:
$APP_GROUP = 'My AD Group'
Add-LocalGroupMember -Group "Administrators" -Member "MyDomain\$APP_GROUP"