VBS脚本实例Word文档下载推荐.docx
《VBS脚本实例Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《VBS脚本实例Word文档下载推荐.docx(9页珍藏版)》请在冰豆网上搜索。
&
base&
"
>
>
comm,0,true
If("
.txt"
)Then
判断是否有指定OU的txt文件
Setfile=("
'
打开文件
Count=0
ErrorCount=0
disabledCount=0
Until=-1
name=
name形如:
cn=test123,ou=test,dc=abc,dc=com
ab
group=Right(name,2)
=0
IfLCase(group)="
ab"
Then
name=Left(name,Len(name)-3)
name
SetUserObj=GetObject("
name)
If=0Then
If=FALSEThen
strNewParentDN="
ou="
ou=personnel,ou=ab,DC=abc,DC=com"
setobjCont=GetObject("
strNewParentDN)
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)
If=0Then
Count_dcits=Count_dcits+1
cmd/cechodcits>
Loop
cmd/cechoCount_dc="
Count_dc&
cmd/cechoCount_dcits="
Count_dcits&
cmd/cechodisabledCount="
disabledCount&
cmd/cechoErrorCount="
ErrorCount&
操作完成"
******************************************************************************
1.2批量导出AD中指定OU的用户和安全组
读取域下abOU下,personnelOU中所有OU中的用户和安全组
结果保存到C:
\
用存放ou=personnel,ou=ab,dc=abc,dc=com下各OU的名称
1)
=-1
ou1="
ou=personnel,ou=ab,dc=abc,dc=com"
SetUserObj_ab=GetObject("
ou1)
ForEachoUserinUserObj_ab
读取到的当前用户的显示名称
account='
用户的登录名
disabled='
用户状态,True为禁用,False为启用
dn=
用户LDAP路径
account&
disabled&
dc>
comm,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\"
uFolder="
\\update\"
temp_year
count=0
SetwsShell=("
SetoFolder=(ftpRar)
SetoSubFolders=
ForEachFilein
rarName=
rarPath=
msgboxrarName
msgboxrarPath
IfLeft(rarName,8)=todayThen
count=count+1
解压缩
cmd="
winrarx-t-o+-p-"
rarPath&
chr(32)&
uFolder
msgboxcmd
cmd
EndIf
Ifcount=0Then
Msgbox"
压缩包不存在!
*******************************************************************************
2.2增量备份
用于文件更新前的增量备份。
根据uFolder路径下的文件,对bakSource路径下的文件进行增量备份,并保存到newPath路径下。
增量备份
count=0
newPath="
\\backup\"
temp_year&
today
SetWsShell=("
SetoFolder=(uFolder)
ForEachFolderinoSubFolders
FolderName=
FolderPath=
IfLeft(FolderName,8)=todayThen
If(newPath)Then
Else
SetnewFolder=(newPath)
EndIf
SetsFolders=(FolderPath)
SetsSubFolders=
ForEachsFolderinsSubFolders
sFolderName=
bakSource="
\\"
sFolderName
bakDestination=newPath&
If(bakSource)Then
cmd/cxcopy/y/e"
bakSource&
bakDestination
cmd,1,true
Next
ForEachFilein
\\网络IP\共享文件夹\"
bakDestination=newPath
Msgbox"
已备份"
count&
个对象。
备份完成!
3数据库相关
3.1批量执行SQL脚本
‘数据库为SQLServer2008/2012,其他版本的数据库没有尝试过。
‘批量执行指定路径(sFolder)下的sql脚本,提示执行结果。
sqlcmd命令格式:
sqlcmd-s"
服务器IP"
-u"
数据库用户名"
-p"
用户密码"
-d"
数据库名"
-i"
sql脚本完全路径"
-p
Setws=("
sFolder="
E:
\work\sql"
#sql脚本存放路径
dbServer="
test-db"
#数据库服务器的计算机名/IP地址(计算机名需要考虑远程域名解析的问题)
dbUser="
db-user"
#访问数据库的用户名,域用户为“域\用户名”
dbPwd="
user-pwd"
#用户密码
db="
test"
#库名
setfs=CreateObject("
setoFolder=(sFolder)'
获取文件夹
setoSubFolders='
获取子目录集合
setoFiles='
获取文件集合
foreachfileinoFiles
sExt=(file)'
获取文件扩展名
sExt=LCase(sExt)'
转换成小写
path=sFolder&
获得文件名(含扩展名,不含路径)和扩展名
cmd/csqlcmd-S"
chr(34)&
dbServer&
-U"
dbUser&
-P"
dbPwd&
db&
Path&
-p"
SetobjExecObject=(cmd)
strText=
msgboxstrText
操作完成!
dbadmin"
HerpP@ssw0rd"
herp3"
\work\更新\herp\test\"
cmdb01"
123456"
cmdb"