0

我想要通过设置的 IP 列表检查多台计算机中 C 驱动器的可用空间的脚本..来自文本。文件

我想要windows 7环境的脚本..脚本应该检查C盘的可用空间,如果小于10gb,那么它会告诉我ip...

我尝试使用 fsutil 但这仅在本地计算机上工作,而且我有很多计算机。

希望有人可以帮助我。

4

1 回答 1

0

创建以下文件:

电脑.txt

computername1
10.40.1.60

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

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

于 2017-09-08T04:55:55.303 回答