[英]Directory object not found error in Get-ADGroupMember
I am new in PowerShell scripting.我是 PowerShell 脚本的新手。 I am writing a script to add users in different AD Groups.
我正在编写一个脚本来在不同的 AD 组中添加用户。 While doing so I do the following:
这样做时,我会执行以下操作:
Check if the user already exist in the group:检查用户是否已存在于组中:
$mbr_exist = Get-ADGroupMember $grpname | Where-Object {$_.SamAccountName -eq $sam}
If user does not exist, then add the user to the group.如果用户不存在,则将该用户添加到组中。
When I manually run the script it runs flawless without any errors.当我手动运行脚本时,它运行完美,没有任何错误。 But when I schedule the script to run it gives an error as follows:
但是当我安排脚本运行时,它会出现如下错误:
3/30/2015 8:32:15 AM **Directory object not foundAt**
+ $mbr_exist = Get-ADGroupMember $grpname | Where-Object {$_.SamAc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
Error at Line:$mbr_exist = Get-ADGroupMember $grpname | Where-Object {$_.SamAccountName -eq $sam}
The strange thing is the user for which it throws the error is present in the group.奇怪的是它抛出错误的用户存在于组中。 I am not sure why this error is occurring when scheduled.
我不确定为什么在预定时会发生此错误。
$grpname is defined as $grpname += "Group1"
' it's a array of strings (No Blanks spaces). $grpname 定义为
$grpname += "Group1"
' 它是一个字符串数组(无空格)。 Added a for loop to access one group at a time.添加了一个 for 循环以一次访问一个组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.