|
通过批处理查询挂载的盘符就可以了,然后做参数传递@echo off
net start "Microsoft iSCSI Initiator Service">nul 2>nul
call :iscsi_logout %serverip% 3260
exit
:iscsi_login
set iscsiip=%1
set iscsiport=%2
iscsicli AddTargetPortal %iscsiip% %iscsiport% >NUL 2>NUL
for /f %%a in ('iscsicli ListTargets ^|find "iqn"') do (
@echo 连接iscsi服务器中……
start /w iscsicli LoginTarget %%a T * * * * * * * * * * * * * * * 0 >NUL 2>NUL
if "%errorlevel%" == "0" echo 此次连接上服务器 %%a
)
for /f "tokens=* delims==" %%i in ('iscsicli ReportPersistentDevices ^|find /i ":\"') do (set SysDrv=%%~i)
set SysDrv=%SysDrv:~0,-1%
echo ISCSI磁盘挂在本机盘符为:%SysDrv%
pause
exit /b
:iscsi_logout
set iscsiip=%1
set iscsiport=%2
for /f "tokens=3 delims=: " %%i in ('iscsicli SessionList ^|find "会话 ID"') do (iscsicli LogoutTarget %%i >NUL 2>NUL)
iscsicli RemoveTargetPortal %iscsiip% %iscsiport% >NUL 2>NUL
iscsicli listtargets t >NUL 2>NUL
goto iscsi_login
|
|