简体   繁体   English

映射的网络驱动器未显示在“我的电脑”中

[英]Mapped network drives are not showing in My Computer

I am trying to create a external network drive using PowerShell 5.0.我正在尝试使用 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.因为根据我的理解,如果我使用-Persist它应该显示在我的电脑窗口中。

After using this, the mapped drive X: is not being displayed in My Computer.使用后,映射的驱动器 X: 没有显示在我的电脑中。

Thanks in Advance!提前致谢!

Welcome to Windows 10 and the endless problems of forced User Account Control. 欢迎使用Windows 10以及强制用户帐户控制的无穷问题。

You will note if you map network drives in Computer then run PowerShell as admin, you cannot access the drives. 您将注意到,如果您在计算机中映射网络驱动器然后以管理员身份运行PowerShell,则无法访问驱动器。 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. 您只需要管理运行PowerShell的访问级别,映射网络驱动器必须在用户级别完成。

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). 我的解决方案是以“正常模式”而不是“管理员模式”(PS作为管理员运行)启动powershell ISE。 I don't know why this phenomen appears, but the drives were displayed in explorer after I run the powershell ISE in Normal-Mode. 我不知道为什么会出现这种现象,但在普通模式下运行PowerShell ISE后,驱动程序显示在资源管理器中。 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 当我粘贴到PowerShell窗口时,它可以工作,然后我可以看到该共享出现在这台PC中

I suppose you put the command inside a ps1 file.我想你把命令放在一个 ps1 文件中。 As explained in this official article: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-psdrive如这篇官方文章所述: 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.在调用 ps1 文件之前添加一个前导点。 Suppose your ps1 file is called MyDrive.ps1.假设您的 ps1 文件名为 MyDrive.ps1。 You have to run:你必须运行:
    . . .\\MyDrive.ps1 .\\MyDrive.ps1

  2. You have to use -Scope Global parameter in your command.您必须在命令中使用-Scope Global参数。 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 .当您想在 File explorer 中查看驱动器时,所有说您应该使用-Persistent或/和-Scope 'Global'的答案都是错误的

Even documentation in Microsoft Docs is wrong .甚至 Microsoft Docs 中的文档也是错误的

Mapping by PSDrive is useless. PSDrive 映射是没有用的。 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.您可以将网络路径保存在$Z并在脚本中将其用作路径,但用户需要在文件资源管理器中进行映射。 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.其他方式如(New-Object -ComObject "Wscript.Network").MapNetworkDrive("Z:", "\\\\192.168.20.100\\share", $True)New-SmbMapping -LocalPath 'Z:' -RemotePath "\\\\192.168.20.100\\share"对我不起作用。

You can get creative, learn how to manipulate with the windows and automate the UI creation of the mapping.您可以发挥创意,学习如何操作窗口并自动创建映射的 UI。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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