#192800 - 2009-03-10 10:47 PM
find a certain share within a domain
|
dwb
Fresh Scripter
Registered: 2009-02-04
Posts: 7
Loc: nv
|
looking for help on a script that would be able to find a certain share on all computers in a domain, servers and user computers. WMI comes to mind and looking for other ways too, maybe kixtart can help with this.
tia
|
|
Top
|
|
|
|
#192803 - 2009-03-11 06:21 AM
Re: find a certain share within a domain
[Re: Allen]
|
dwb
Fresh Scripter
Registered: 2009-02-04
Posts: 7
Loc: nv
|
to be more explicit:
this particular user would like a script that finds all shares that are shared via "everybody" has no user/password. he has 6000 machines to check
|
|
Top
|
|
|
|
#192804 - 2009-03-11 07:45 AM
Re: find a certain share within a domain
[Re: dwb]
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11634
Loc: Space
|
This script might work, will need Admin rights on all remote systems and I'll leave populating the list up to you. Some use the NET VIEW or a UDF here like it but that often misses a LOT of computers. You also might need to add some code to make sure WMI is functional and you can connect to it otherwise you'll get a lot of timeouts and maybe even a script abend. WMIConfirm() - Confirm access to WMI
Here is a link to the SharePerms() - Share Permission Control
There are many other UDF scripts here: UDF Script Library
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')
$SO=SetOption('WrapAtEOL','On')
Dim $Systems, $Shares, $sComputer, $File, $Report
$Systems = ReadFile(@ScriptDir+'\systems.txt')
$File = @ScriptDir+'\'+'system_shares.txt'
If Exist($File)
Del $File
EndIf
$Report = RedirectOutput($File,0)
For Each $sComputer In $Systems
If $sComputer
$Shares = ListSharesAndPerms($sComputer)
EndIf
Next
$Report = RedirectOutput("")
RUN 'Notepad.exe ' + $File
Function ListSharesAndPerms($sComputer)
Dim $File, $Report, $objWMIService, $colShares, $objShare
$objWMIService = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!\\" + $sComputer + "\root\cimv2")
$colShares = $objWMIService.ExecQuery("Select * from Win32_Share")
For Each $objShare In $colShares
If $objShare
If Not $objShare.Type = '-2147483648' And Not InStr($objShare.Name,'IPC'+'$')
$sComputer + ' ' + 'SHARE-NAME:' + ' ' + $objShare.Name + ' Path: ' + $objShare.Path ?
SharePerms('SHOW','\\'+$sComputer+'\'+$objShare.Name)
EndIf
EndIf
Next
EndFunction
Function SharePerms($cmd,$object,Optional $trustee,Optional $perms)
Dim $ADSU, $GSD, $oDacl, $Ace, $oAce
$ADSU = CreateObject("ADsSecurityUtility")
$GSD = $ADSU.GetSecurityDescriptor($object, 2, 1)
$oDacl = $GSD.DiscretionaryAcl
If $cmd = "SHOW"
For Each $Ace In $oDacl
If $Ace
$SharePerms = $SharePerms + @CRLF
"Trustee: " + $Ace.Trustee + @CRLF
"Flags: " + $Ace.AceFlags + @CRLF
"AccessMask: " + $Ace.AccessMask + @CRLF
"Type: " + $Ace.AceType + @CRLF + @CRLF
EndIf
Next
EndIf
If $cmd = "DEL"
If $trustee <> ""
For Each $Ace in $oDacl
If $Ace.trustee = $trustee
$oDacl.RemoveAce($Ace)
EndIf
Next
$GSD.DiscretionaryAcl = $oDacl
$ADSU.SetSecurityDescriptor($object, 2, $GSD, 1)
Else
Exit 1
EndIf
EndIf
If $cmd = "ADD"
If $trustee <> ""
$oAce = CreateObject("AccessControlEntry")
$oAce.Trustee = $trustee
Select
Case $perms = "READ"
$oAce.AccessMask = 1179817
Case $perms = "WRITE"
$oAce.AccessMask = 1245631
Case $perms = "FULL"
$oAce.AccessMask = 2032127
Case 1
$oAce.AccessMask = 1179817
EndSelect
$oDacl.AddAce($oAce)
$GSD.DiscretionaryAcl = $oDacl
$ADSU.SetSecurityDescriptor($object, 2, $GSD, 1)
Else
Exit 1
EndIf
EndIf
Exit @ERROR
EndFunction
Function ReadFile($file)
Dim $lf, $f, $_, $t
$lf=Chr(10)
$f=FreeFileHandle
$_=Open($f,$file)
If @ERROR Exit @ERROR EndIf
Do $t=$t+$lf+ReadLine($f) Until @ERROR
$_=Close($f)
$ReadFile=Split(SubStr($t,2),$lf)
EndFunction
|
|
Top
|
|
|
|
#192805 - 2009-03-11 07:52 AM
Re: find a certain share within a domain
[Re: dwb]
|
dwb
Fresh Scripter
Registered: 2009-02-04
Posts: 7
Loc: nv
|
i was thinking about searching AD and all the computers say listed in the container "computers" and/or other OU's containing computers. that would get me my computer list, then search for shares and test the share property for it's status. versus, say, reading from a text file that has 6000+ computers listed.
i could then write those results to a CSV text file to import into, say Excel.
if not AD then what about WMI or something?
|
|
Top
|
|
|
|
#192814 - 2009-03-11 09:50 AM
Re: find a certain share within a domain
[Re: Lonkero]
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11634
Loc: Space
|
I'm not MCP so will MCSE do? 
Depends on OS and version as Microsoft changed some along the way. I general though as long as the underlying NTFS permissions are set correctly it shouldn't matter and is only a secondary protection method.
|
|
Top
|
|
|
|
#192829 - 2009-03-11 06:49 PM
Re: find a certain share within a domain
[Re: NTDOC]
|
dwb
Fresh Scripter
Registered: 2009-02-04
Posts: 7
Loc: nv
|
Enabling "Network access: Let Everyone permissions apply to anonymous users" does not generate the list this client would like. Your suggestion does solve a problem however, but not the requested solution of this particular client.
|
|
Top
|
|
|
|
#192830 - 2009-03-11 06:52 PM
Re: find a certain share within a domain
[Re: dwb]
|
dwb
Fresh Scripter
Registered: 2009-02-04
Posts: 7
Loc: nv
|
NTDOC,
thanks, i'll give the code a run and check it out. mucho gracias
|
|
Top
|
|
|
|
#192834 - 2009-03-11 09:00 PM
Re: find a certain share within a domain
[Re: Lonkero]
|
dwb
Fresh Scripter
Registered: 2009-02-04
Posts: 7
Loc: nv
|
lonkero, ok, i'll pass the suggestion onward to him and get his feedback
|
|
Top
|
|
|
|
#192875 - 2009-03-13 08:01 PM
Re: find a certain share within a domain
[Re: Lonkero]
|
dwb
Fresh Scripter
Registered: 2009-02-04
Posts: 7
Loc: nv
|
NTDOC: thanks. that works fine. i'll look for a UDF Script that could substitute for the "net view" command so the program could grab a list versus the user manually doing that -- or give him the option for both.
Lonkero: thanks for the link. the user may make use of that util or something like "hyena" also.
meanwhile the script is doing ok as an option too.
mucho gracias
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(mole)
and 1300 anonymous users online.
|
|
|