This write-up will elaborate on the “New-PSDrive” cmdlet in PowerShell.
“net use” in PowerShell Without Specifying Drive
As stated above, the alternative of the “net use” cmdlet in PowerShell is the “New-PSDrive”. This cmdlet is responsible for creating temporary and persistent drives and then mapping them to a network server.
Examples related to the above-discussed cmdlet are demonstrated below.
Example 1: Utilize the Cmdlet “New-PSDrive” to Create a Temporary Network Drive
To create a temporary network drive and then mapped to a network, provided cmdlet can be used:
In the above code statement:
- First, write the “New-PSDrive” cmdlet.
- Then, specify the parameter “-Name” and assign it the value “Public”.
- After that, write the parameter “-PSProvider” parameter and specify the value “FileSystem” to it.
- Lastly, add another parameter “-Root” and define it as the server address.
Example 2: Use the “New-PSDrive” Cmdlet to Create a Temporary Drive Mapped to a Local Directory
Create a temporary drive and then mapped to a local directory by running the following command:
Name = "Docs"
PSProvider = "File_System"
Root = "C:\Users\User01\Documents"
Description = "Map this to the Documents folder."
}
New-PSDrive @new_param
According to the above script code:
- First, create a hash-table and assign it to the “$new_param”.
- Inside a hash-table, create variables and assign the stated values to them, including name, PSProvider, directory location, and description.
- Lastly, call the hash-table with the aid of the “New-PSDrive” cmdlet.
Example 3: Use the “New-PSDrive” Cmdlet to Create a Temporary Drive for a Registry Key
In this illustration, the temporary drive will be created for a registry key:
In the above-provided code:
- First, add the “New-PSDrive” cmdlet, followed by the “-Name” parameter having the value of “Company”.
- After that, add another parameter “-PSProvider” and assign it the value “Registry” value.
- Lastly, specify the “-Root” parameter and define the registry value “HKLM:\Software\Company” to it.
Example 4: Use the “New-PSDrive” Cmdlet to Create a Persistent Drive
To create a persistent network drive, execute the below-given command:
In the above-discussed command:
- First, write the “New-PSDrive” cmdlet along with the “-Name” parameter having the value “V” assigned to it.
- Then, add the “-PSProvider” parameter and assign the value “FileSystem”.
- Add the “-Root” parameter and mention the server drive.
- Lastly, add the “-Persist” parameter to create a persistent drive.
We have provided the usage of the “New-PSDrive” cmdlet in PowerShell without specifying the drive.
Conclusion
The CMD “net use” cmdlets alternative in PowerShell is the “New-PSDrive”. The “New-PSDrive” creates the drives including persistent and temporary. Moreover, it maps the created drives to both local and remote computers. This blog explained the CMD “net use” cmdlets alternative which is “New-PSDrive” in PowerShell.