资源描述:
《VBS脚本实例》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、VBS脚本实例说明:本文中所列出的脚本实例,均为本人因日常工作需要所写,已在生产环境中验证并使用(参数请自行修改),希望可以帮到有需要的人。但本人并非非常熟悉VBS脚本,属于现学现卖的,欢迎批评指正或是与VBS/PowerShell脚本相关的技术交流。谢谢!1AD相关1.1迁移用户/计算机到指定OU************************************************************************************** onerrorresumenextSetfso=CreateObject("S
2、cripting.FileSystemObject")Setbasefile=fso.OpenTextFile("C:base.txt",1) SetWSshell=CreateObject("Wscript.shell") Do Until basefile.AtEndOfLine=-1 '读取txt文件,直到最后一行结束 base=basefile.ReadLine comm="cmd/cecho"&base&">>C:resualt.txt" WSshell.runcomm,0,true Iffso.fileexists("C:"&
3、base&".txt")Then '判断是否有指定OU的txt文件 Setfile=fso.OpenTextFile("C:"&base&".txt",1) '打开文件 Count=0 ErrorCount=0 disabledCount=0 Do Untilfile.AtEndOfLine=-1 name=file.ReadLine 'name形如:cn=test123,ou=test,dc=abc,dc=com ab group=Right(name,2) Err.Number=0 IfLCase(g
4、roup)="ab"Then name=Left(name,Len(name)-3) 'wscript.echoname SetUserObj=GetObject("LDAP://"&name) 'wscript.echoerr.number IfErr.Number=0Then IfUserObj.AccountDisabled=FALSEThen strNewParentDN="ou="&base&",ou=personnel,ou=ab,DC=abc,DC=com"
5、 setobjCont=GetObject("LDAP://"&strNewParentDN) objCont.MoveHere"LDAP://"&name,vbNullString Count_dc=Count_dc+1 else strNewParentDN="ou=personel,ou=disabledAccounts,DC=abc,DC=com" setobjCont=GetObject("LDAP://"&strNewParentDN) objCont.Mo
6、veHere"LDAP://"&name,vbNullString disabledCount=disabledCount+1 EndIf Else ErrorCount=ErrorCount+1 comm="cmd/cechodc>>C:resualt.txt" WSshell.runcomm,0,true comm="cmd/cecho"&name&">>C:resualt.txt" WSshell.runcomm,0,true EndIf Else
7、name=Left(name,Len(name)-6) SetUserObj=GetObject("LDAP://"&name) IfErr.Number=0Then ' IfUserObj.AccountDisabled=FALSEThen strNewParentDN="ou="&base&",ou=personnel,ou=ab,DC=abc,DC=com" setobjCont=GetObject("LDAP://"&strNewParentDN) objCont.M
8、oveHere"LDAP://"&name,vbNullString Count_dcits=Count_dcits+1