PowerShell Logo Small

New-PSDrive



This is the built-in help made by Microsoft for the command 'New-PSDrive', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Creates a Windows PowerShell drive in the current session.

SYNTAX


New-PSDrive [-Name] <string> [-PSProvider] <string> [-Root] <string> [-Credential <PSCredential>] [-Description <string>] [-Scope <string>] [-Con
firm] [-WhatIf] [-UseTransaction] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


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

You can use the Windows PowerShell drives that you create to access data in the associated data store, just like you would do with any mapped dri
ve. You can change locations into the drive (using "set-location", "cd", or "chdir") and access the contents of the drive (using "get-item", "get
-childitem", or "dir").

However, the Windows PowerShell drives are known only to Windows PowerShell. You cannot access them by using Windows Explorer, Windows Management
Instrumentation (WMI), Component Object Model (COM), or the Microsoft .NET Framework, or by using tools such as Net Use.

Windows PowerShell drives exist only in the current Windows PowerShell session. To make the drive persistent, you can export the session to whic
h you have added the drive, or you can save a New-PSDrive command in your Windows PowerShell profile.

To delete a drive that was created by New-PSDrive, use the Remove-PSDrive cmdlet.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113357
about_Providers
Get-PSDrive
Remove-PSDrive

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

C:\PS>new-psdrive -name P -psprovider FileSystem -root \\Server01\Public

Name Provider Root
---- -------- ----
P FileSystem \\Server01\Public



Description
-----------
This command creates a Windows PowerShell drive that functions like a mapped network drive in Windows. The command creates a Windows PowerShell d
rive named P: that is mapped to the \\Server01\Public network share.

It uses the Name parameter to specify a name for the drive, the PSProvider parameter to specify the Windows PowerShell FileSystem provider, and t
he Root parameter to specify the network share.

When the command completes, the contents of the \\Server01\Public share appear in the P: drive. To see them, type: "dir p:".








-------------------------- EXAMPLE 2 --------------------------

C:\PS>new-psdrive -name MyDocs -psprovider FileSystem -root "C:\Documents and Settings\User01\My Documents" -Description "Maps to my My Documents
folder."

Name Provider Root
---- -------- ----
MyDocs FileSystem C:\Documents and Settings\User01\My Documents



Description
-----------
This command creates a Windows PowerShell drive that provides quick access to a local directory. It creates a drive named MyDocs: that is mapped
to the
"C:\Documents and Settings\User01\My Documents" directory on the local computer.

It uses the Name parameter to specify a name for the drive, the PSProvider parameter to specify the Windows PowerShell FileSystem provider, the R
oot parameter to specify the path to the My Documents folder, and the Description parameter to create a description of the drive.


When the command completes, the contents of the My Documents folder appear in the MyDocs: drive. To see them, type: "dir mydocs:".








-------------------------- EXAMPLE 3 --------------------------

C:\PS>new-psdrive -name MyCompany -psprovider Registry -root HKLM:\Software\MyCompany

Name Provider Root
---- -------- ----
MyCompany Registry HKEY_LOCAL_MACHINE\Software\MyCo...



Description
-----------
This command creates a Windows PowerShell drive that provides quick access to a frequently checked registry key. It creates a drive named MyCompa
ny that is mapped to the HKLM\Software\MyCompany registry key.

It uses the Name parameter to specify a name for the drive, the PSProvider parameter to specify the Windows PowerShell Registry provider, and the
Root parameter to specify the registry key.


When the command completes, the contents of the MyCompany key appear in the MyCompany: drive. To see them, type: "dir MyCompany:".








-------------------------- EXAMPLE 4 --------------------------

C:\PS>new-psdrive -name PsDrive -psprovider FileSystem -root \\Server01\Public

C:\PS> $drive = new-object -com wscript.network
C:\PS> $drive.MapNetworkDrive("X:", "\\Server01\Public")


C PS:\> get-psdrive public, x

Name Provider Root
---- -------- ----
PsDrive FileSystem \\Server01\public
X FileSystem X:\


C:\PS>get-psdrive psdrive, x | get-member

TypeName: System.Management.Automation.PSDriveInfo
Name MemberType Definition
---- ---------- ----------
CompareTo Method System.Int32 CompareTo(PSDriveInfo drive),
Equals Method System.Boolean Equals(Object obj),
GetHashCode Method System.Int32 GetHashCode()
...



C:\PS> net use
Status Local Remote Network
---------------------------------------------------------------------------
X: \\server01\public Microsoft Windows Network


C:\PS> get-wmiobject win32_logicaldisk | ft deviceid
deviceid
--------
C:
D:
X:

C:\PS> get-wmiobject win32_networkconnection
LocalName RemoteName ConnectionState Status
--------- ---------- --------------- ------
X: \\products\public Disconnected Unavailable



Description
-----------
This example shows the difference between a Windows drive that is mapped to a network share and a Windows PowerShell drive that is mapped to the
same network share.

The first command uses the New-PSDrive cmdlet to create a Windows PowerShell drive called PSDrive: that is mapped to the \\Server01\Public networ
k share.

The second set of commands uses the New-Object cmdlet to create a Wscript.Network COM object and then use its MapNetworkDrive method to map the \
\Server01\Public network share to the X: drive on the local computer.

Now, you can examine the two drives. Using a Get-PSDrive drive command, the drives appear to be the same, although the network share name appears
only in the root of the PSDrive: drive.

Sending the drive objects to Get-Member shows that they have the same object type, System.Management.Automation.PSDriveInfo.

However, a "net use" command, a Get-WmiObject command to the Win32_LogicalDisk class, and a Get-WmiObject command to the Win32_NetworkConnection
class find only the X: drive that was created by using the Wscript.Network object. That is because Windows PowerShell drives are known only to Wi
ndows PowerShell.

If you close the Windows PowerShell session and then open a new one, the PSDrive: drive is gone, and the X: drive persists.

Therefore, when deciding which method to use to map network drives, consider how you will use the drive, whether it needs to be persistant, and w
hether the drive needs to be visible to other Windows features.