本文介绍了使用Powershell添加Active Directory组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Powershell在DomainLocal中创建一个新组,但是下面的代码无法正常工作。我没有收到错误,但是也没有在给定的路径中创建组。

I'm trying to create a new group in the DomainLocal with Powershell but my code below is not working. I don't get an error, but nor does it create the group in the path given.

Function AD{
Param (
        [Parameter (Mandatory=$true)] [STRING] $ProjectCode

        )

 #setting up Folder template path and name for folders
 $ProjectName = "$($ProjectCode)"

 $Folder = "C:\FunctionOutputs\ProjectFolders"
 $ProjectFolder = " $Folder\$($ProjectName)"


 #establishing AD group and member naming conventions
 $adminName = "AB_"+$ProjectName+"_CDE_ADMIN_LCL"
 $adminName

  #check that new $ProjectFolder exists to create "_ADMIN_LCL" group
 if(Test-Path -Path $ProjectFolder){

      New-ADGroup -Name $adminName  -GroupScope DomainLocal -DisplayName $adminName -Path "OU=Groups, OU=Test, OU=Ohio, OU=NA, DC=aws, DC=example, DC=com" -Verbose
      }
}


推荐答案

如果您根本没有输出任何内容,则可能意味着

If you're getting no output at all, that likely means that

Test-Path -Path $ProjectFolder

返回 False 。也就是说,项目目录不存在,因此它甚至都不会尝试创建组。如果您使用的是以前没有为其创建目录的新项目名称来调用它,则应该这样做,因为您没有在此代码中创建该文件夹。

is returning False. That is, the project directory doesn't exist, so it doesn't even try to create the group. If you are calling this with a new project name that you have not previously created a directory for, then that's expected, since you're not creating the folder in this code.

如果要创建目录,可以使用:

If you would like to create the directory, you can use:

New-Item $ProjectFolder -ItemType Directory

此外,这也是可疑的:

-Path "OU=Groups, OU=Test, OU=Ohio, OU=NA, DC=aws, DC=example, DC=com"

AD中的专有名称在逗号后没有空格。照原样,这将引发异常。

Distinguished names in AD don't have spaces after the commas. As-is, that would throw an exception.

这篇关于使用Powershell添加Active Directory组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 11:14