PowerShell is a powerful scripting language that can be used to manage and automate many tasks on Windows systems. One of the most useful commands in PowerShell is the New-PSDrive command, which allows users to map a network drive to their local computer. This command is especially useful for administrators who need to access network resources quickly and easily. In this article, we will explore the New-PSDrive command in detail, including its syntax, parameters, inputs, outputs, examples, and tips.
What is the New-PSDrive Command?
The New-PSDrive command is a PowerShell command that allows users to map a network drive to their local computer. This command is especially useful for administrators who need to access network resources quickly and easily. The New-PSDrive command can be used to create a persistent connection to a network resource, which means that the connection will remain active even after the user logs off or the computer is restarted.
Syntax and Parameters
The syntax for the New-PSDrive command is as follows:
New-PSDrive [-Name] <String> [-PSProvider] <String> [-Root] <String> [-Description <String>] [-Credential <PSCredential>] [-Persist] [-Scope <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
The parameters for the New-PSDrive command are as follows:
Parameter | Description |
---|---|
Name | The name of the new drive. |
PSProvider | The type of provider to use for the new drive. |
Root | The root of the new drive. |
Description | A description of the new drive. |
Credential | The credentials to use for the new drive. |
Persist | Specifies whether the drive is persistent or not. |
Scope | The scope of the new drive. |
WhatIf | Specifies whether to display what would happen if the command is run. |
Confirm | Specifies whether to prompt for confirmation before running the command. |
Inputs and Outputs
The New-PSDrive command requires the following inputs:
- Name: The name of the new drive.
- PSProvider: The type of provider to use for the new drive.
- Root: The root of the new drive.
- Description: A description of the new drive.
- Credential: The credentials to use for the new drive.
- Persist: Specifies whether the drive is persistent or not.
- Scope: The scope of the new drive.
The New-PSDrive command does not produce any output.
Examples
The following example shows how to create a persistent connection to a network resource:
New-PSDrive -Name “MyDrive” -PSProvider FileSystem -Root “\\server\share” -Persist
The following example shows how to create a non-persistent connection to a network resource:
New-PSDrive -Name “MyDrive” -PSProvider FileSystem -Root “\\server\share”
The following example shows how to create a connection to a network resource with credentials:
New-PSDrive -Name “MyDrive” -PSProvider FileSystem -Root “\\server\share” -Credential (Get-Credential)
Tips
Here are some tips for using the New-PSDrive command:
- Make sure you have the correct permissions to access the network resource.
- If you are creating a persistent connection, make sure to use the -Persist parameter.
- If you are creating a connection with credentials, make sure to use the -Credential parameter.
- If you are creating a connection with a scope, make sure to use the -Scope parameter.
- If you are unsure of what would happen if you run the command, use the -WhatIf parameter.
- If you are unsure if you want to run the command, use the -Confirm parameter.
Conclusion
The New-PSDrive command is a powerful PowerShell command that allows users to map a network drive to their local computer. This command is especially useful for administrators who need to access network resources quickly and easily. The New-PSDrive command has a variety of parameters that can be used to customize the connection, including the name, provider, root, description, credentials, persist, scope, whatif, and confirm parameters. With these parameters, users can create persistent or non-persistent connections to network resources with or without credentials. By following the syntax and parameters outlined in this article, users can easily create a connection to a network resource using the New-PSDrive command.