Have a windows 2012 R2 there users need to mapp a share on a remote server through unc path.
want to use New-PSDrive cmdlet. ave tried with.
New-PSDrive -Name “Z” -PSProvider FileSystem -Root “\server\share” -Persist
But get access denied on that share, so have to add in some credential to this, have tried with
Here i got a login window and it work to map the drive if fill in the cred, but i want to use the credential the user have login with to the server so they dont have to login to the share . the users have permission on the share. (still get access denied)
New-PSDrive already uses the current logon credentials by default, if you don’t provide a credential. If that’s not working, double-check the share permissions and double-check the current user (run “whoami”).
For example, if you’ve run the shell As Administrator, that may be your problem in this instance, because it would attempt to use that credential rather than the one you logged onto Windows with. Running WhoAmI will let you verify who the shell thinks you are.
i forgot to add in that the script must run as administrator and map the drive, application that need this mapped drive runs as administrator in windows to work. The user i run the shell with have permission on the share
i run the
New-PSDrive -Name “Z” -PSProvider FileSystem -Root “\server\share” -Persist
There is no safe way to do that. What you’re asking is a way to provide Administrator credentials - which you would have to do in a way that anyone could read - to someone who is not an Administrator. Just write down the Admin credentials on a Post-It Note and hang it in the break room ;).
Sorry, but there’s just no secure way to do this. PowerShell deliberately makes it difficult because there’s no safe way to do it - it’s a bad security practice.
I have a bat file that open the PS shell as administrator like this and then run the PS1 script like obove.
@echo off
NET SESSION 1>NUL 2>NUL
IF %ERRORLEVEL% EQU 0 GOTO ADMINTASKS
CD %~dp0
MSHTA “javascript: var shell = new ActiveXObject(‘shell.application’); shell.ShellExecute(‘%~nx0’, ‘’, ‘’, ‘runas’, 0); close();”
EXIT