Resources for IT Professionals > Página Inicial dos Fóruns > The Official Scripting Guys Forum! > VB Script: Delete multiple shares on a server with deleting the C$ and D$ share.
Fazer uma PerguntaFazer uma Pergunta
 

RespondidoVB Script: Delete multiple shares on a server with deleting the C$ and D$ share.

  • quarta-feira, 1 de julho de 2009 17:37b4sher Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    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:
    Set
     objWMIService = GetObject("winmgmts:"
     _
        	& "{impersonationLevel=impersonate}!\\"
     & strServer & "\root\cimv2"
    )
    	Set
     colShares = objWMIService.ExecQuery _
        	("Select * from Win32_Share Where Name = '"
     & strUsrShare & "'"
    )
    	For
     Each
     objShare in
     colShares
        	objShare.Delete
    	Next
    
    
    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 "Select * from Win32_Share" in that snippet of code and was wondering if there is a way to select all the shares that start with "a" and so on and so forth (i.e. a*).

    If anyone has any ideas, thoughts, suggestions that would be awesome.

    Thanks a lot!

Respostas

  • quarta-feira, 1 de julho de 2009 17:54NickHunyady Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    Shouldn't be a problem. The WQL can handle that sort of query.

    ("Select * from Win32_Share Where Name Like 'a%'")
    • Marcado como Respostab4sher quarta-feira, 1 de julho de 2009 18:02
    •  

Todas as Respostas

  • quarta-feira, 1 de julho de 2009 17:54NickHunyady Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    Shouldn't be a problem. The WQL can handle that sort of query.

    ("Select * from Win32_Share Where Name Like 'a%'")
    • Marcado como Respostab4sher quarta-feira, 1 de julho de 2009 18:02
    •  
  • quarta-feira, 1 de julho de 2009 17:55b4sher Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Thanks for the reply! But would this cause reason for the script to run slowly? Querying that many shares?
  • quarta-feira, 1 de julho de 2009 18:01NickHunyady Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    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.
  • quarta-feira, 1 de julho de 2009 18:30perhof Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    You can also query all shares and exclude certain shares.
    Select * from Win32_Share Where Not Name = 'C$' AND Not Name = 'D$'

    I would also recommend you to avoid deleting other administrative shares like admin$, ipc$, print$ etc.

  • quarta-feira, 1 de julho de 2009 18:42NickHunyady Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Building on perhof's reply it could be easier to build your query to just exclude administrative shares all together.

    ("Select * from Win32_Share Where Name Like 'a%' AND Type = '0'")