debal
debal

Reputation: 1017

Get disk space information from multiple remote windows servers

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.

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.

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

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

Upvotes: 4

Views: 22736

Answers (2)

Roxx
Roxx

Reputation: 3986

So, PowerShell is not enabled, which means you need to use a 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 

Upvotes: 3

jeremyjjbrown
jeremyjjbrown

Reputation: 8009

You should be able to issue remote commends with PowerShell but you have to enable PowerShell Remoting. Here is a tutorial that looks ok.

Upvotes: 0

Related Questions