首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过ip地址检查多台计算机中C驱动器的空闲空间

通过ip地址检查多台计算机中C驱动器的空闲空间
EN

Stack Overflow用户
提问于 2017-09-07 09:05:34
回答 1查看 748关注 0票数 0

我想要通过IP的设置列表检查C驱动器在多台计算机上的空闲空间的脚本。从短信里。文件

我想要windows 7环境的脚本。脚本应该检查C驱动器的空闲空间,如果小于10 it,它将向我显示ip.

我试过用fsutil,但是这个工作只是在本地的机器上,而且我有很多计算机。

希望有人能帮我这个忙。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-08 04:55:55

创建以下文件:

computers.txt

代码语言:javascript
复制
computername1
10.40.1.60

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

CheckDiskFree.vbs

代码语言:javascript
复制
'
' 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

要运行脚本,必须执行以下命令:FreeSpaceReport.csv脚本将创建带有结果的cscript CheckDiskFree.vbs

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46092252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档