简体   繁体   中英

Powershell Map Network Drive, write file to it but Notepad fails to find file

My Powershell script:

New-PSDrive -Name J -Root \\myserver\mypath -PSProvider FileSystem
"test" | Out-File J:\test.txt
Get-Content -Path J:\test.txt
notepad J:\test.txt

J drive maps ok, the file gets created, Get-Content can read it BUT notepad (or any .exe) cannot see the file.

What should I do to make the drive mapping visible to other executables run within the script?

Thanks.

New-PSDrive by default creates drives that are visible only to PowerShell commands , in the same session.

To create a regular mapped drive that all processes see, use the -Persist switch , in which case you're restricted to the usual single-letter drive names (such as J: in your example).

Note: Despite the switch's name, the resulting mapping is only persistent (retained across OS sessions) if you either invoke it directly from the global scope of your PowerShell session (possibly by dot-sourcing a script that contains the New-PSDrive call from there) or explicitly use -Scope Global .

Otherwise, the mapping goes out of scope (is removed) along with the scope in which it was defined.

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