你好,想做一个批处理文件,可以查询服务器每个磁盘的总大小,使用空间,剩余空间,和使用百分比? 20
我想巡检多个服务器,通过一个批处理文件把各个服务器的磁盘使用率和磁盘大小,空间空间,使用空间列出来,谢谢了。我看你以前回答了一个类似的问题,但是附件已经失效了,麻烦能在传...
我想巡检多个服务器,通过一个批处理文件把各个服务器的磁盘使用率和磁盘大小,空间空间,使用空间列出来,谢谢了。我看你以前回答了一个类似的问题,但是附件已经失效了,麻烦能在传一下吗
展开
1个回答
展开全部
复制粘贴到记事本,另存为xx.bat,编码选ANSI
' 2>nul 3>nul&cls&@echo off
'&rem 获取磁盘分区容量信息
'&set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
'&title %#% +%$%%$%/%@% %z%
'&cscript -nologo -e:vbscript "%~f0"
'&echo;%#% +%$%%$%/%@% %z%
'&pause&exit
On Error Resume Next
Set fso=CreateObject("Scripting.Filesystemobject")
Set ws=CreateObject("WScript.Shell")
Set wmi=GetObject("winmgmts:\\.\root\cimv2")
Set query1=wmi.ExecQuery("Select * from Win32_DiskDrive")
For Each item1 in query1
WSH.echo "Caption=" & item1.Caption
WSH.echo "DeviceID=" & item1.DeviceID
WSH.echo "InterfaceType=" & item1.InterfaceType
WSH.echo "MediaType=" & item1.MediaType
WSH.echo "Size=" & SizeFormat(item1.Size)
WSH.echo "========================================"
index=item1.Index
If index <> "" Then
Set query2=wmi.ExecQuery("Select * from Win32_LogicalDiskToPartition")
For Each item2 in query2
If InStr(item2.Antecedent, "Disk #" & index & ",") >0 Then
drive=replace(split(item2.Dependent,"=")(1), """", "")
If drive <> "" Then
Set query3=wmi.ExecQuery("Select * from Win32_LogicalDisk where Caption='" & drive & "'")
For Each item3 in query3
line=""
line=line & item3.Caption & " | "
line=line & item3.Description & " | "
line=line & item3.FileSystem & " | "
line=line & SizeFormat(item3.Size) & " | "
line=line & SizeFormat(item3.FreeSpace) & " | "
line=line & SizeFormat(item3.Size - item3.FreeSpace) & " | "
line=line & FormatNumber((item3.Size - item3.FreeSpace) / item3.Size, 2, true) * 100 & "%"
WSH.echo line
Next
End If
End If
Next
End If
WSH.echo ""
Next
Function SizeFormat(size)
If size >= 1099511627776 Then
SizeFormat = FormatNumber(size/1099511627776, 2, true) & " TB"
ElseIf size >= 1073741824 Then
SizeFormat = FormatNumber(size/1073741824, 2, true) & " GB"
ElseIf size >= 1048576 Then
SizeFormat = FormatNumber(size/1048576, 2, true) & " MB"
ElseIf size >= 1024 Then
SizeFormat = FormatNumber(size/1024, 2, true) & " KB"
Else
SizeFormat = size & "B"
End If
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询