Unable to delete Azure File Share mapped drive

Bryan McMurray 36 Reputation points Microsoft Employee
2020-09-07T19:09:36.19+00:00

Hi,

I have an Azure File Share, and used the recommended script to map a drive for an off-premise device.
(Poweshell)

    cmd.exe /C "cmdkey /add:`"XYZ.file.core.windows.net`" /user:`"Azure\ABC`" /pass:`"123`""
    New-PSDrive -Name Z -PSProvider FileSystem -Root "\\XYZ.file.core.windows.net\xyz" -Persist

This works fine, now I need to remove this connection. I did:
(Powershell)

Remove-PSDrive -Name Z

.The drive is removed from file explorer. I followed up with:

cmd.exe /C "cmdkey /delete:`"XYZ.file.core.windows.net`""

output: CMDKEY: Credential deleted successfully.

Nevertheless, if I access \XYZ.file.core.windows.net it opens just fine.
I need to completely remove this access. What am I missing here?

Thank you for anyone who can help.

Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,188 questions
0 comments No comments
{count} vote

Accepted answer
  1. Prafulbusa 91 Reputation points Microsoft Employee
    2020-09-08T00:22:35.377+00:00

    Try running this command ==> net use Z: /delete

    Also, you can restart system and try opening, it will no longer allow you to access.

    As it seems that command removed the mapped drive but it's able to access that's interesting.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Bryan McMurray 36 Reputation points Microsoft Employee
    2020-09-10T23:18:48.53+00:00

    Indeed a system restart appears to resolve the issue.
    It is normally a basic thing to do to fix many mundane issues, but is bizarre that something like this needs a system restart. Once you delete a credential, the system should not be able to connect from that point on.
    I guess I will just have to remember this security loophole.
    cmdkey /delete only takes effect if followed by a restart. Was unaware of this.

    1 person found this answer helpful.
    0 comments No comments