2

I'm trying to map a drive to another server using a "system" account in powershell. I am successful but then the server is only accessible if logged in as system, but not as administrator or regular user.

If I map it using an administrator powershell or dos command shell, then it is available to everyone. Unfortunately I cannot do that because I am using Amazon Web Service (AWS) SendCommand feature to do the mapping and it only uses the system level powershell. Even if I put the mapping command within a batch file and have it run that, the mapped drive still is only available to system powershell user.

Here is an example of the two commands that are sent via AWS SendCommand:

cd "C:/Program Files/Enventive/EnCOM Listener 1.0/lib/"
start-process "cmd.exe" "/c MapNetworkDrive 172.31.26.59"

The batch file does a net use command like this:

net use D: \\%1\Company /USER:Administrator /PERSISTENT:YES "<password>"

Is there any way to have a drive mapped by a system level powershell be available to all users?

I have also tried the following method from within a system level powershell but got the same result:

$user = "Administrator"
$pass = ConvertTo-SecureString -String '<password>' -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user,$pass
New-PSDrive -Name D -PSProvider FileSystem -Root \\172.31.26.59\Company -Credential $cred -Persist

After doing this the D: drive was available from within the system level powershell, but not from a DOS command shell or Administrator level powershell

I also tried:

$net = new-object -ComObject WScript.Network
$net.MapNetworkDrive("D:", "\\172.31.26.59\Company", $false, "Administrator", '<password>')

Got the same result. In all attempts, what shows in File Explorer is "Disconnected Network Drive (D:)" and if I click on it a popup says "D:\ is not accessible. The user name or password is incorrect."

4
  • When using New-PSDrive, have you tried adding -Scope Global?
    – root
    May 3, 2018 at 16:06
  • Just tried and now it says: "New-PSDrive : A specified logon session does not exist. It may already have been terminated"
    – tekknow
    May 3, 2018 at 16:28
  • I had previously done: net use D: /DELETE
    – tekknow
    May 3, 2018 at 16:38
  • I was able to get rid of the New-PSDrive using: Remove-PSDrive -Name D. Then I could add it back in with the -Scope Global option. Unfortunately, same result.
    – tekknow
    May 3, 2018 at 16:42

1 Answer 1

2

Is there any way to have a drive mapped by a system level powershell be available to all users? No.

New-PSDrive

Mapped network drives are specific to a user account. Mapped network drives that you create in sessions that are started by using the Run as administrator option or by using the credential of another user are not visible in a session that was started without explicit credentials, or by using the credentials of the current user.

By the way, you can run into drive letter collisions assigning a mapped drive letter to D

A and B are typically reserved for the floppy drives of last century, and C and D are usually reserved for the hard drive and optical drive, so the card reader will use E, F, G, and H.

2
  • I'll give you credit for the answer even if I don't believe there is not a way to do it. The SYSTEM user is supposed to be able to do anything. The way I resolved it was to put the "net use" command in a batch file and place it in the Windows startup folder. Then did a reboot so it would run.
    – tekknow
    May 4, 2018 at 14:20
  • @tekknow mapping particular drives to particular shares is typical task for a logon script. You could set up such a logon script easy in an Active Directory environment. However, there is a way to do it in a workgroup environment or even in a peer-to-peer network. Google for windows logon script; please ask another question in doubts.
    – JosefZ
    May 4, 2018 at 18:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .