Friday, January 7, 2011

Script to get disk configuration - An Alternative to Disk Manager. (faster, easier, logged)

Here's a very handy script when you need to capture the Disk Configuration of a server. Let's say you can Dynamic Disks, and you need to know how many LUNs are making a Windows OS Disk.


REM I stole this code from my good greek friend. I hope he doesn't get angry, anyways I gave him some ideas so he shouldn't :)


@echo off

if exist "%systemroot%\system32\diskpart.exe" set dskprt=%systemroot%\system32\diskpart.exe
if "%dskprt%" EQU "" goto END

echo list disk>dskprt_script.doc
echo list volume>>dskprt_script.doc

%dskprt% -s dskprt_script.doc>%computername%_diskpart.doc

set /a cd=0
set /a cv=0

findstr /c:" Disk " %computername%_diskpart.doc>dskprt_temp.doc
for /f %%a in (dskprt_temp.doc) do (
set /a cd+=1
)
set /a cd=%cd%-2

findstr /c:" Volume " %computername%_diskpart.doc>dskprt_temp.doc
for /f %%a in (dskprt_temp.doc) do (
set /a cv+=1
)
set /a cv=%cv%-2

del dskprt_temp.doc




del dskprt_script.doc
for /l %%a in (0,1,%cd%) do (
echo select disk %%a>>dskprt_script.doc
echo detail disk>>dskprt_script.doc
)
%dskprt% -s dskprt_script.doc>%computername%_disk.doc
del dskprt_script.doc
for /l %%a in (0,1,%cv%) do (
echo select volume %%a>>dskprt_script.doc
echo detail volume>>dskprt_script.doc
)
%dskprt% -s dskprt_script.doc>%computername%_volume.doc
del dskprt_script.doc

echo Regards to Bistakis Pig.
pause

:END



Make sure it's working the way you want.
And compare the result logs and running the diskpart commands manually (as some diskpart.exe version did have a bug and it didn't worked correctly using diskpart /script option).

Alternatives but not as good to get LUNs configuration:
wmic partition list /format:htable >disk.html
wmic logicaldisk list /format:htable >logicaldisk.html

0 comments:

Post a Comment