CmdID / PowerShell / Cmdlets / New
New-PSDrive
Creates temporary and persistent drives that are associated with a location in an item data store. PowerShell reference
From the PowerShell reference
10 parameters
Aliases mount, ndr
What it does
Creates temporary and persistent drives that are associated with a location in an item data store. The New-PSDrive cmdlet creates temporary and persistent drives that are mapped to or associated with a location in a data store, such as a network drive, a directory on the local computer, or a registry key, and persistent Windows mapped network drives that are associated with a file system location on a remote computer. Temporary drives exist only in the current PowerShell session and in sessions that you create in the current session. They can have any name that is valid in PowerShell and can be mapped to any local or remote resource. You can use temporary PowerShell drives to access data in the associated data store, just as you would do with any mapped network drive. You can change locations into the drive, by using Set-Location, and access the contents of the drive by using Get-Item or Get-ChildItem. Because temporary drives are known only to PowerShell, you can't access them by using File Explorer, Windows Management Instrumentation (WMI), Component Object Model (COM), Microsoft .NET Framework, or with tools such as net use. The following features were added to New-PSDrive in PowerShell 3.0: - Mapped network drives. You can use the Persist parameter of New-PSDrive to create Windows mapped network drives. Unlike temporary PowerShell drives, Windows mapped network drives aren't session-specific. They're saved in Windows and they can be managed by using standard Windows tools, such as File Explorer and net use. Mapped network drives must have a drive-letter name and be connected to a remote file system location. When your command is scoped locally, no dot-sourcing, the Persist parameter doesn't persist the creation of a PSDrive beyond the scope in which the command is running. If you're running New-PSDrive inside a script, and you want the drive to persist indefinitely, you must dot-source the script. For best results, to force a new drive to persist indefinitely, add the Scope parameter to your command, and set its value to Global. For more information about dot-sourcing, see about_Scripts. - External drives. When an external drive is connected to the computer, PowerShell automatically adds a PSDrive to the file system that represents the new drive. You don't have to restart PowerShell. …
New-PSDrive [-Name] <String> [-PSProvider] <String> [-Root] <String> [-Description <String>] [-Scope <String>] [-Persist] [-Credential <PSCredential>] [-WhatIf] [-Confirm] [-UseTransaction] [<CommonParameters>]
Create a temporary drive mapped to a network share
New-PSDrive -Name "Public" -PSProvider "FileSystem" -Root "\\Server01\Public"IdentifyCreate a temporary drive mapped to a local directory
$parameters = @{
Name = "MyDocs"
PSProvider = "FileSystem"
Root = "C:\Users\User01\Documents"
Description = "Maps to my My Documents folder."
}
New-PSDrive @parametersIdentifyCreate a temporary drive for a registry key
New-PSDrive -Name "MyCompany" -PSProvider "Registry" -Root "HKLM:\Software\MyCompany"IdentifyCreate a persistent mapped network drive using credentials
$cred = Get-Credential -Credential Contoso\ServiceAccount
New-PSDrive -Name "S" -Root "\\Server01\Scripts" -Persist -PSProvider "FileSystem" -Credential $cred
Net UseIdentifyTrips 1 Sigma rule: lowSystem Network Connections Discovery Via Net.EXE by frack113
Create persistent and temporary drives
# Create a temporary PowerShell drive called PSDrive:
# that's mapped to the \\Server01\Public network share.
New-PSDrive -Name "PSDrive" -PSProvider "FileSystem" -Root "\\Server01\Public"
# Use the Persist parameter of New-PSDrive to create the X: mapped network drive,
# which is also mapped to the \\Server01\Public network share.
New-PSDrive -Persist -Name "X" -PSProvider "FileSystem" -Root "\\Server01\Public"
# Now, you can use the Get-PSDrive drive cmdlet to examine the two drives.
# The drives appear to be the same, although the network share name appears only
# in the root of the PSDrive: drive.
Get-PSDrive -Name "PSDrive", "X"IdentifyCreate persistent drive in a script
New-PSDrive -Persist -Name "X" -PSProvider "FileSystem" -Root "\\Server01\Public" -Scope GlobalIdentifyIts page in the reference: New-PSDrive.
Parameters
-CredentialSpecifies a user account that has permission to do this action. The default is the current user.
Since PowerShell 3.0, when the value of the Root parameter is a UNC path, you can use credentials to create file system drives.
Credentials are stored in a PSCredential object and the password is stored as a SecureString.
NOTE: For more information about SecureString data protection, see How secure is SecureString?.-DescriptionSpecifies a brief text description of the drive. Type any string.
To see the descriptions of all the session's drives, Get-PSDrive | Format-Table Name, Description.
To see the description of a particular drive, type (Get-PSDrive <DriveName>).Description.-NameSpecifies a name for the new drive. For persistent mapped network drives, use a drive letter. For temporary PowerShell drives, you aren't limited to drive letters, use any valid string.-PersistIndicates that this cmdlet creates a Windows mapped network drive. The Persist parameter is only available on Windows.
Mapped network drives are saved in Windows on the local computer. They're persistent, not session-specific, and can be viewed and managed in File Explorer and other tools.
When you scope the command locally, without dot-sourcing, the Persist parameter doesn't persist
the creation of a PSDrive beyond the scope in which you run the command. If you run
New-PSDrive inside a script, and you want the new drive to persist indefinitely, you must
dot-source the script. For best results, to force a new drive to persist, specify Global as the
value of the Scope parameter and include Persist in your command.
The name of the drive must be a letter, such as D or E. The value of Root parameter must be a UNC path of a different computer. The PSProvider parameter's value 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.
Mapped network drives are specific to a user account. …-PSProviderSpecifies the PowerShell provider that supports drives of this kind.
For example, if the drive is associated with a network share or file system directory, the PowerShell provider is FileSystem. If the drive is associated with a registry key, the provider is Registry.
Temporary PowerShell drives can be associated with any PowerShell provider. Mapped network drives can be associated only with the FileSystem provider.
To see a list of the providers in your PowerShell session, use the Get-PSProvider cmdlet.-RootSpecifies the data store location to which a PowerShell drive is mapped.
For example, specify a network share, such as \\Server01\Public, a local directory, such as C:\Program Files, or a registry key, such as HKLM:\Software\Microsoft.
Temporary PowerShell drives can be associated with a local or remote location on any supported provider drive. Mapped network drives can be associated only with a file system location on a remote computer.-ScopeSpecifies a scope for the drive. The acceptable values for this parameter are: Global, Local, and Script, or a number relative to the current scope. Scopes number 0 through the number of scopes. The current scope number is 0 and its parent is 1. For more information, see about_Scopes.-UseTransactionIncludes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see about_Transactions.-ConfirmPrompts you for confirmation before running the cmdlet.-WhatIfShows what would happen if the cmdlet runs. The cmdlet isn't run.