@echo off
SET "i=0"
setlocal EnableDelayedExpansion


mpclaim -s -d > mpdisk.txt

for /f "tokens=1-8" %%A IN (mpdisk.txt) DO (

  SET var=%%F
  if "!var!"=="IBM" (
  SET "mpio_disk[!i!]=%%B"
  SET "system_disk[!i!]=Disk%%D"
  SET /A i+=1
  )  
)

datapath query device > datapath.txt

SET "count=0"
SET "count1=0"

for /f "tokens=1-9" %%A IN (datapath.txt) DO (
     
	 SET var=%%A
	 SET removed=%%D
     if "!var!"=="DEV#:" (
	 
	     SET sdd_disk[!count!]=%%B
	     SET dsystem_disk[!count!]=%%E
	     SET /A count+=1
		 
	 
	 )
	 
	 if "!var!"=="SERIAL:" (
	     
	     SET serial_id[!count1!]=%%B
	     SET /A count1+=1
	 )
	 
	 
	 
	 if "!removed!"=="Removed" (
	     
		 SET /A count-=1
	 )
    	
)



if Exist serial.txt del serial.txt
if Exist datapath.txt del datapath.txt
if Exist mpdisk.txt del mpdisk.txt



SET "count=0"
SET "count1=0"
for /F "tokens=2 delims==" %%A in ('set dsystem_disk[') do (  
SET "sysdisk=%%A"

for /F "tokens=2 delims==" %%G in ('set system_disk[') do (
SET "dsysdisk=%%G"
if "!sysdisk!"=="!dsysdisk!" (
call :process !count1!
)

SET /A count1+=1 )

SET count1=0
SET /A count+=1)

SET count=0
for /f "tokens=1-9" %%A IN (serial.txt) DO (
    SET new_mpio_serial[!count!]=%%A
	SET /A count+=1
	)

SET count=0
for /F "tokens=2 delims==" %%G in ('set serial_id[') do SET /A count+=1



SET /A count-=1
echo     LUN_SERIAL_NO#                    MPIO_DISK       SYSTEM_DISK SDDDSM_DEV#


FOR /L %%G IN (0,1,%count%) DO ( 
echo !serial_id[%%G]!      MPIO !new_mpio_serial[%%G]!       !dsystem_disk[%%G]!          !sdd_disk[%%G]!
SET /A count+=1
)
ECHO Note: LUN_SERIAL_NO# and SDDDSM_DEV# are same as in "datapath query device" output.

if Exist serial.txt del serial.txt




:process
echo !mpio_disk[%1]! >> serial.txt
EXIT /B



