VBS脚本实例
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
VBS脚本实例
说明:
本文中所列出的脚本实例,均为本人因日常工作需要所写,已在生产环境中验证并使用(参数请自行修改),希望可以帮到有需要的人。但本人并非非常熟悉VBS脚本,属于现学现卖的,欢迎批评指正或是与VBS/PowerShell脚本相关的技术交流。谢谢!
1AD相关
1.1迁移用户/计算机到指定OU
************************************************************************************** on error resume next
Set fso = CreateObject("Scripting.FileSystemObject")
Set basefile =fso.OpenTextFile("C:\base.txt",1)
Set WSshell=CreateObject("Wscript.shell")
Do Until basefile.AtEndOfLine = -1 '读取txt文件,直到最后一行结束
base = basefile.ReadLine
comm = "cmd /c echo " & base & " >>C:\resualt.txt"
WSshell.run comm,0,true
If fso.fileexists("C:\" & base & ".txt") Then '判断是否有指定OU的txt文件
Set file=fso.OpenTextFile("C:\" & base & ".txt",1) '打开文件
Count = 0
ErrorCount = 0
disabledCount = 0
Do Until file.AtEndOfLine=-1
name = file.ReadLine 'name 形如:cn=test123,ou=test,dc=abc,dc=com ab group = Right(name,2)
Err.Number = 0
If LCase(group) = "ab" Then
name = Left(name,Len(name)-3)
'wscript.echo name
Set UserObj = GetObject("LDAP://" & name)
'wscript.echo err.number
If Err.Number = 0 Then
If UserObj.AccountDisabled = FALSE Then
strNewParentDN = "ou=" & base & ",ou=personnel,ou=ab,DC=abc,DC=com"
set objCont = GetObject("LDAP://" & strNewParentDN)
objCont.MoveHere "LDAP://" & name,vbNullString
Count_dc = Count_dc + 1
else
strNewParentDN = "ou=personel,ou=disabledAccounts,DC=abc,DC=com"
set objCont = GetObject("LDAP://" & strNewParentDN)
objCont.MoveHere "LDAP://" & name,vbNullString
disabledCount = disabledCount + 1
End If
Else
ErrorCount = ErrorCount + 1
comm = "cmd /c echo dc>>C:\resualt.txt"
WSshell.run comm,0,true
comm = "cmd /c echo " & name & " >>C:\resualt.txt"
WSshell.run comm,0,true
End If
Else
name = Left(name,Len(name)-6)
Set UserObj = GetObject("LDAP://" & name)
If Err.Number = 0 Then '
If UserObj.AccountDisabled = FALSE Then
strNewParentDN = "ou=" & base & ",ou=personnel,ou=ab,DC=abc,DC=com"
set objCont = GetObject("LDAP://" & strNewParentDN)
objCont.MoveHere "LDAP://" & name,vbNullString
Count_dcits = Count_dcits + 1
else
strNewParentDN = "ou=personel,ou=disabledAccounts,DC=abc,DC=com"
set objCont = GetObject("LDAP://" & strNewParentDN)
objCont.MoveHere "LDAP://" & name,vbNullString
disabledCount = disabledCount + 1
End If
Else
comm = "cmd /c echo dcits>>C:\resualt.txt"
WSshell.run comm,0,true
ErrorCount = ErrorCount + 1
comm = "cmd /c echo " & name & " >>C:\resualt.txt"
WSshell.run comm,0,true
End If
End If
Loop
file.close
comm = "cmd /c echo Count_dc=" & Count_dc & " >>C:\resualt.txt"
WSshell.run comm,0,true
comm = "cmd /c echo Count_dcits=" & Count_dcits & " >>C:\resualt.txt"
WSshell.run comm,0,true
comm = "cmd /c echo disabledCount=" & disabledCount & " >>C:\resualt.txt" WSshell.run comm,0,true
comm = "cmd /c echo ErrorCount=" & ErrorCount & " >>C:\resualt.txt"
WSshell.run comm,0,true
End If
Loop
basefile.close
wscript.echo "操作完成"
Wscript.Quit