May 20 2022 09:21 AM - edited May 20 2022 09:25 AM
I'm writing a script to remap drives to new paths (file server migration), and I had everything working. I'm using Remove-SMBMapping and New-SMBMapping.
While it was working there was a strange bug where it would only work if I pasted the code directly into powershell. But if I called the .ps1 script file, the drive mappings would change (as verified by NET USE from the command line), Explorer continued to show and use the old drive mappings. If I end process for Explorer.exe and re-run it, then it would show and use the new mappings. I just ignored this at the time.
Well now I'm doing some more testing, now no matter what I do, when using New-SMBMapping in any way, Explorer refuses to see the drive (even new mappings) while the system does see the correct drives via cmdline.
I'm at a complete loss as to why this is an issue. It occurs in both Powershell 7 as well as Windows Powershell 5.1.
Does anyone have a clue as to what is happening here?
FWIW I know that drives mapped in the standard UAC user context are not visible to admin contexts and vice versa. That is not the issue here. This is all under the same user context. No elevated admin sessions are at play. In fact, if it were this, restarting Explorer would have no affect.
Also this is an issue whether -persistent $true is used or not.
Finally, if I just simply use native Windows cmd prompt command "Net Use" to map the drive, even within the Powershell console, everything works as expected. This is only an issue using the powershell specific cmdlet to map the drive.
May 22 2022 10:42 AM
May 23 2022 01:22 PM
May 23 2022 01:33 PM
May 23 2022 01:34 PM
May 23 2022 01:54 PM
May 23 2022 01:58 PM
May 23 2022 02:01 PM
Jun 01 2022 04:25 AM
Jun 01 2022 07:57 AM
Jun 01 2022 08:03 AM
Jun 01 2022 08:28 AM
Oct 16 2022 11:09 PM
@MatthewMcDonald_ews i searched same stuff like crazy the ansmwer is as such (and so badly documented you would want to scream aloud !
basically you need to use new-psdrive and add -scope global to your script and.... it works like a charm !
New-PSDrive -Name "J" -Root "UNC" -Persist -PSProvider "FileSystem" -scope global
hope this helps ....
kind regards
David
Nov 14 2022 11:32 PM
Nov 15 2022 05:09 AM
@KieranCork i've moved away from new-smbmapping and use new-psdrive instead... is this the on you used ?
Nov 15 2022 06:36 AM
@davidblum_dbciYeah, New-PSDrive is what I've been using. I'm pointing to a local directory (OneDrive), so perhaps that is the issue, as it doesn't let you use "-Persist" either.