Trying to create a script to automate mounting CIFS shares as drives on windows 2008/2012 server. The share requires a login (Unfortunately, AD can not be used) and needs to be mounted as a persistent drive that survives reboots.
Windows allows below
net use x: \\10.243.212.19\demo_nas_share /USER:username password /PERSISTENT:YES
However above won't save credential for next boot. We need to use
net use x: \\10.243.212.19\demo_nas_share /SAVECRED /PERSISTENT:YES
But this cmd only accepts the login details via a prompt and difficult to call from the script. Not sure if default windows server install has a native tool like 'Expect' to automate this. I like to avoid installing a third party utility.
NOTE: You can not combine /USER and /SAVECRED. This apparently was supported in some older version of windows though.
The other commonly suggested solutions is to put the cmd into startup folder. But I don't want to expose the password in plain text.
Can anyone recommend a native solution ?
Best Answer
Just a thought but you could just dump your command into a batch file and set it as a logon script in the local gpo.
@echo off
If exist x: goto Remove
goto Map
:Remove
net use x: /DELETE
:Map
net use x: \10.243.212.19\demo_nas_share /USER:username password
:End