8/26/2023 0 Comments Mapped drives in registry![]() By default, the cmdlet will output the results of the drive mapping. Note that we added | Out-Null to the cmdlet. New-PSDrive -Name Log -PSProvider FileSystem -Root c:\temp\logfiles -Description "Log Folder" | Out-Null In your PowerShell profile add the following line: # Create shotcuts to long folder paths If you get an error that your profile is not found, then follow this article to quickly create one. This way the mapping will be recreated every time you open PowerShell. But when you need to access a long folder path often from PowerShell then you could add the cmdlet to your PowerShell Profile. ![]() There is no option to store mappings to local folders with New-PSDrive. Temporary mappings are gone after you close the PowerShell window. For example: Get-ChildItem log: new-PSDrive Creating a persistent mapping to a local folder But we can not only navigate to the folder, we now also reference the mapping in other cmdlets. This way we can quickly navigate to the log files with cd log. Also, we can create a mapping to a local folder on our computer.įor example, we can create a mapping to our log folder with: New-PSDrive -Name Log -PSProvider FileSystem -Root c:\temp\logfiles -Description "Log Folder" We can give any name we want to the mapping. With temporary mappings, we are not limited to letters only. New-PSDrive -Name V -PSProvider FileSystem -Root \\VBoxSvr\Win11 -Persist -Credential $cred Creating a Temporary Drive Mapping in PowerShellĪs mentioned we can also create a temporary drive mapping with PowerShell. # Create the drive mapping with the credentials For this, we first need to create a credential object that we can use to map the network drive. Just like with Net Use we can use different credentials to open a remote network drive. Using different credentials for the mapped network drive ![]() The network location will now be available in Explorer or any other tool that you want to use. So to map the network share \\VBoxSvr\Win11 and assign it the drive letter v: we can use the following command: New-PSDrive -Name V -PSProvider FileSystem -Root \\VBoxSvr\Win11 -Persist New-PSDrive network mapping To make it available outside PowerShell (in Explorer) The network location that you want to map Set to FileSystem for network shares and folders There are a couple of required parameters to create a network connection: Parameter This way the network drive will be available in Explorer and other tools and not only in PowerShell. To map a network drive with PowerShell, we are going to create a persistent network connection. Adding a new network drive with New-PSDrive They will remain available when you close the PowerShell session or even reboot your computer. Persistent drives are assigned a drive letter and therefore can also be used in Explorer. They are great to use when you need to interact with a remote folder or a long folder path on your local computer. They won’t be visible in Windows Explorer and will be gone when you close the PowerShell session. Temporary drives can only be used in the current PowerShell session. Temporary vs Persistent drivesīefore we are going to take a look at how to create the network drives, I first want to explain the difference between temporary and persistent drives. In this article, we are going to take a closer look at all the possibilities of the New-PSDrive cmdlet with some useful examples for you to use. Drives created with the cmdlet can be temporary for only the current PowerShell sessions or persistent so they can be used in explorer. ![]() With the New-PSDrive cmdlet, we cannot only map network drives but also create drive mappings to local folders or registry keys on our computer. Although we can use Net Use in PowerShell, there is a more powerful alternative, the New-PSDrive cmdlet. We all know the Net Use command that we can use to map network drives from the command line.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |