VBS脚本实例Word格式.docx
- 文档编号:19072682
- 上传时间:2023-01-03
- 格式:DOCX
- 页数:8
- 大小:17.64KB
VBS脚本实例Word格式.docx
《VBS脚本实例Word格式.docx》由会员分享,可在线阅读,更多相关《VBS脚本实例Word格式.docx(8页珍藏版)》请在冰豆网上搜索。
base&
"
>
>
\resualt.txt"
WSshell.runcomm,0,true
Iffso.fileexists("
\"
.txt"
)Then
判断是否有指定OU的txt文件
Setfile=fso.OpenTextFile("
'
打开文件
Count=0
ErrorCount=0
disabledCount=0
Untilfile.AtEndOfLine=-1
name=file.ReadLine
name形如:
cn=test123,ou=test,dc=abc,dc=com
ab
group=Right(name,2)
Err.Number=0
IfLCase(group)="
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="
ou=personnel,ou=ab,DC=abc,DC=com"
setobjCont=GetObject("
strNewParentDN)
objCont.MoveHere"
name,vbNullString
Count_dc=Count_dc+1
else
ou=personel,ou=disabledAccounts,DC=abc,DC=com"
disabledCount=disabledCount+1
EndIf
Else
ErrorCount=ErrorCount+1
cmd/cechodc>
name&
Else
name=Left(name,Len(name)-6)
IfErr.Number=0Then
Count_dcits=Count_dcits+1
cmd/cechodcits>
Loop
file.close
cmd/cechoCount_dc="
Count_dc&
cmd/cechoCount_dcits="
Count_dcits&
cmd/cechodisabledCount="
disabledCount&
cmd/cechoErrorCount="
ErrorCount&
basefile.close
wscript.echo"
操作完成"
Wscript.Quit
******************************************************************************
1.2批量导出AD中指定OU的用户和安全组
读取域下abOU下,personnelOU中所有OU中的用户和安全组
结果保存到C:
\personnel-ab.txt
用base.txt存放ou=personnel,ou=ab,dc=abc,dc=com下各OU的名称
1)
basefile.AtEndOfLine=-1
ou1="
ou=personnel,ou=ab,dc=abc,dc=com"
SetUserObj_ab=GetObject("
ou1)
ForEachoUserinUserObj_ab
name=oUser.name
读取到的当前用户的显示名称
account=oUser.sAMAccountName'
用户的登录名
disabled=oUser.AccountDisabled'
用户状态,True为禁用,False为启用
dn=oUser.distinguishedName
用户LDAP路径
account&
disabled&
dc>
\personnel-ab.txt"
WSshell.runcomm,0,true
输出到指定文件夹
Next
2文件相关
2.1解压文件到指定文件夹
获取当前日期
temp_day=day(date)
temp_month=month(date)
temp_year=year(date)
IfLen(temp_day)=1Then
temp_day="
0"
temp_day
IfLen(temp_month)=1Then
temp_month="
temp_month
today=temp_year&
temp_month&
msgboxtoday
获取压缩包
ftpRar="
D:
\FTP\HERP3.1"
uFolder="
\HERP3.1\update\"
temp_year
count=0
SetwsShell=wscript.CreateObject("
wscript.shell"
SetoFolder=fso.GetFolder(ftpRar)
SetoSubFolders=oFolder.SubFolders
ForEachFileinoFolder.Files
rarName=File.Name
rarPath=File.Path
msgboxrarName
msgboxrarPath
IfLeft(rarName,8)=todayThen
count=count+1
解压缩
cmd="
winrarx-t-o+-p-"
rarPath&
chr(32)&
uFolder
msgboxcmd
wsShell.Runcmd
EndIf
Ifcount=0Then
Msgbox"
压缩包不存在!
"
Wscript.quit
*******************************************************************************
2.2增量备份
用于文件更新前的增量备份。
根据uFolder路径下的文件,对bakSource路径下的文件进行增量备份,并保存到newPath路径下。
增量备份
count=0
newPath="
\HERP3.1\backup\"
temp_year&
today
SetWsShell=WScript.CreateObject("
SetoFolder=fso.GetFolder(uFolder)
ForEachFolderinoSubFolders
FolderName=Folder.Name
FolderPath=Folder.Path
IfLeft(FolderName,8)=todayThen
Iffso.FolderExists(newPath)Then
Else
SetnewFolder=fso.CreateFolder(newPath)
EndIf
SetsFolders=fso.GetFolder(FolderPath)
SetsSubFolders=sFolders.SubFolders
ForEachsFolderinsSubFolders
sFolderName=sFolder.Name
bakSource="
\\172.17.0.32\DLHWJ_Web32\"
sFolderName
bakDestination=newPath&
Iffso.FolderExists(bakSource)Then
cmd/cxcopy/y/e"
bakSource&
bakDestination
WsShell.Runcmd,1,true
Next
ForEachFileinsFolders.Files
\\网络IP\共享文件夹\"
File.Name
bakDestination=newPath
Iffso.FileExists(bakSource)Then
Msgbox"
已备份"
count&
个对象。
备份完成!
3数据库相关
3.1批量执行SQL脚本
‘数据库为SQLServer2008/2012,其他版本的数据库没有尝试过。
‘批量执行指定路径(sFolder)下的sql脚本,提示执行结果。
sqlcmd命令格式:
sqlcmd-s"
服务器IP"
-u"
数据库用户名"
-p"
用户密码"
-d"
数据库名"
-i"
sql脚本完全路径"
-p
Setws=WScript.CreateObject("
sFolder="
E:
\work\sql"
#sql脚本存放路径
dbServer="
test-db"
#数据库服务器的计算机名/IP地址(计算机名需要考虑远程域名解析的问题)
dbUser="
db-user"
#访问数据库的用户名,域用户为“域\用户名”
dbPwd="
user-pwd"
#用户密码
db="
test"
#库名
setfs=CreateObject("
setoFolder=fs.GetFolder(sFolder)'
获取文件夹
setoSubFolders=oFolder.SubFolders'
获取子目录集合
setoFiles=oFolder.Files'
获取文件集合
foreachfileinoFiles
sExt=fs.GetExtensionName(file)'
获取文件扩展名
sExt=LCase(sExt)'
转换成小写
path=sFolder&
file.Name'
获得文件名(含扩展名,不含路径)和扩展名
cmd/csqlcmd-S"
chr(34)&
dbServer&
-U"
dbUser&
-P"
dbPwd&
db&
Path&
-p"
SetobjExecObject=ws.Exec(cmd)
strText=objExecObject.StdOut.ReadAll()
msgboxstrText
操作完成!
wscript.quit
172.17.0.61"
dbadmin"
HerpP@ssw0rd"
herp3"
\work\更新\herp\test\01-CRHDAT.sql"
127.0.0.1"
cmdb01"
123456"
cmdb"
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VBS 脚本 实例