vbscript - 如何使用 VBScript 从 Active Directory 中获取部门信息?
问题描述
我不是任何类型的脚本编写者,只是试图获取一些域信息的网络专家。
我有一个包含多个 OU、多个安全组的域。我正在尝试根据他们是域中特定安全组的成员来填充 AD 中用户帐户的“部门:”字段(在“组织”选项卡下)。
我正在使用的代码在这里:
{
On Error Resume Next
Set objGroup = GetObject _
("LDAP://CN=LiveTimeCustomers,OU=Service Accounts,DC=domain,DC=com", group)
' WScript.Echo objGroup.Name
For Each objMember In objGroup.Members
' WScript.Echo vbCrlf & " Name: " & objMember.Name
arrGroups = objMember.GetEx("memberOf")
If (Err.Number = 0) Then
On Error GoTo 0
strGroups = LCase(Join(arrGroups))
' Update Department attribute for COMMUNITY SECTION members
If InStr(strGroups, "cn=community section,ou=community,ou=organisation,dc=domain,dc=com") Then
' WScript.Echo vbCrlf & " Name: " & objMember.Name & " is member of COMMUNITY SECTION"
Set objUser = GetObject(objMember.ADsPath)
objUser.department = "COMMUNITY SECTION"
objUser.SetInfo
End If
}
我在运行时遇到的错误是:
行:23 字符:5 在缓存中找不到目录属性。行和字符指的是这个:arrGroups = objMember.GetEx("memberOf")
解决方案
答案是不要在 vbscript 中执行此操作!无论如何感谢您的帮助。在建议将此脚本更新为 Powershell 后,我就这样做了。我需要运行一个“启动”脚本以管理员身份运行 PS,并调用我想要编辑 AD 的脚本。
启动脚本:
Start-Process powershell '-NoProfile -File \\domain.com\SYSVOL\domain.com\scripts\SetDepartmentAttribute.ps1' -verb RunAs
活动目录代码:
`Import-Module ActiveDirectory
Get-ADGroupMember -Identity "COMMUNITY"| Set-ADUser -Replace @{Department="COMMUNITY"}`
所有这一切都提供了您在 DC 上的执行策略允许运行脚本 - 检查一下。
推荐阅读
- javascript - 如何正确地将 useReducer 操作传递给子级而不导致不必要的渲染
- python - 关系“analysis_result”的“e”列不存在
- python - Python Instabot 错误 - 照片没有兼容的照片纵横比
- c# - 创建一个由不同形状的数组组成的数组
- c - 未能将内存分配给指针的指针
- sql-server - SQL Server 存储过程的打印问题
- pyiron - 是否可以在 pyiron 中保存项目级别的字典?
- python - 使用多处理从类中的函数返回值
- android - 通过撰写导航传递 Parcelable 参数
- javascript - Firebase 写入和更新数据并发?