Removing Shares (Remotely, Too)

Share |

Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Powershell Plus

13 Free SQL Tools from Idera

Free Ebook: Mastering Powershell


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()

Twitter This Tip! ReTweet this Tip!

Posted Dec 29 2011, 06:00 AM by ps1
Copyright 2012 All rights reserved.