# Credentioal PSDrive

**URL:** <https://forums.powershell.org/t/credentioal-psdrive/8845>\
**Category:** PowerShell Help\
**Created:** [June 16, 2017, 7:47am UTC](https://forums.powershell.org/t/credentioal-psdrive/8845 "2017-06-16T07:47:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![windows-liveuser63](https://avatars.discourse-cdn.com/v4/letter/w/9dc877/32.png) [@windows-liveuser63](https://forums.powershell.org/u/windows-liveuser63)\
**Post date:** [June 16, 2017, 7:47am UTC](https://forums.powershell.org/t/credentioal-psdrive/8845/1 "2017-06-16T07:47:22Z")

</div>

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

New-PSDrive -Name “Z” -PSProvider FileSystem -Root “\upi503\root” -Persist -Credential $cred

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)

Is where any way i can add this to the script?

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [June 16, 2017, 7:50am UTC](https://forums.powershell.org/t/credentioal-psdrive/8845/2 "2017-06-16T07:50:11Z")

</div>

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.

Or, use NET USE instead and see if that works.

---

<div class="post-metadata">

**Author:** ![windows-liveuser63](https://avatars.discourse-cdn.com/v4/letter/w/9dc877/32.png) [@windows-liveuser63](https://forums.powershell.org/u/windows-liveuser63)\
**Post date:** [June 16, 2017, 8:03am UTC](https://forums.powershell.org/t/credentioal-psdrive/8845/3 "2017-06-16T08:03:08Z")

</div>

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

Output

New-PSDrive : Access is denied  
At line:1 char:1

- New-PSDrive -Name “Z” -PSProvider FileSystem -Root “\server\share” -Persist
- 

```auto
  + CategoryInfo : InvalidOperation: (Z:PSDriveInfo) [New-PSDrive], Win32Exception
  + FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand
```

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [June 16, 2017, 8:06am UTC](https://forums.powershell.org/t/credentioal-psdrive/8845/4 "2017-06-16T08:06:19Z")

</div>

Ah, That is a good extra detail ;).

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.

---

<div class="post-metadata">

**Author:** ![windows-liveuser63](https://avatars.discourse-cdn.com/v4/letter/w/9dc877/32.png) [@windows-liveuser63](https://forums.powershell.org/u/windows-liveuser63)\
**Post date:** [June 19, 2017, 1:01am UTC](https://forums.powershell.org/t/credentioal-psdrive/8845/5 "2017-06-19T01:01:52Z")

</div>

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

:ADMINTASKS

powershell -file “c:\install\map\_root.ps1”

EXIT

---

<div class="post-metadata">

**Author:** ![windows-liveuser63](https://avatars.discourse-cdn.com/v4/letter/w/9dc877/32.png) [@windows-liveuser63](https://forums.powershell.org/u/windows-liveuser63)\
**Post date:** [June 20, 2017, 8:00am UTC](https://forums.powershell.org/t/credentioal-psdrive/8845/6 "2017-06-20T08:00:55Z")

</div>

just want to inform u that i solve this with above bat file and the map\_root.ps1 file is edited like

New-PSDrive -Name “Z” -PSProvider FileSystem -Root “\sever\share” -Persist -Credential $cred

With this users have to login to the share. (same cred as their are login as to the server)

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:38pm UTC](https://forums.powershell.org/t/credentioal-psdrive/8845/7 "2024-05-16T20:38:31Z")

</div>

Closed on May 16, 2024, 8:38pm UTC


