脚本很新,但我设法将一些东西放在一起,我检索可用的磁盘空间 - 格式化我想要的方式。然后将文件导入SQL。
我得到的错误是连接正在使用输出文件。我怎么能让这个在没有错误的情况下在一个脚本下运行..所有的帮助表示赞赏。
`CONST strComputer = "."
AuditPath = "C:\Users\Pam\Desktop\Khalid.txt"
ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=khalid;Data Source=GRIMLEY"
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(AuditPath,True)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_Volume")
Set objConn = CreateObject ("ADODB.Connection")
d = date()
ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=khalid;Data Source=GRIMLEY"
DIM objWMIService, objItem, colItems
DIM AuditPath, txt , strSQL , ConnectionString
txt = "Server" & vbtab & "DriveLetter" & vbtab & "DriveName" & vbtab & "Size" & vbtab & "Used" & vbtab & "Free" & vbtab & "% Free" & vbtab & "Date" & vbcrlf
Server = "ALL_IN_ONE_Final"
For Each objItem In colItems
ObjFile.Write Server & ","
objFile.write objItem.DriveLetter & ","
ObjFile.Write objItem.Label & ","
objFile.write Int(objItem.Capacity /1073741824)\1 & ","
objFile.write Int((objItem.Capacity - objItem.FreeSpace )/1073741824)\1 & ","
objFile.write Int (objItem.FreeSpace /1073741824)\1 & ","
objFile.write ((objItem.FreeSpace/objItem.Capacity) * 100)\1 & "," & vbcrlf
next
WScript.Sleep 8000
Set objConn = CreateObject ("ADODB.Connection")
objConn.Open ConnectionString
strSQL = strSQL & " BULK INSERT Server_Space"
strSQL = strSQL & " FROM 'C:\Users\Pam\Desktop\Khalid.txt' with"
strSQL = strSQL & " ( FIELDTERMINATOR =',', ROWTERMINATOR = '0x0a')"
objConn.Execute strSQL
objConn.Close
WScript.Quit()`