OSD, Task Sequence, and VBS to map a drive
I am using SCCM for OSD (in conjunction with SmartDeploy). I have a boot media that is created with SCCM/SmartDeploy. It is based on WinPE 3.0 It boots up to the SCCM Task Sequence list. I have a very simple task sequence setup to fire off the deployment. First step is to map a network drive (Y:) to a share that contains a common script that everyone will run. A second task sequence will run to fire off this script (y:\sdmap.vbs). This script (see below) extrapolates the current IP address from WinPE and disects the octets. I take a certain octet and based on that octet, it will map the drive to the users LOCAL server (I have 26 remote location). When I run the script on my PC, it works flawlessly. When I try to run it from with in my task sequence I error out on the following line: objnetwork.mapnetworkdrive strLocalDrive, strServer & strShare, , strUSer, StrPas The logic appears to work as it errors out in the appropriate Case section. Now the funny thing is, I can issue a Net Use command (Net Use Z: \\server\share$) and then provide the credentials when asked and the drive maps. Howeve, I need to be able to do it from a script. *************************************************************** ' Execute an ipconfig to the local machine and store the output in the stdout Set objShell = CreateObject("Wscript.Shell") set objNetwork = WScript.CreateObject("WScript.Network") Set objExec = objshell.exec("%comspec% /c ipconfig.exe") strLocalDrive = "z:" ' Local Drive StrShare = "Share$" ' Share StrPer = "False" StrUsr = "domain\user" ' Authorized Credential StrPas = "Password" ' loop through the stream looking for key phrase "IPv4 Addresses" do while NOT (objexec.StdOut.AtEndOfStream) strLine = objExec.StdOut.ReadLine if(inStr(strLine, "IPv4 Address")) then ' Parse strLine to optain IP strIP = trim(right(strLine, Len(strLine) - inStrRev(strLine, ":"))) Exit Do End If Loop arrTokens = Split(strIP, ".") Select Case arrTokens(1) Case "98" strServer = "\\Server1\" objnetwork.mapnetworkdrive strLocalDrive, strServer & strShare, , strUSer, StrPas Case "47" strServer = "\\Server2\" objnetwork.mapnetworkdrive strLocalDrive, strServer & strShare, , strUSer, StrPas Case "111" strServer = "\\Server3\" objnetwork.mapnetworkdrive strLocalDrive, strServer & strShare, , strUSer, StrPas Case "118" strServer = "\\Server4\" objnetwork.mapnetworkdrive strLocalDrive, strServer & strShare, , strUSer, StrPas Case "177" strServer = "\\Server5\" objnetwork.mapnetworkdrive strLocalDrive, strServer & strShare, , strUSer, StrPas End Select ************************************************************************************ When I run the script in the PE, I get the following error: sdmap.vbs (30,3) WSHNetwork.MapNetworkDrive: Access is Denied If you look at the code, I am using objNetwork.MapNetworkDrive. What do I need to do, to accomplish this. Thanks
June 22nd, 2011 2:37am

i think this is because you are running the script as Local System, try using a Connect to Network Folder step in the task sequence prior to this specifying the same user, does it work ? My step by step SCCM Guides I'm on Twitter > ncbrady
Free Windows Admin Tool Kit Click here and download it now
June 22nd, 2011 9:32am

I would put a msgbox right above the "select case" to look at the exact syntax of the command msgbox strLocalDrive& "," & strServer & strShare&", ,"& strUSer&","& StrPas I also do a drivemapping in a vbscript when running in winPE and don't have a problem.
June 22nd, 2011 10:43am

Niall, that is actually my short term solution. But if I map it statically, I have to have 26 seperate task sequences (One task sequence for each location using the same credentials). Not a big fan of that. If I can get the script to work, it will be a single task sequence that will map the to the appropriate local server. Like I said, the code works flawleslly running from a command prompt in Win7. Jerenda, I will try that and report back.
Free Windows Admin Tool Kit Click here and download it now
June 22nd, 2011 5:12pm

Agree with Niall that it appears to be because you're running as local system. Are you on R2 where you can specify a runas account? Does the account that is running the task have access to the share? Is the machine in the Domain at the time this runs (ie, could you add Domain Computers to the share permissions). Also... couldn't you put a condition on the Connect to Network Folder task so if variable=x, connect to share x, if variable=y, connect to share y, etc. You would need 26 steps like this in the task sequence but it would keep things in a single TS. Maybe you could use the TS variable for default gateway?
June 22nd, 2011 7:11pm

When it errors I can F8 to a command window. I can then use Net Use to map to the drive using the same credentials that I am attempting to use in the script. Well as far as the machine being in the domain, these (most of the time) will be new computers receving an image; never been on the network / domain. And no, this is a Windows 2008 R1 server/
Free Windows Admin Tool Kit Click here and download it now
June 23rd, 2011 1:02pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics