#PSTip Rename a local or a mapped drive using Shell.Application
In the ‘Create mapped network drive using WScript.Network‘ post, it was shown how a mapped drive can be mounted. The mapped drive doesn’t initially have a friendly name–only the name of the shared folder and the server name will be shown. In order to rename the drive using PowerShell, the Shell.Application COM object can be used. This code will allow you to rename a mapped network drive or any local disk:
$ShellObject = New-Object –ComObject Shell.Application $DriveMapping = $ShellObject.NameSpace('Z:') $DriveMapping.Self.Name = 'NewName'
To make this shorter the following one-liner can be used to rename a local drive:
(New-Object -ComObject Shell.Application).NameSpace('Z:').Self.Name='NewName'Share on: