我正在尝试检查办公室的一些远程服务器上的硬盘空间。下面的文件可以正常调试,但文本文件中没有输出。我已经尝试过 PS 和其他 VB 代码,它们似乎可以工作,但我需要或至少希望将数据保存在文本文件中以便保存。
想法?
arrServers = Array("server.domain.net", "server2.domain.net", "server3.domain.net")
strFilePath = "freespace.txt"
On Error Resume Next
Set objFso = CreateObject("Scripting.FileSystemObject")
Set oFile = objFso.OpenTextFile(strFilePath, 2, vbTrue)
If Not IsNothing(oFile) Then
For Each strComputer In arrServers
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
If objWMIService Then
Set colDiskDrives = objWMIService.ExecQuery _
("Select * from Win32_PerfFormattedData_PerfDisk_LogicalDisk Where " _
& "Name <> '_Total'")
For Each objDiskDrive In colDiskDrives
oFile.WriteLine "Drive", objDiskDrive.Name, "on", strComputer, "has", _
objDiskDrive.FreeMegabytes & "MB (" & objDiskDrive.PercentFreeSpace & "%) Free"
Next
Else
oFile.WriteLine "Could not connect to " & strComputer
End If
Next
Else
WScript.Echo "Could not open text file."
End If