简体   繁体   中英

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.

Thanks in Advance!

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.

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

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

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:

  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

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.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM