我正在编写一个PowerShell脚本来创建一个新的Active Directory组,并根据用户所在的部门自动将其放入正确的OU中。 Active Directory中的用户,然后需要将其用作活动目录中OU的名称。当我不使用AD路径中的变量时,此脚本可以工作。Active Directory路径中的字符串变量不起作用
[string]$department = Get-ADUser -identity johndoe -properties department | Select department
New-ADGroup -Name NewADGroup -GroupScope Global -path “OU=($department),OU=SubDepartment,OU=MainDepartment,DC=OrgName”
然而,当我尝试使用变量$部门如上,我得到以下错误:
New-ADGroup : The object name has bad syntax
At C:\Users\JohnDoe\Desktop\CreateNewGroup.ps1:7 char:1
+ New-ADGroup -Name NewADGroup -GroupScope Global -path
"OU=($department ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CN=NewADGroup,DC=OrgName
:String) [New-ADGroup], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8335,Microsoft.ActiveDirec
tory.Management.Commands.NewADGroup
我怎么能叫的Active Directory路径内部变量?
''($ department)'应该是'$($ department)'或者只是'$ department' –