Announcement

Collapse
No announcement yet.

Running a command against all subfolders in a folder

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Running a command against all subfolders in a folder

    I need to be able to run this command against a wim file in multiple sub folders can someone please show me how to do this.

    wbadmin get versions -backupTarget:\\server\E$\Desktops\username >> c:\cmdfiles\logs\backup-versions.log

    Thanks

  • #2
    Re: Running a command against all subfolders in a folder

    I don't think you can do that even if the wim file was mounted.
    You may have to apply the image first.
    Caesar's cipher - 3

    ZKHQ BRX HYHQWXDOOB GHFLSKHU WKLV BRX ZLOO UHDOLVH LW ZDV D ZDVWH RI WLPH!

    SFX JNRS FC U6 MNGR

    Comment


    • #3
      Re: Running a command against all subfolders in a folder

      I can run the command without the vhd (my bad) being mounted. I have a batch file that will do it but it has one line per user, with is about 60 users, and has to be updated everytime a uses leaves and a new one comes in.

      Comment


      • #4
        Re: Running a command against all subfolders in a folder

        I want to do something like this. Where each line in the names.txt file is substituted in for username.

        Code:
        for /f %a in (c:\cmdfiles\names.txt) do wbadmin get versions -backupTarget:\\server\E$\Desktops\username >> c:\cmdfiles\logs\backup-versions.log

        Comment


        • #5
          Re: Running a command against all subfolders in a folder

          I have not tested and I don't know your file structure but you could try this:
          Code:
          for /f %%a in ('dir \\server\E$\Desktops /b') do wbadmin get versions -backupTarget:\\server\E$\Desktops\%%a >> c:\cmdfiles\logs\backup-versions.log
          Regards,
          Jeremy

          Network Consultant/Engineer
          Baltimore - Washington area and beyond
          www.gma-cpa.com

          Comment


          • #6
            Re: Running a command against all subfolders in a folder

            I got this working, base don Felipe's script here:
            http://www.visualbasicscript.com/Rea...ng-m61746.aspx

            Code:
            @REM This script validates backups created with wbadmin
            @REM By Steve Lammert  3/21/2012 
              
            @echo off 
              
            :: Keep variables local 
            SETLOCAL 
              
            ::DEFINE VARIABLES (logfile) 
            set logfile=c:\cmdfiles\logs\%computername%-backups.txt
            set inputfile=c:\cmdfiles\names.txt
            
            :: DELETE OLD FILES
            del %inputfile% /q 
            del %logfile% /q
            
            :: CREATE NEW INPUT FILE
            @REM Change this line to the location the backs are stored
            dir d:\desktops\*. /b >> %inputfile%
            
            :Run 
            cls 
            @echo. 
            @echo Retriving Users from %inputfile% please wait... 
            @echo. 
             
            :: Search the TXT file line by line 
            FOR /F "tokens=* delims=" %%A IN ('TYPE %inputfile%') DO CALL :ParseINI "%%A" 
              
            @echo Finished Reading %inputfile% 
              
            @echo Command Completed 
            @echo Output on the logfile : %logfile%. 
            rem pause 
            rem notepad %logfile% 
            copy %logfile% \\backup03\e$\desktops
            @REM Clean Variables 
            ENDLOCAL 
            set USR= 
            set logfile= 
            set inputfile=
            
            goto end
            rem exit 
             
            ::===== Go thru .TXT and set each line to a variable and execute; === 
            :ParseINI 
            SET USR="%~1" 
            ::Clean the quotes from the servername 
            SET USR=%USR:"=% 
              
            :: Do the CMD 
            ECHO ************************************* >> %logfile%
            ECHO Checking backup for : %USR%  >> %logfile%
            ECHO Checking backup for : %USR% 
            set ERRORLEVEL=0 
            @REM RUNS wbadmin to validate the backup
            @REM 
            @REM Modify the drive letter on the following line
            @REM 
            wbadmin get versions -backupTarget:\\%computername%\E$\Desktops\%USR% >> %logfile% 
            
            :end
            Last edited by akitafan; 23rd March 2012, 14:54.

            Comment


            • #7
              Re: Running a command against all subfolders in a folder

              Thanks for sharing.
              Regards,
              Jeremy

              Network Consultant/Engineer
              Baltimore - Washington area and beyond
              www.gma-cpa.com

              Comment


              • #8
                Re: Running a command against all subfolders in a folder

                I have to update this to be able to run against a remote system since all of our branch/backup servers are running 2003, so no wbadmin for me. So I can now run it from my Vista workstation and just pass it a parameter of the server name.

                Code:
                @REM This script validates backups created with wbadmin
                @REM By Steve Lammert  3/21/2012 
                @REM Updated 3/23/2012 - Modified to accept command line parameter so the script
                @REM 			can be run on one server and collect data from branch servers.
                @REM 			Usage - verify-backups.cmd "server-name"
                  
                @echo off 
                
                :: Check for servername
                ECHO.%1 | FIND "?" >NUL 
                IF NOT ERRORLEVEL 1 GOTO Syntax 
                IF [%1]==[] GOTO Syntax 
                  
                :: Keep variables local 
                SETLOCAL 
                  
                ::DEFINE VARIABLES (logfile) 
                set servername=%1
                set logfile=c:\cmdfiles\logs\verify-backups.log
                set inputfile=c:\cmdfiles\names.txt
                
                
                :: DELETE OLD FILES
                del %inputfile% /q 
                del %logfile% /q
                
                :: CREATE NEW INPUT FILE
                @REM Change this line to the location the backs are stored
                dir \\%1\d$\desktops\*. /b >> %inputfile%
                
                :Run 
                cls 
                @echo. 
                @echo Retriving Users from %inputfile% please wait... 
                @echo. 
                 
                :: Search the TXT file line by line 
                FOR /F "tokens=* delims=" %%A IN ('TYPE %inputfile%') DO CALL :ParseINI "%%A" 
                  
                @echo Finished Reading %inputfile% 
                  
                @echo Command Completed 
                @echo Output on the logfile : %logfile%. 
                rem pause 
                rem notepad %logfile% 
                copy %logfile% \\backup03\e$\desktops\%1-backups.log
                
                @REM Clean Variables 
                ENDLOCAL 
                set USR= 
                set logfile= 
                set inputfile=
                
                goto end
                rem exit 
                 
                ::===== Go thru .TXT and set each line to a variable and execute; === 
                :ParseINI 
                SET USR=%1 
                ::Clean the quotes from the username 
                SET USR=%USR:"=% 
                  
                :: Do the CMD 
                ECHO ************************************* >> %logfile%
                ECHO Checking backup for : %USR%  >> %logfile%
                ECHO Checking backup for : %USR% 
                set ERRORLEVEL=0 
                @REM RUNS wbadmin to validate the backup
                @REM 
                @REM Modify the drive letter on the following line
                @REM 
                wbadmin get versions -backupTarget:\\%servername%\D$\Desktops\%USR% >> %logfile% 
                
                :end

                Comment

                Working...
                X