Link to home
Start Free TrialLog in
Avatar of AlphaLolz
AlphaLolzFlag for United States of America

asked on

PS with credentials to map/unmap drives

I use my own laptop at my customer site.  I have a network logon, but because my laptop is not a member of the domain (and I don't log on to the network) I am prompted for my credentials whenever I use some network resource (IIS, fileshares, Exchange).

At times, this becomes annoying.  The prompts for my credentials may popup behind other windows and I don't see them, etc.

Long story short, I'd like to have a PS that will map a drive (and then unmap it) for the servers with shares I most use to do this that I can schedule to run regularly from the scheduler so that the prompting is done in the background and I can just start using the shares (about a half dozen) I regularly use.

I've found commands for mapping and unmapping drives, but I don't see a syntax with a credential parameter, which won't work for this situation.  Can anyone provide an example or pointer to one that would workout?
ASKER CERTIFIED SOLUTION
Avatar of John
John
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Qlemo
You can't do that for Exchange or IIS. A map drive's authentication token only works for shares, and only for shares on the same server. But for shares, you can use an approach similar to what John suggested.
As soon as you run net use \\«server» /user:«domain»\«username» «password», all mapped drives for that server should work.
You can do that "mapping" outside of PS in cmd.exe, unless you want to have the password provided and not being contained anywhere in plain text. For having an encrypted password, PS comes into play. Or you run the above net use line once with /savecred to allow for storage in your Windows Network Passwords Vault.
Avatar of AlphaLolz

ASKER

I didn't say I was trying to do this for IIS or Exchange.  I used those as examples of when I'm prompted for my credentials.
Just what I was looking for and apparently doesn't leave me with my drive volumes consumed either from what I can see (ala no F: or G: seem exist).  I won't need to unmap if nothing ends up laying around.  I have to try this from off the network to see what evil happens when the server's not available.
Thanks for the update and I was happy to help.   For folder, I can use C$ (F$) but I am a server administrator so I can get away with that.
One thing I have done before is provide credentials to services (account/password under which to run).  Perhaps I can do the same with the windows scheduler (just haven't checked).  I'd rather not put my credentials anywhere.
yes, just don't need to provide a folder (hidden or otherwise).  I just wanted to get the prompting out of the way early in the day to not have to do it later.
You can try scheduler running as administrator but it will have to deal with script / credentials.
klamerus, "just don't need to provide a folder" and "apparently doesn't leave me with my drive volumes consumed either" appear to say you are using my suggestion in #a42191267, not John's.

And I can tell from experience that "mapped" drives to locations no longer available do not harm W7+, at least if not overused and cleared out occasionally. We map drives when connecting to clients via VPN, and the scripted unmapping doesn't work all of the time, staying mapped for a week or so; but it had no effect for my machine.