Answered Script backup printqueues

  • Wednesday, August 04, 2010 9:27 AM
     
     

    Hi,

    I am scripting a backup of our printer queues using the printbrm.exe tool in Powershell on Windows Server 2008 R1.
    In my script, I execute the following command:

    PS> C:\Windows\System32\spool\tools\Printbrm.exe -s \\PRINTCLUSTER -b -f c:\scripts\backup.printerExport

    I would like to create a log in which I can see if the printbrm.exe command worked well or not.
    However, I don't seem to be able to redirect the printbrm.exe output to a logfile.
    I tried the following:

    PS> C:\Windows\System32\spool\tools\Printbrm.exe -s \\PRINTCLUSTER -b -f c:\scripts\backup.printerExport > backup.log

    A "backup.log" file is created, but this remains empty.

    I also tried to catch the exit code through powershell, but this doesn't seem to work either:

    PS> C:\Windows\System32\spool\tools\Printbrm.exe -s \\PRINTCLUSTER -b -f c:\scripts\backup.printerExport
    PS> echo $LastExitCode
    0

    If the printbrm failed or succeeded, the $LastExitCode is always zero..

    How can I know from Powershell if the printbrm.exe command worked succesfully?

All Replies

  • Wednesday, August 04, 2010 3:23 PM
    Answerer
     
     

    I just run my task in a command prompt but I get a log piping to file.  With this script I pass in a server name, take an existing backup file and use the -d option added in 2008 R2 to expand the cab file, then copy prebuilt brm files that contain no driver and print processor data (the print drivers are already installed on my server), rebuild the backup file with -d option and restore just the printers to the local server.  Basically this updates the printers on my server with changes made from several other print servers.

    =========================================

    @setlocal
    @if "%~1"=="" goto :usage

    @set logfile=%date:~4,2%%date:~7,2%%date:~12,2%

    delnode /q c:\%1

    %windir%\system32\spool\tools\printbrm -d c:\%1 -r -f c:\%1.cab

    copy \\server\public\stresslab\brm\zeroedfiles\* c:\%1 /y

    del c:\%1.cab

    %windir%\system32\spool\tools\printbrm -d c:\%1 -b -f c:\%1.cab

    %windir%\system32\spool\tools\printbrm -r -O FORCE -f c:\%1.cab > %1.%logfile%.log

    @endlocal
    goto :EOF

    :Usage
    @echo.
    @echo  Must specify server name (\\servername)
    @echo.
    @endlocal
    goto :EOF

     


    Alan Morris Windows Printing Team; Search the Microsoft Knowledge Base here: http://support.microsoft.com/search/Default.aspx?adv=1
  • Wednesday, August 04, 2010 6:27 PM
     
     

    Hi, 

    I noticed that you are piping the printbrm.exe output to a file exactly the same way as I did it. 
    I am however using Windows Server 2008 R1, and that same piping to a file doesn't seem to be working there for printbrm.exe..

    Have you ever piped the printbrm.exe output to a file on Windows Server 2008 R1? 
    Or are there other ways to verify from script whether the printbrm.exe command ran succesfully? 

    Thanks!

  • Wednesday, August 04, 2010 7:26 PM
    Answerer
     
     Answered
    I recall there was some localization bug when outputting this info to file but can't find the context. I did confirm that you are not going crazy with this, there is only a zero byte file on 2008 SP2.  If I find a work around other than 2008 R2 / Windows 7, I'll let you know.
    Alan Morris Windows Printing Team; Search the Microsoft Knowledge Base here: http://support.microsoft.com/search/Default.aspx?adv=1
  • Thursday, December 13, 2012 9:19 PM
     
     

    Has this ever been resolved in Server 2008 R1?

    I am currently working on a script to pipe printbrm command line output then it will email the contents of the txt file in message body. However, the txt file and email have no content due to printbrm > file.txt bug

  • Friday, December 14, 2012 2:25 AM
    Answerer
     
     

    There was never a customer request for the fix.  You would need to call support and go through that route.   I've used posts in forums to get the team that handles servicing related changes to notice but this forum is not an official support path.  The issue has been addressed in the current OS as well as the previous OS released over 3 years ago so getting traction on this would be real hard. 

    I would use PrintBRM from Win7 (or Win 8) and remotely target the 2008 machine.   


    Alan Morris Windows Printing Team

  • Wednesday, January 02, 2013 2:36 PM
     
     

    Hi,

    You should be able to create an output file using the Powershell cmdlet "OUT-FILE" and it would look like the following

    PS> C:\Windows\System32\spool\tools\Printbrm.exe -s \\ printerserver -b -f c:\scripts\backup.printerExport | out-file c:\scripts\backup.log

    out-table is also another cmdlet you could use should you want to put it in table form.