Forum Discussion

MatthewMcDonald_ews's avatar
MatthewMcDonald_ews
Brass Contributor
May 20, 2022

New-SMBMapping not showing in Explorer until Explorer process is closed/restarted

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.

16 Replies

  • You could try using the New-PSDrive cmdlet. i.e.

    New-PSDrive -Name X -Root \\Fileserver\Share -PSProvider FileSystem

    This creates a mapping which is visible in Windows Explorer straight away, you can use the -Persist parameter to make it permanent. The New-SMBMapping is for the PowerShell session itself until it closes?
    • MatthewMcDonald_ews's avatar
      MatthewMcDonald_ews
      Brass Contributor
      No change. Anything I do within Powershell with drive letters is not reflected in the Explorer process.

      Note: I am using Windows 11.

      Further, I remember running into this problem a few months back but it only surfaced if I ever launched the script via the PS file from Explorer. If I launched it directly in Powershell, or simply manually typed the commands in Powershell it worked as expected. Now, all of a sudden, no matter what I do, if it's done in Powershell, Explorer will not see the change until it is restarted.
      • Harm_Veenstra's avatar
        Harm_Veenstra
        MVP
        I'm also using Windows 11, I typed the command in a Windows Terminal and.. Now it doesn't work for me also.. PowerShell 5 and 7 in Windows Terminal, but also from a script file... Which it did yesterday...I don't get it 🙂

Resources