Monday, January 9, 2012

Removing Shares (Remotely, Too) using PowerShell


PowerTip of the Day, from


Removing Shares (Remotely, Too)

In a previous tip you learned how you can create ad-hoc shares using WMI. These shares persist until you remove them again. So if you'd like to clean up behind you, here is a one-liner that removes a share locally or remote:

PS> ([wmi]'\\Storage1\root\cimv2:Win32_Share="Hidden"').Delete()

Just replace "Hidden" with the name of the share you want to delete, and replace "storage1" with the name or IP address of the target system. If you want to delete a share on your local system, remove the server name altogether:

PS> ([wmi]'root\cimv2:Win32_Share="Hidden"').Delete()



No comments:

Post a Comment