Removing a PS drive is quite easy. You can do so by just running the
Remove‑PSDrive command and enter the name of the drive. First, I'll run
Get‑PSDrive command, and we can see that apart from default drives, there
are custom PS drives that we created earlier.
I'll remove K drive using Remove‑PSDrive command. You can also mention
multiple PS drives separated by comma. I'll now run Remove‑PSDrive command
followed by drive names. I'll enter RootCA and PowershellCoreRegistry drives
that we created and hit Enter. Next, I'll try to remove S drive that was
created from PowerShell profile.
We can see that the K drive, the rootCA drive,
and the PowershellCoreRegistry drive got removed, but S drive still persists,
that's because this drive was created from PowerShell
profile, and hence, it won't be removed.
Likewise, you cannot remove Windows physical and logical drives, so
if I try to remove D and E drive and run Get‑PSDrive command, we
can see these drives are still intact.
You can also remove default drives using Remove‑PSDrive command.
So when I try to remove alias HKCU and Temp drive, these drives will be removed. We can verify this by running Get‑PSDrive command.