Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Scan every machine in the list and find all machines that has shares of any kind which has songs in them. Only those names should be logged in them.

Hi,

Scan every machine in the list and find all machines that has shares of any kind which has songs in them. Only those names should be logged in them.
Mp3 and any type of Audio songs. Need to log the data as

Machine name      Share name       Filenames
                                                        Filename2

For this case i think we need to get into the C$ and D$ of each machine and run this scan and log just the shared folders data. As even the Domain admin may not have permissions to these shares.

REgards
Sharath

@ECHO on
SETLOCAL ENABLEDELAYEDEXPANSION
Set CSVFile=C:\EveryoneShareSecurityWriteable.csv
 
IF NOT EXIST "%CSVFile%" ECHO "Machine Name","Share Name">"%CSVFile%"
 
for /F %%a in (C:\Computers.txt) do CALL :PROCESS %%a
 
GOTO :EOF
 
:PROCESS
for /f "tokens=1 delims=:" %%a in ('rmtshare \\%1^| find /v /i "default share" ^| find /v /i "Remote admin" ^| find /v /i "Remote IPC" ^| FIND /v /i "Printer drivers" ^| FIND ":"') DO (
    set Share=%%a
    set Share=!Share:~0,-2!
    For /l %%z in (1,1,30) DO if "!Share:~-1!" == " " Set Share=!Share:~0,-1!
 
    Set EveryoneSharePerm=
    RMTSHARE \\%1\"!Share!" | find /i "\everyone" | find /i "FULL CONTROL"
    IF NOT ERRORLEVEL 1 Set EveryoneSharePerm=Writeable
 
    if not defined EveryoneSharePerm (
        RMTSHARE \\%1\"!Share!" | find /i "\everyone" | find /i "CHANGE"
        IF NOT ERRORLEVEL 1 Set EveryoneSharePerm=Writeable
    )
 
    Set EveryoneSecurityPerm=
    IF DEFINED EveryoneSharePerm (
        FOR /f "tokens=1,*" %%b in ('rmtshare \\%1\"!Share!" ^| FIND /i "Path"') DO (
            Set SharePath=%%c
            Set SharePath=!SharePath::=$!          
            cacls "\\%1\!SharePath!" | find /i "everyone" | findstr /e /i /c:"F "
            IF NOT ERRORLEVEL 1 Set EveryoneSecurityPerm=Writeable
 
            IF NOT DEFINED EveryoneSecurityPerm (
                cacls "\\%1\!SharePath!" | find /i "everyone" | findstr /e /i /c:"C "
                IF NOT ERRORLEVEL 1 Set EveryoneSecurityPerm=Writeable
            )
        )
    )
 
    IF DEFINED EveryoneSharePerm IF DEFINED EveryoneSecurityPerm ECHO "%1","!Share!">>"%CSVFile%"
 
)

Open in new window

Avatar of Justin_W_Chandler
Justin_W_Chandler
Flag of United States of America image

Are you asking something or just posting code?
Avatar of bsharath

ASKER

Hi,

I if the above requirment can be done. With the help of the code provided...
Actuall the code checks each machine in the list and find all Open shares. Thought it would be useful to any one who may help
Hi,

I if the above requirment can be done. With the help of the code provided...
Actuall the code checks each machine in the list and find all Open shares. Thought it would be useful to any one who may help
Avatar of AmazingTech
AmazingTech

OK.

I hope this is what you wanted in the output format you wanted. Filename is Computername-Share.csv

Let me know.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
Set Ext=*.mp3 *.wma
 
 
for /F %%a in (C:\Computers.txt) do CALL :PROCESS %%a
 
GOTO :EOF
 
:PROCESS
for /f "tokens=1 delims=:" %%a in ('rmtshare \\%1^| find /v /i "default share" ^| find /v /i "Remote admin" ^| find /v /i "Remote IPC" ^| FIND /v /i "Printer drivers" ^| FIND ":"') DO (
    set Share=%%a
    set Share=!Share:~0,-2!
    For /l %%z in (1,1,30) DO if "!Share:~-1!" == " " Set Share=!Share:~0,-1!
 
    for /f "tokens=1,*" %%b in ('rmtshare \\%1\"!Share!" ^| find /i "path"') do Set RemotePath=%%c
    
    Set RemotePath=!RemotePath::=$!
 
    CALL :GETFILES %1 "!RemotePath!" "!Share!"
 
)
GOTO :EOF
 
:GETFILES
echo Working on \\%1\%~3 using \\%1\%~2
Set Header="%1","%~3"
    
for /r "\\%1\%~2" %%c in (%Ext%) do (
     Set FoundSong=%%c
     if NOT "!Header:~2,1!" == "," ECHO "Machine Name","Share Name","Filename with path">"%1-%~3.csv"
     @echo !Header!,"!FoundSong:\\%1\%~2\=!">>"%1-%~3.csv"
     Set Header="",""
)

Open in new window

Thanks AT works perfect.

Can i give a no. Like log only machines that may have 50 or more mp3's
Thanks AT works perfect.

Can i give a no. Like log only machines that may have 50 or more mp3's
ASKER CERTIFIED SOLUTION
Avatar of AmazingTech
AmazingTech

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a lot for this :-)