'Mapped network drives are not showing in My Computer
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.
Solution 1:[1]
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.
Solution 2:[2]
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
Solution 3:[3]
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
Solution 4:[4]
I suppose you put the command inside a ps1 file. As explained in this official article: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-psdrive
You have two solutions:
You add a leading dot before calling the ps1 file. Suppose your ps1 file is called MyDrive.ps1. You have to run:
. .\MyDrive.ps1You have to use
-Scope Global
parameter in your command. Your code should have beenNew-PSDrive -Name "X" -PSProvider FileSystem -Root "\\192.168.0.1\hde_path" -Scope Global -Persist
Good luck
Solution 5:[5]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Deadly-Bagel |
Solution 2 | Lorchi |
Solution 3 | mcolhoun |
Solution 4 | SEAKTF |
Solution 5 | KUTlime |