从多个远程 Windows 服务器获取磁盘空间信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21421891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get disk space information from multiple remote windows servers
提问by debal
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.
我正在尝试制作一种工具,该工具可以登录到多个远程 Windows 服务器并获取其驱动器详细信息并将其显示在一个窗口下。
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.
我期待在远程服务器中执行的可能命令是wmic logicaldisk get size,freespace,caption
. 我打算获取此命令的输出并显示它。
I have remote server hostname and IP, username and password.
我有远程服务器主机名和 IP、用户名和密码。
How do I connect to these remote servers and execute the command?
如何连接到这些远程服务器并执行命令?
回答by Ironic
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.
因此,powershell 未启用,这意味着您需要使用批处理文件。我建议你试试这个脚本。我找到了这个脚本,它运行良好。
I hope this help you.
我希望这对你有帮助。
@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