Mapped network drives are not showing in My Computer
Asked Answered
W

5

6

I am trying to create a external network drive using PowerShell 5.0. I Need those drive to display in My Computer. For that purpose I am using this follow command.

New-PSDrive -Name "X" -PSProvider FileSystem -Root "\\192.168.0.1\hde_path" -Persist

Is there anything wrong with this command? Because as per my understanding if I use -Persist it is should be displayed in the My Computer window.

After using this, the mapped drive X: is not being displayed in My Computer.

Wayfaring answered 24/2, 2017 at 10:1 Comment(4)
Did you run the command in a powershell window running in the same user context of your logged on user?Taphouse
Yes @LucaClavarinoWayfaring
Can you see a "X" key in the registry under HKEY_CURRENT_USER\Network? Get-ChildItem X: shows you the right content of your share?Taphouse
What do you get if you run net usePyrrhonism
M
0

Welcome to Windows 10 and the endless problems of forced User Account Control.

You will note if you map network drives in Computer then run PowerShell as admin, you cannot access the drives. I assume the reverse is also true.

Unfortunately there isn't a way to turn off this "feature", at least not without breaking half of everything else. You just have to manage the access level you run PowerShell as, mapping network drives has to be done at the user level.

Mailman answered 24/2, 2017 at 12:59 Comment(0)
W
8

I had the same problem. My solution was to start the powershell ISE in "Normal-Mode" instead of the "Administrator-Mode" (PS run as Admin). I don't know why this phenomen appears, but the drives were displayed in explorer after I run the powershell ISE in Normal-Mode. Greets

Worldweary answered 27/2, 2018 at 8:24 Comment(2)
What is normal mode? If I use $identity = [Security.Principal.WindowsIdentity]::GetCurrent() $principal = New-Object Security.Principal.WindowsPrincipal $identity $isAdmin = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) I get false. Am I in normal mode? In this mode, I cannot see a mapped drive in explorer.Tsuda
Oddly this works .. Only Microsoft can account for such an issue . 'Support Ticket Generator' Otherwise known as an STG.Warder
P
2

I suppose you put the command inside a ps1 file. As explained in this official article: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-psdrive

You have two solutions:

  1. You add a leading dot before calling the ps1 file. Suppose your ps1 file is called MyDrive.ps1. You have to run:
    . .\MyDrive.ps1

  2. You have to use -Scope Global parameter in your command. Your code should have been

    New-PSDrive -Name "X" -PSProvider FileSystem -Root "\\192.168.0.1\hde_path" -Scope Global -Persist

Good luck

Pictor answered 10/7, 2021 at 14:58 Comment(0)
H
1

When I run this from a script, it does not work, because the session expires on script completion.

It works when I paste into the PowerShell window, and then I can see the share appear in This PC

Hypognathous answered 20/10, 2018 at 14:20 Comment(1)
Great, seems that the script execution is like a subshell in linux.Tsuda
T
1

All the answers saying you should use -Persistent or/and -Scope 'Global' are wrong in scenario when you want to see the drive in File explorer.

Even documentation in Microsoft Docs is wrong.

Mapping by PSDrive is useless. You can save the network path in $Z and use it in your scripts as a path but users need the mapping in File Explorer. This scenario is not covered... Easily.

Other ways like (New-Object -ComObject "Wscript.Network").MapNetworkDrive("Z:", "\\192.168.20.100\share", $True) or New-SmbMapping -LocalPath 'Z:' -RemotePath "\\192.168.20.100\share" did not worked for me.

You can get creative, learn how to manipulate with the windows and automate the UI creation of the mapping.

enter image description here

Taverner answered 31/10, 2021 at 23:24 Comment(2)
You are right, but you are not providing an answer! What's is the solution?Unending
@Unending "You can get creative, learn how to manipulate with the windows and automate the UI creation of the mapping."Taverner
M
0

Welcome to Windows 10 and the endless problems of forced User Account Control.

You will note if you map network drives in Computer then run PowerShell as admin, you cannot access the drives. I assume the reverse is also true.

Unfortunately there isn't a way to turn off this "feature", at least not without breaking half of everything else. You just have to manage the access level you run PowerShell as, mapping network drives has to be done at the user level.

Mailman answered 24/2, 2017 at 12:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.