I recently wanted to create a task sequence in MDT that would build all of my Hyper-V hosts and map the iSCSI connection and connect the storage on its own. After digging around and testing several methods, I thought that the best way to do this would be that I could add a small PowerShell script into the “Custom Tasks” section at the end of the task sequence.
After some searching, and more testing, I came up with the following script:
Set-Service msiscsi –StartupType “Automatic”
New-IscsiTargetPortal –TargetPortalAddress ServerIPAddress
To run the script:
1. Copy and paste this script into a text file, change the “ServerIPAddress” to the IP of your iSCSI target and then save it with a .ps1 extension.
2. Copy the script to your Scripts folder on the Deployment Share.
3. Add a line called “Run PowerShell Script” under “General” and name it “Map iSCSI” under the Custom Tasks section.
4. Under the “PowerShell Script” section, put in “.\Scripts\ScriptName.ps1” to it and save.
After this, you can run your task sequence, and as long as you have the servers mapped on the target end, they will map at the end of the task sequence.
Note: You will still have to go into the iSCSI initiator and set the connection as “Active” and use Multipath if needed.
I hope this helps!