Answers:
使用Powershell,可以使用以下命令:
Get-WmiObject -Class win32_logicalDisk -ComputerName server1, server2, server3, etc | Select-Object pscomputername, deviceid, freespace, size
用远程服务器名称或IP 替换server1,server2等。
输出看起来像这样:
如果需要,可以将其添加| Export-Csv -Path .\drives.csv
到脚本的末尾,以将文件输出为逗号分隔值(CSV)文件以供Excel使用。如果这样做,则在打开Excel时,您需要将Excel中的驱动器大小列设置为数字格式。
只是为了咯咯笑,我编写了这个PowerShell脚本,它将在Active Directory中的所有服务器上执行任务:
$ErrorActionPreference= 'silentlycontinue'
Get-ADComputer -Filter 'OperatingSystem -like "*Server*"' -Properties * | Select-Object Name |
ForEach-Object {
If (Test-Connection $_.Name -Count 1){
Get-WmiObject -Class win32_logicalDisk -ComputerName $_.Name |
Select-Object pscomputername, deviceid, freespace, size
}
else {
Write-host $_.Name " Connection Error"
}
}
使用命令fsutil
:
fsutil volume diskfree C:
fsutil volume diskfree \\server\share
输出将如下所示:
Total # of free bytes : 851127304192
Total # of bytes : 2147480485888
Total # of avail free bytes : 851127304192
要仅获取具有可用字节的行,可以使用:
fsutil volume diskfree C: | find /i "avail free"
伙计们,我还提供了一个使用fsutil和telnet的解决方案:
<package>
<job id="vbs">
<script language="VBScript">
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "telnet 182.56.32.23 -l work"
WScript.Sleep 500
WshShell.AppActivate "Telnet"
WScript.Sleep 500
WshShell.SendKeys "y"
WshShell.SendKeys "~"
WScript.Sleep 500
WshShell.SendKeys "helloworld"
WScript.Sleep 500
WshShell.SendKeys "~"
WScript.Sleep 500
WshShell.SendKeys "C:\Users\work2\Desktop\diskcheck.bat"
WScript.Sleep 200
WshShell.SendKeys "~"
</script>
</job>
</package>
diskcheck.bat:
fsutil卷无磁盘C: 输出: 可用字节总数:17084395520 字节总数:249145847808 可用空闲字节总数:17084395520
Function GetRemoteDiskSpace (
[String]$TargetComputer,
[String]$Drive
)
{
$Drive = New-PSDrive -Name K -PSProvider FileSystem -Root "\\$TargetComputer\$Drive$" -Persist
$Info = Get-PSDrive $Drive
$Free = $Info.Free /1GB
Remove-PSDrive -Name $drive -PSProvider FileSystem
return $Free
}