From: mit0408 on
I am using the following script to delete shares and want to specify multiple
shares, instead of just one share name. How can I do so?

DomainName = "domain.com"
ServerName = "Server1"
ShareName = "Share1"

Set cont = GetObject("WinNT://"& DomainName &"/"& ServerName
&"/LanmanServer,FileService")
cont.Delete "FileShare", ""& ShareName &""


Also, how can I add to this script so that it deletes the directories
associated witht he shares, once the shares are removed? The directory names
match that of the share names.

Thanks
From: LikeToCode on
You could loop through the "cont" array and compare it to an Array of all of
the possible share names then and delete the matches and then delete the
folders using the FileSystem Object.

Set cont = GetObject("WinNT://"& DomainName &"/"& ServerName &_
"/LanmanServer,FileService")
For Each str In cont
If InStr(FindShare(str.name),str.name) > 0 Then
strPath = str.path 'capture the path in an variable
cont.Delete "FileShare", ""& str.name &""
Dim objFSO: Set objFSO = CreateObject("scripting.filesystemobject")
objFSO.DeleteFolder strpath,True
End If
next

Function FindShare(name)
Dim ShareName(4)
ShareName(0) = "Share1"
ShareName(1) = "Share2"
ShareName(2) = "Share3"
ShareName(3) = "Share4"

For Each Share In ShareName
If InStr(Share,name) > 0 Then
FindShare = Share
End If
Next
End Function
From: rno on
You can put the desired server/share names in an array or Dictionary
object, then loop thru that and process them as you want

See the VBScript documentation for examples on how to use a dictionary

Note that keys in a Dictionary have to be unique, so if a dictionary
doesn't work for you, use an array instead. Same principle, really

hth
arno


On Fri, 5 Mar 2010 10:45:01 -0800, mit0408
<mit0408(a)discussions.microsoft.com> wrote:

>I am using the following script to delete shares and want to specify multiple
>shares, instead of just one share name. How can I do so?
>
>DomainName = "domain.com"
>ServerName = "Server1"
>ShareName = "Share1"
>
>Set cont = GetObject("WinNT://"& DomainName &"/"& ServerName
>&"/LanmanServer,FileService")
>cont.Delete "FileShare", ""& ShareName &""
>
>
>Also, how can I add to this script so that it deletes the directories
>associated witht he shares, once the shares are removed? The directory names
>match that of the share names.
>
>Thanks

From: Al Dunbar on
Loops are great, however, not so elegant when you have to write code to
construct large data structures to iterate through. A sometimes better
approach is to put the data in a file and write the code to process the data
it reads as it goes along.

Another approach I find useful is to code a function to do the work (i.e. to
delete one share), and call it multiple times, i.e.:

DelShare "domain1.com" "\\server1\share1"
DelShare "domain1.com" "\\server1\share2"
DelShare "domain1.com" "\\server2\share1"
DelShare "domain1.com" "\\server2\share2"
DelShare "domain2.com" "\\server1\share1"
DelShare "domain2.com" "\\server1\share2"
DelShare "domain2.com" "\\server2\share1"
DelShare "domain2.com" "\\server2\share2"

Of course, this gets way ugly if there are a lot of shares to delete.


/Al


"rno" <nospam(a)fake.org> wrote in message
news:hjo2p5h7vcqg7m0h8glp7fuv6d3fh4hdd8(a)4ax.com...
> You can put the desired server/share names in an array or Dictionary
> object, then loop thru that and process them as you want
>
> See the VBScript documentation for examples on how to use a dictionary
>
> Note that keys in a Dictionary have to be unique, so if a dictionary
> doesn't work for you, use an array instead. Same principle, really
>
> hth
> arno
>
>
> On Fri, 5 Mar 2010 10:45:01 -0800, mit0408
> <mit0408(a)discussions.microsoft.com> wrote:
>
>>I am using the following script to delete shares and want to specify
>>multiple
>>shares, instead of just one share name. How can I do so?
>>
>>DomainName = "domain.com"
>>ServerName = "Server1"
>>ShareName = "Share1"
>>
>>Set cont = GetObject("WinNT://"& DomainName &"/"& ServerName
>>&"/LanmanServer,FileService")
>>cont.Delete "FileShare", ""& ShareName &""
>>
>>
>>Also, how can I add to this script so that it deletes the directories
>>associated witht he shares, once the shares are removed? The directory
>>names
>>match that of the share names.
>>
>>Thanks
>