设置广告组无法找到在同一个脚本刚刚创建组(PowerShell的) [英] Set-ADGroup cannot find group just created in same script (PowerShell)

查看:191
本文介绍了设置广告组无法找到在同一个脚本刚刚创建组(PowerShell的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个脚本来创建安全和通讯组,让他们按照我们的命名标准。在脚本中,我使用New-DistributionGroup创建组,设置DistributionGroup添加一些自定义属性,然后想用设置广告组添加说明。 (旁白:!什么是痛苦的新DistributionGroup不能做这些事),尽管设置睡眠时间长达30秒,设置广告组总是失败,:

I'm working on a script to create Security and Distribution groups so that they will follow our naming standards. In the script I use New-DistributionGroup to create the group, Set-DistributionGroup to add some Custom attributes, and then want to use Set-ADGroup to add a Description. (aside: what a pain that New-DistributionGroup can't do these things!) Despite setting sleep times up to 30 seconds, Set-ADGroup always fails with:

设置 - 广告组:找不到对象身份: AcctTesting1 的项下: [我们的域]

Set-ADGroup : Cannot find an object with identity: 'AcctTesting1' under: [our domain].

然而,如果我删除了从菜单ADGROUP code线,运行脚本,然后立即运行Set-广告组code,它完美的作品。

Yet if I remove the line of code from Set-ADGroup, run the script, and then immediately run the Set-ADGroup code, it works perfectly.

下面是脚本的相关部分:(我们的域名删除)

Here is the relevant portion of the script: (our domain name removed)

    $GroupTypeName = "Assignment"
    $OU = $BaseOU + "AssignmentGroups"
    New-DistributionGroup -Name $SAMname -Alias $Alias -DisplayName $DisplayName -ManagedBy `
        "CN=Administrator,CN=Users,[our domain]" -OrganizationalUnit $OU `
        -SamAccountName $SAMname -Type Security
    Set-DistributionGroup -Identity $SAMname -CustomAttribute10 "ASSIGNMENT GROUP" `
        -CustomAttribute11 $PRMCode
    echo "Waiting for new group to replicate"
    Start-Sleep -s 20
    Set-ADGroup -Identity $SAMname -Description "$Alias AssignmentGroup"

我是比较新的PowerShell脚本,所以如果你有关于如何解决这一问题的想法,我倒是AP preciate一个小细节!

I'm relatively new to PowerShell scripting, so if you have ideas on how to fix this, I'd appreciate a little detail!

推荐答案

我'没能测试,但这里是一个可能的解释。

I'am not able to test it but here is a possible explanation.

新DistributionGroup 是Exchange的cmdlet,创建一个通用组的。通用组上自己的全局目录域控制器创建。 设置广告组是一个Active Directory的cmdlet,试图找到一组任何域控制器上。

New-DistributionGroup is an Exchange Cmdlet that create an Universal Groups. Universal Groups are created on a Domain Controller that own the Global Catalog. Set-ADGroup is an active Directory Cmdlet that try to find a group on any Domain Controller.

所以你的问题的原因之一是,你必须要等待您的GC复制到你的参照物域控制器。你也许尝试与全局编录一个控制器上运行脚本,以测试这一点。

So one reason of your problem is that you have to wait for the replication from your GC to your referent Domain Controller. You perhaps try to run your script on a controller with the Global Catalog to test this.

这篇关于设置广告组无法找到在同一个脚本刚刚创建组(PowerShell的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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