locked
Remove-PSDrive not disconnecting network drives RRS feed

  • Question

  • Update: I think I figured it out.  I switched to using the Remove-SMBMapping command instead of Remove-PSDrive and it appears to be working.  Side note, if you try using SMBMapping, be aware that it wants the drive letter with the colon (Z:), where PSDrive wants just the letter (Z)

    I'm working on a script and the only part that doesn't work is the Remove-PSDrive command.  I've isolated each line and it's only this one not doing what I think it should.  And even when I run the command on its own it still doesn't work, nor does it give me any error

    As you can see from the screen grab it's not removing the Z drive.  Am I not understanding how this command works or am I doing something wrong?


    • Edited by WCELY Tuesday, August 20, 2019 7:45 PM Update
    Tuesday, August 20, 2019 3:58 PM

Answers

  • I see the same behavior. It appears that remove-psdrive only works on drives that have been mapped with new-psdrive.

    "--- Adding P drive ---"
    New-PSDrive -Name "P" -PSProvider "FileSystem" -Root "\\fs1\Engineering"
    "--- See if its there ---"
    Get-PSDrive P
    "--- Remove it ---"
    Remove-PSDrive P 
    "--- Still there? ---"
    Get-PSDrive P
    

    Just use net.exe in your script.

    net.exe use z: /del

    Tuesday, August 20, 2019 4:43 PM

All replies

  • I see the same behavior. It appears that remove-psdrive only works on drives that have been mapped with new-psdrive.

    "--- Adding P drive ---"
    New-PSDrive -Name "P" -PSProvider "FileSystem" -Root "\\fs1\Engineering"
    "--- See if its there ---"
    Get-PSDrive P
    "--- Remove it ---"
    Remove-PSDrive P 
    "--- Still there? ---"
    Get-PSDrive P
    

    Just use net.exe in your script.

    net.exe use z: /del

    Tuesday, August 20, 2019 4:43 PM
  • Is there a way to use a variable in the net.exe command for the drive letter?  I don't think everyone has the drives mapped to the same letters.
    Tuesday, August 20, 2019 5:22 PM
  • $letter = 'Z'
    $share = '\\server\share'
    net.exe use "$($letter):" $share
    Get-PSDrive $letter
    net.exe use "$($letter):" /del 

    Wednesday, August 21, 2019 12:11 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Friday, September 6, 2019 12:05 PM