从多个远程 Windows 服务器获取磁盘空间信息 [英] Get disk space information from multiple remote windows servers

查看:84
本文介绍了从多个远程 Windows 服务器获取磁盘空间信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一种工具,该工具可以登录到多个远程 Windows 服务器并获取其驱动器详细信息并将其显示在一个窗口中.

I am trying to make a tool that would login to multiple remote windows servers and get their drive details and display them under one window.

我期待在远程服务器中执行的可能命令是wmic logicaldisk get size,freespace,caption.我打算得到这个命令的输出并显示出来.

Possible command that I am looking forward to execute in the remote server is wmic logicaldisk get size,freespace,caption. I intend to get the output of this command and display it.

我有远程服务器主机名和 IP、用户名和密码.

I have remote server hostname and IP, username and password.

如何连接到这些远程服务器并执行命令?

How do I connect to these remote servers and execute the command?

推荐答案

因此,powershell 未启用,这意味着您需要使用批处理文件.我建议你试试这个脚本.我找到了这个脚本,它运行良好.

So, powershell is not enabled it means you need to use batch file. I would suggest you to try this script. I have found this script and it is working fine.

希望对您有所帮助.

@ECHO OFF
IF "%~1"=="" goto help
IF "%~2"=="" goto help

@SETLOCAL ENABLEEXTENSIONS
@SETLOCAL ENABLEDELAYEDEXPANSION

@FOR /F "tokens=1-3" %%n IN ('"WMIC /node:"%1" LOGICALDISK GET Name,Size,FreeSpace | find /i "%2""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p

@SET /A TotalSpace=!TotalBytes:~0,-9!
@SET /A FreeSpace=!FreeBytes:~0,-10!
@SET /A TotalUsed=%TotalSpace% - %FreeSpace%
@SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace!
@SET /A PercentFree=100-!PercentUsed!

IF %TotalSpace% LSS 0 goto error

@ECHO Total space: %TotalSpace%GB
@ECHO Free space: %FreeSpace%GB
@ECHO Used space: %TotalUsed%GB
@ECHO Percent Used: %PercentUsed%%%
@ECHO Percent Free: %PercentFree%%%

@SET TotalSpace=
@SET FreeSpace=
@SET TotalUsed=
@SET PercentUsed=
@SET PercentFree=
goto end

:error
echo.
echo *** Invalid server or drive specified ***
echo.
goto help

:help
echo.
echo diskfree.cmd
echo.
echo Queries remote server for free disk space.
echo Specify a MACHINENAME and a drive letter to be queried
echo.
echo Example:   diskfree.cmd MACHINENAME c:
echo.
goto end


:end 

这篇关于从多个远程 Windows 服务器获取磁盘空间信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆