Create a domain account. Assign the account permissions to the share and NTFS directory. Set the task to execute under the account you just created.
Map drive in powershell through Scheduled Task without credentials
-
29-08-2022 - |
Pregunta
I'm trying to run a powershell backup script as a scheduled task, and as a part of this I need to map a network drive (before copying the backup to the remote host).
Now, this was working when I had it like this:
NET use $RemoteDir $RemoteUser $BackupPass
But due to security concerns, I can't keep the password in plain text, or anywhere on the server. So, my hope was that, since it's run as a scheduled task, 'NET' would be able to "inherit" the credentials from the user running the scheduled task, so that it could be run like this:
NET use $RemoteDir
But it doesn't seem to work, when I log the error I get:
The password is invalid for <RemoteDir>.
Enter the user name for <RemoteDir>':
So, my question is: Is there any way to get this to work? I.e. having NET use the credentials that the scheduled job is running with? Or do I need to find another approach?
Edit: Forgot to mention, the user running the scheduled task is a domain user, and it has access to the remote.
Thanks!
Solución
Otros consejos
I dont have the solution, but a work arround. You can store a password in a file locked down to say "domain admin" like the suggestion above and follow the directions on this link:
http://geekswithblogs.net/Lance/archive/2007/02/16/106518.aspx
Seems weird, I manage station users from scheduled task without any problem, so it is possible to use the credentials. Maybe the net use
is just misbehaving, have you tried using New-PSDrive instead?