This script can be run from the command line including Server Core to quickly connect to an iSCSI target
- Windows host running the Microsoft iSCSI Software Initiator (You can check the iSCSI initiator location guide on how to get the initiator here:
2. Pre-configured iSCSI target. You will first need to create a LUN on your iSCSI target. A list of supported targets is here: http://blogs.msdn.com/san/archive/2008/08/04/logo-listings-for-enterprise-storage-arrays.aspx
REM – Batch file quick connect to an iSCSI Target.
REM – 1. First add portal for the IP address that has been entered.
REM – 2. List Targets.
REM – 3. If only one target is listed, then logon.
REM – 4. Mark it persistent.
REM – 5. Done.
echo “Trying to add target %1 for discovery”
iscsicli QAddTargetPortal %ipaddress%
REM – Find out the number of Targets discovered for the portal address
FOR /F “usebackq skip=1” %%G IN (`iscsicli ListTargets`) DO (
REM – Get a valid IQN Name.
IF !_RESULT!==iqn. (
SET /a _count = _count + 1
REM – Check if there is only one target.
if !_count! equ 1 (
echo “Found A Target – %TargetName%: Attempt to login”
iscsicli QLoginTarget %TargetName%
Echo “Mark the target as a persistent target”
iscsicli PersistentLoginTarget %TargetName% * * * * * * * * * * * * * * * *
) ELSE (
echo “Did not find a single Target to login”