New-PSDrive

Create a temporary or persistent mapped network drive. (ndr, mount)

Syntax
      New-PSDrive [-name] string -PSProvider string [-Persist]
         [-root] string [-description string] [-scope string]
            [-credential PSCredential] [-WhatIf] [-confirm] [-UseTransaction] [CommonParameters]

Key
   -name 
       The PowerShell drive name to be added.
       This is not limited to drive letters,any valid string may be used.
       PowerShell drives names are case-sensitive.

   -PSProvider 
       The name of the provider, if omitted you will be prompted.
       e.g. FileSystem, Registry or Certificate.
       type get-psprovider for a list of providers.

    -Persist
       Create a mapped network drive. Mapped network drives are persistent, not session-specific, and can be
       viewed and managed in File Explorer and other tools. (PowerShell 3.0+)

       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 mapped network drive, use Remove-PSDrive.
       When you disconnect a mapped network drive, the mapping is permanently deleted from the computer, not just
       deleted from the current session.

       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 a session that started without explicit credentials or
       with the credentials of the current user.

   -root string
       The data store location that the PowerShell drive will be mapped to.

       e.g. a network share (\\Server64\files), a local directory (C:\Programs),
       or a registry key (HKLM:\Software\Microsoft).

   -description string
       A short description of the drive.

   -scope 
       A scope for the drive.
       Valid values are "Global", "Local", or "Script", or a number relative
       to the current scope (0 through the number of scopes, where 0 is the
       current scope and 1 is its parent).
       "Local" is the default. For more information, see about_Scopes.

   -credential PSCredential
       A user account that has permission to perform this action.
       The default is the current user.
       a user-name, such as "User01" or "Domain01\User01", or a PSCredential
       object, such as the one retrieved by using the Get-Credential cmdlet.
       If you type a user name, you will be prompted for a password.
       This parameter is not supported by any providers installed with PowerShell.

   -whatIf
       Describe what would happen if you executed the command without
       actually executing the command.

   -confirm
       Prompt for confirmation before executing the command.

   -UseTransaction
       Include the command in the active transaction.

Standard Aliases for New-PSDrive: mount, ndr

On machines with PowerShell 5.0+ and Windows 10, the newer command New-SmbMapping is available.

In Q4471218 Mapped network drives are displayed as Unavailable when you run the NET USE command.
Microsoft's recommendation is to remap them with New-SmbMapping

New-PSDrive creates a PowerShell drive that is "mapped" to a location in a data store, such as a network drive, a directory on the local computer, or a registry key.

If a non-persistent drive is mapped (without the -Persist option) the drive will be visible only within PowerShell, not to Windows Explorer, net use or Get-CIMinstance Win32_NetworkConnection

Examples

Install a drive called 'SS64' using the file system provider. The drive will be rooted at "C:\MyDocs":

PS C:\> new-psdrive -name SS64 -psProvider FileSystem -root C:\MyDocs -persist
DIR SS64:

Install a drive called 'S:' using the file system provider. The drive will be rooted at \\Server64\teams:

PS C:\> new-psdrive -name S -PsProvider FileSystem -root \\Server64\teams -persist
S:
PS S:\> DIR S:

The parameters are positional, so
PS C:\> New-PSDrive -name M -psprovider FileSystem -root \\Server\Share

is the same as:
PS C:\> New-PSDrive M FileSystem \\Server\Share

"If the automobile had followed the same development cycle as the computer, a Rolls-Royce would today cost $100, get a million miles per gallon, and explode once a year, killing everyone inside" ~ Robert X. Cringely, InfoWorld

Related PowerShell Cmdlets

New-SmbMapping - Map to SMB share, (Windows 10).
Get-PSDrive - Get drive information (DriveInfo).
Remove-PSDrive - Remove a provider/drive from its location.
Get-Command - Retrieve basic information about a command.
Get-Member - Enumerate the properties of an object.
VBScript MapDrive - Map a Drive letter to a network file share.
Equivalent bash command: mount - Mount a file system.


 
Copyright © 1999-2024 SS64.com
Some rights reserved