随笔 - 196  文章 - 0  评论 - 9  阅读 - 63万

根据计算机帐号,将其自动的移动到相应的OU脚本

很多的企业都有这样的要求:希望整理自己的computers容器中的计算机,根据计算机名将其添加到对应的OU中去,但如果由人力来实现的话,工作量非常大,所以,在这次给某个企业实施项目的时候,我随手写了一个脚本,该脚本会自动将计算机加入到对应的OU中去。用户可以自己改写一下脚本,以适应自己的情况,我的脚本里对计算机名截取了2个字符。

dim strADsPath
dim sResultText
Const ADS_SCOPE_SUBTREE = 2
Set con = CreateObject(“ADODB.Connection”)
Set com = CreateObject(“ADODB.Command”)
‘Open the connection with the ADSI-OLEDB provider name
con.Provider = “ADsDSOObject”
con.Open

Com.ActiveConnection = con

Com.CommandText = “<LDAP://cn=computers,DC=contoso,DC=com>;” & “(objectClass=computer);name;subTree”
Set rs = Com.Execute()
i=0

Do Until rs.EOF
   sResultText=rs.Fields(“name”).value
   Select Case left(sResultText,2)
   Case “c1″
       strADsPath=”LDAP://cn=” & sResultText & “,cn=computers,dc=contoso,dc=com”
       set objou=getobject(“LDAP://ou=ouc1,dc=contoso,dc=com“)
       objou.movehere strADsPath,vbNullString
   Case “c2″
       strADsPath=”LDAP://cn=” & sResultText & “,cn=computers,dc=contoso,dc=com”
       set objou=getobject(“LDAP://ou=ouc2,dc=contoso,dc=com“)
       objou.movehere strADsPath,vbNullString
   Case “c3″
      strADsPath=”LDAP://cn=” & sResultText & “,cn=computers,dc=contoso,dc=com”
      set objou=getobject(“LDAP://ou=ouc3,dc=contoso,dc=com“)
       objou.movehere strADsPath,vbNullString
   Case “c4″
      strADsPath=”LDAP://cn=” & sResultText & “,cn=computers,dc=contoso,dc=com”
      set objou=getobject(“LDAP://ou=测试,dc=contoso,dc=com”)
       objou.movehere strADsPath,vbNullString
End Select

  rs.MoveNext
Loop

con.close

 

然后,在控制面板的“定期任务”中,将此脚本指定多少时间执行一次,然后输入执行的用户和密码,即可。

posted on   周德顺  阅读(648)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
< 2013年1月 >
30 31 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31 1 2
3 4 5 6 7 8 9

点击右上角即可分享
微信分享提示