VB Script: Delete multiple shares on a server with deleting the C$ and D$ share.Hi, I have just recently been thrown into VB Scripting as a means to make me and my fellow admin's jobs a bit easier. Right now we are migrating about 1000 user shares off a server and onto a new CIF. I wrote a script for this that lists all user folders in a directory (all of them are shared folders) and then runs that list (a saved txt file) through a loop that first unshares their drive, then xcopy's their data to the new server. The script runs...but it is extremely slow. I'm pretty sure it is getting hung up on querying all of the shares via:<br/> <div style="color:Black;background-color:White"> <pre><span style="color:Blue">Set</span> objWMIService = GetObject(<span style="color:#a31515">&quot;winmgmts:&quot;</span> _ &amp; <span style="color:#a31515">&quot;{impersonationLevel=impersonate}!\\&quot;</span> &amp; strServer &amp; <span style="color:#a31515">&quot;\root\cimv2&quot;</span> ) <span style="color:Blue">Set</span> colShares = objWMIService.ExecQuery _ (<span style="color:#a31515">&quot;Select * from Win32_Share Where Name = '&quot;</span> &amp; strUsrShare &amp; <span style="color:#a31515">&quot;'&quot;</span> ) <span style="color:Blue">For</span> <span style="color:Blue">Each</span> objShare <span style="color:Blue">in</span> colShares objShare.Delete <span style="color:Blue">Next</span> </pre> </div> As we have over 1000 shares on that server. So I figure it might be easier on the front end to delete all shares then migrate their data. However I can't delete the standard C$ and D$ share, as that is how I am xcopying their data over. But I am specifically noticing the &quot;Select * from Win32_Share&quot; in that snippet of code and was wondering if there is a way to select all the shares that start with &quot;a&quot; and so on and so forth (i.e. a*).<br/> <br/> If anyone has any ideas, thoughts, suggestions that would be awesome.<br/> <br/> Thanks a lot!© 2009 Microsoft Corporation. All rights reserved.Wed, 01 Jul 2009 18:42:43 Zcc2ddd80-175c-4af1-8e04-4366570af1achttp://social.technet.microsoft.com/Forums/en/ITCG/thread/cc2ddd80-175c-4af1-8e04-4366570af1ac#cc2ddd80-175c-4af1-8e04-4366570af1achttp://social.technet.microsoft.com/Forums/en/ITCG/thread/cc2ddd80-175c-4af1-8e04-4366570af1ac#cc2ddd80-175c-4af1-8e04-4366570af1acb4sherhttp://social.technet.microsoft.com/Profile/en-US/?user=b4sherVB Script: Delete multiple shares on a server with deleting the C$ and D$ share.Hi, I have just recently been thrown into VB Scripting as a means to make me and my fellow admin's jobs a bit easier. Right now we are migrating about 1000 user shares off a server and onto a new CIF. I wrote a script for this that lists all user folders in a directory (all of them are shared folders) and then runs that list (a saved txt file) through a loop that first unshares their drive, then xcopy's their data to the new server. The script runs...but it is extremely slow. I'm pretty sure it is getting hung up on querying all of the shares via:<br/> <div style="color:Black;background-color:White"> <pre><span style="color:Blue">Set</span> objWMIService = GetObject(<span style="color:#a31515">&quot;winmgmts:&quot;</span> _ &amp; <span style="color:#a31515">&quot;{impersonationLevel=impersonate}!\\&quot;</span> &amp; strServer &amp; <span style="color:#a31515">&quot;\root\cimv2&quot;</span> ) <span style="color:Blue">Set</span> colShares = objWMIService.ExecQuery _ (<span style="color:#a31515">&quot;Select * from Win32_Share Where Name = '&quot;</span> &amp; strUsrShare &amp; <span style="color:#a31515">&quot;'&quot;</span> ) <span style="color:Blue">For</span> <span style="color:Blue">Each</span> objShare <span style="color:Blue">in</span> colShares objShare.Delete <span style="color:Blue">Next</span> </pre> </div> As we have over 1000 shares on that server. So I figure it might be easier on the front end to delete all shares then migrate their data. However I can't delete the standard C$ and D$ share, as that is how I am xcopying their data over. But I am specifically noticing the &quot;Select * from Win32_Share&quot; in that snippet of code and was wondering if there is a way to select all the shares that start with &quot;a&quot; and so on and so forth (i.e. a*).<br/> <br/> If anyone has any ideas, thoughts, suggestions that would be awesome.<br/> <br/> Thanks a lot!Wed, 01 Jul 2009 17:37:03 Z2009-07-01T17:44:25Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/cc2ddd80-175c-4af1-8e04-4366570af1ac#9fcb06c3-84d5-477f-8c47-55eb8c49a24chttp://social.technet.microsoft.com/Forums/en/ITCG/thread/cc2ddd80-175c-4af1-8e04-4366570af1ac#9fcb06c3-84d5-477f-8c47-55eb8c49a24cNickHunyadyhttp://social.technet.microsoft.com/Profile/en-US/?user=NickHunyadyVB Script: Delete multiple shares on a server with deleting the C$ and D$ share.Shouldn't be a problem. The WQL can handle that sort of query.<br/><br/>(<span style="color:#a31515">&quot;Select * from Win32_Share Where Name Like 'a%'&quot;</span>)<br/>Wed, 01 Jul 2009 17:54:05 Z2009-07-01T17:54:05Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/cc2ddd80-175c-4af1-8e04-4366570af1ac#37be87ba-5521-4c49-8d83-a6b2b03e485fhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/cc2ddd80-175c-4af1-8e04-4366570af1ac#37be87ba-5521-4c49-8d83-a6b2b03e485fb4sherhttp://social.technet.microsoft.com/Profile/en-US/?user=b4sherVB Script: Delete multiple shares on a server with deleting the C$ and D$ share.Thanks for the reply! But would this cause reason for the script to run slowly? Querying that many shares?Wed, 01 Jul 2009 17:55:16 Z2009-07-01T17:55:27Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/cc2ddd80-175c-4af1-8e04-4366570af1ac#36cbfa60-5760-4548-a41a-efb9a79fc84ahttp://social.technet.microsoft.com/Forums/en/ITCG/thread/cc2ddd80-175c-4af1-8e04-4366570af1ac#36cbfa60-5760-4548-a41a-efb9a79fc84aNickHunyadyhttp://social.technet.microsoft.com/Profile/en-US/?user=NickHunyadyVB Script: Delete multiple shares on a server with deleting the C$ and D$ share.Querying that many shares may take a while to begin with, although if your doing this locally it should run just fine. One thing to remember though, since you are using the operator and only looking for things that start wiht a* this will limit your results drastically.Wed, 01 Jul 2009 18:01:30 Z2009-07-01T18:01:30Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/cc2ddd80-175c-4af1-8e04-4366570af1ac#39d944e1-df81-4039-8ff0-57f95c31241fhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/cc2ddd80-175c-4af1-8e04-4366570af1ac#39d944e1-df81-4039-8ff0-57f95c31241fperhofhttp://social.technet.microsoft.com/Profile/en-US/?user=perhofVB Script: Delete multiple shares on a server with deleting the C$ and D$ share.<p>You can also query all shares and exclude certain shares.<br/>Select * from Win32_Share Where Not Name = 'C$' AND Not Name = 'D$'<br/><br/>I would also recommend you to avoid deleting other administrative shares like admin$, ipc$, print$ etc.</p>Wed, 01 Jul 2009 18:30:33 Z2009-07-01T18:30:33Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/cc2ddd80-175c-4af1-8e04-4366570af1ac#e120246a-5fa9-4e9d-9b47-cd6ab08a1ea1http://social.technet.microsoft.com/Forums/en/ITCG/thread/cc2ddd80-175c-4af1-8e04-4366570af1ac#e120246a-5fa9-4e9d-9b47-cd6ab08a1ea1NickHunyadyhttp://social.technet.microsoft.com/Profile/en-US/?user=NickHunyadyVB Script: Delete multiple shares on a server with deleting the C$ and D$ share.Building on perhof's reply it could be easier to build your query to just exclude administrative shares all together.<br/><br/>(<span style="color:#a31515">&quot;Select * from Win32_Share Where Name Like 'a%' AND Type = '0'&quot;)<br/><br/> <table style="width:61pt;border-collapse:collapse" border=0 cellspacing=0 cellpadding=0 width=81> <colgroup span=1><col style="width:61pt" span=1 width=81></colgroup> <tbody> <tr style="height:12.75pt" height=17> <td style="width:61pt;height:12.75pt;background-color:transparent;border:#ece9d8" width=81 height=17 align=right></td> </tr> </tbody> </table> </span>Wed, 01 Jul 2009 18:42:43 Z2009-07-01T18:42:43Z