5

I'd like to mount an NFS share from Windows 2012 using PowerShell and have this mount be visible in contexts other than the PowerShell session that invoked it. If I use the New-PSDrive command (cmdlet?), e.g.:

New-PSDrive Z -PsProvider FileSystem -Root \\10.40.1.1\export\isos 

Then it will mount the NFS server to the Z drive, but I can't access this drive in, say, File Explorer.

0

4 Answers 4

1

Kernel Panic is correct about the PSDrive cmdlet being usable only within the PowerShell environment. The TechNet article ‘Using the New –PSDrive Cmdlet’ states ‘Mapped drives last only as long as your current Windows PowerShell session.’ However, you can create a configuration file that will re-map the drives every time you start PowerShell.

Further, the TechNet Article ‘Converting the Windows Script Host MapNetworkDrive Method’ also states that any drive created with the –PSDrive cmdlet ‘can be used exactly like any other mapped network drive as long as you are working in Windows PowerShell.’ This is a PowerShell Drive and not a true mapped drive. This article goes on to show that you can map drives in PowerShell using the Net Use command:

net use z: \\server\folder 

Hope this helps,

1
  • 2
    "‘Mapped drives last only as long as your current Windows PowerShell session." No, with the Persist flag it isn't bound to the session. Commented Jul 14, 2015 at 8:55
6

You need to use the Persist flag.

New-PSDrive Z -PsProvider FileSystem -Root \\10.40.1.1\export\isos -Persist 

-Persist

Creates a Windows mapped network drive. Mapped network drives are saved in Windows on the local computer. They are persistent, not session-specific, and can be viewed and managed in File Explorer and other tools. The name of the drive must be a letter, such as D or E. The value of the Root parameter must be a UNC path to a different computer. The value of the PSProvider parameter must be FileSystem. To disconnect a Windows mapped network drive, use the Remove-PSDrive cmdlet. When you disconnect a Windows mapped network drive, the mapping is permanently deleted from the computer, not just deleted from the current session. NOTE: Mapped network drives are specific to a user account. Mapped network drives that you create in sessions that are started with the "Run as administrator" option or with the credential of another user are not visible in session that started without explicit credentials or with the credentials of the current user.

See https://technet.microsoft.com/en-us/library/hh849829.aspx

0

My understanding is the PSDrive cmdlet, prior to Powershell 3, is a mapping between the shell and some data store. This will not carry outside of the 'shell'. Powershell 3.0 has the Persistent parameter which can do what you want.

2
  • I'm running PowerShell Version 3.0 on the server. If I add the '-persist' flag, I don't see a change in behavior. Commented May 20, 2013 at 18:16
  • Are you running it with elevated credentials? Are they different creds than the user for whom you are mapping the share? Commented May 20, 2013 at 18:21
0

FWIW, the CMD mount command used to work for me until I realized that, contrary to its' documented options, it only maps credentials (be it domain, LDS or system) of the logged in user, i.e., the user that started the command.

Given the UAC control is in place, this effectively means the command only works for one's user session, in other words, if you want to use alternate credentials, you need to use runas, which itself only lasts for the CMD session.

This is despite the fact it itself supports these options: -u:username -p:*.

There was a hotfix KB2684578, but it is "no longer available".

(According to the same KB article, the net command suffers from the same fallacy.)

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.