通过ip地址查看多台电脑C盘空闲space

Check free space of C drive in multiple computers via ip address

我想要一个脚本,它可以通过设置的 IP 列表检查多台计算机中 C 驱动器的空闲 space。来自文本。文件

我想要 windows 7 环境的脚本.. 并且脚本应该检查 C 驱动器的空闲 space,如果小于 10gb,那么它会告诉我那个 ip...

我试过使用 fsutil,但这只能在本地机器上工作,而且我有很多电脑。

希望有人能帮助我。

创建以下文件:

computers.txt

computername1
10.40.1.60

您可以指定计算机名称或它们的 ips。

CheckDiskFree.vbs

'
' Check drive c free space
'
On Error Resume Next

Const MIN_FREE = 10 ' Gb
Const ForAppending = 8
Const HARD_DISK = 3
Const ForReading = 1
CONST ForWriting = 2 

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set SrvList = objFSO.OpenTextFile("computers.txt", ForReading)
Set oShell = CreateObject("WScript.Shell")
Set ReportFile = objFSO.OpenTextFile ("FreeSpaceReport.csv", ForAppending, True)

'
' Report headers
'

ReportFile.writeline "Computer" & vbTAB & "Drive C Free (Gb)" & vbTAB & "Status"

'
' Loop
'

Do Until SrvList.AtEndOfStream

  StrComputer = SrvList.Readline
  wscript.echo now & vbTAB & StrComputer

  If Not IsConnectible(strComputer, "", "") Then

    ReportFile.writeline(strComputer & vbTAB & " no available")

  Else

    Set objWMIService = GetObject("winmgmts:" _ 
        & "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2") 

    Set colDisks = objWMIService.ExecQuery _ 
        ("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & " AND DeviceID = 'C:' ") 

    For Each objDisk in colDisks 
        FreeGB = objDisk.FreeSpace / (1024 * 1024 * 1024)
        strStatus = "ok"      
        If FreeGB < MIN_FREE Then strStatus = "Low disk"
        ReportFile.writeline(strComputer & vbTAB & Round(FreeGB,2) & vbTAB & strStatus)
    Next 

  End If    

Loop

'
Wscript.Quit 

Function WMIDateStringToDate(dtmBootup)

  WMIDateStringToDate = CDate(Mid(dtmBootup, 7, 2) & "/" & _
         Mid(dtmBootup, 5, 2) & "/" & Left(dtmBootup, 4) _
         & " " & Mid (dtmBootup, 9, 2) & ":" & _
         Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, _
         13, 2))

End Function


Function IsConnectible(sHost, iPings, iTO) 
' Returns True or False based on the output from ping.exe 
' 
' Author: Alex Angelopoulos/Torgeir Bakken 
' Works an "all" WSH versions 
' sHost is a hostname or IP 
' iPings is number of ping attempts 
' iTO is timeout in milliseconds 
' if values are set to "", then defaults below used 


  Const OpenAsASCII      =  0 
  Const FailIfNotExist  =  0 
  Const ForReading      =  1 
  Dim sTempFile, fFile

  If iPings = "" Then iPings = 2 
  If iTO = "" Then iTO = 750 


  sTempFile = objFSO.GetSpecialFolder(2).ShortPath & "\" & objFSO.GetTempName

  oShell.Run "%comspec% /c ping.exe -n " & iPings & " -w " & iTO & " " & sHost & ">" & sTempFile, 0 , True 
  Set fFile = objFSO.OpenTextFile(sTempFile, ForReading, FailIfNotExist, OpenAsASCII) 

  Select Case InStr(fFile.ReadAll, "TTL=")
    Case 0 IsConnectible = False 
    Case Else IsConnectible = True 
  End Select 

  fFile.Close
  objFSO.DeleteFile(sTempFile) 

End Function

要运行脚本你必须执行以下命令:cscript CheckDiskFree.vbs 该脚本将使用结果创建 FreeSpaceReport.csv