none
Printbrm.exe & using a space in the target path RRS feed

  • Question

  • I'm trying to backup print servers using Powershell but having problems with a space being in the target path (-f).  Here's what I'm working with:

    $ServerName=$env:computername

    $NESLBINPath = "C:\Program Files\NESL\bin"

    $PrintServerBackupPath ="$NESLBINPath\PrintServer_Backup\"

    md $NESLBINPath\PrintServer_Backup; remove-item-path$PrintServerBackupPath\$ServerName.bak-force; cmd/c"c:\windows\system32\spool\tools\printbrm.exe -s \\$ServerName-b -f $PrintServerBackupPath\$ServerName.bak"

    Now please don't laugh at my PS skills - if I change the script to use something that doesn't contain a space in the target path everything works.  For some reason Printbrm.exe has trouble with the space.  As you can see, I use the same space in one of my variables and have no problems.

    I've tried using various quotes ("), ticks (`), apostrophes ('), forward slashes (/) and numerous tricks that I've found on "The Google".  I tried dumping the variables and just hammering out the path - no help.  I tried using Invoke-Expression in place of cmd /c - no help.  I just can't get around it.

    Wednesday, June 27, 2018 2:35 PM

Answers

  • You are correct, no one has offered a solution because the problem is not with Powershell.  It is with PrintBrm.  I have played with your script until I am sure it is sending the correct options to the program and still get the same error.  As a matter of fact I have typed all of the info directly into the command line.

    The problem is that PrintBrm simply will not accept a path with a space in it.  I even tried using the path specified in -d for directory option.  It simply will not accept a path with a space.

    You will have to change your directory or open a case with Microsoft.  This is not a scripting problem.

    JRussell97

    • Proposed as answer by jrv Wednesday, June 27, 2018 8:26 PM
    • Marked as answer by NESLDave Thursday, June 28, 2018 12:19 PM
    Wednesday, June 27, 2018 8:05 PM

All replies

  • Wednesday, June 27, 2018 2:39 PM
  • Please do not post colorized code. Use the code posting tool instead you can find on the edit bar.

    $ServerName = $env:computername
    $NESLBINPath = "C:\Program Files\NESL\bin"
    $PrintServerBackupPath = "$NESLBINPath\PrintServer_Backup\"
    md "$NESLBINPath\PrintServer_Backup"
    remove-item -path $PrintServerBackupPath\$ServerName.bak-force
    cmd /c """c:\windows\system32\spool\tools\printbrm.exe"" -s \\$ServerName -b -f ""$PrintServerBackupPath\$ServerName.bak"""

    I recommend for you to start to learn the basics of Powershell from scratch.

    You don't need to start cmd from Powershell as Powershell already is command line interface and is able to start external tools.   ;-)

    The pure Powershell way to start an external tool would be something like this:

    Start-Process -FilePath 'c:\windows\system32\spool\tools\printbrm.exe' -ArgumentList "-s \\$ServerName -b -f ""$PrintServerBackupPath\$ServerName.bak"""


    Best regards,

    (79,108,97,102|%{[char]$_})-join''




    • Edited by BOfH-666 Wednesday, June 27, 2018 3:00 PM
    Wednesday, June 27, 2018 2:46 PM
  • Well, that appears to do nothing - no error message, nothing - I just returns to the prompt.  I do see a brief cmd window that quickly flashes on the display but it's not there long enough to even see what it is.

    -Dave

    Wednesday, June 27, 2018 4:35 PM
  • Add "-NoNewWindow" to see the error.


    \_(ツ)_/

    Wednesday, June 27, 2018 4:37 PM
  • That doesn't even run if I change out the target path with one that has no space.

    -Dave

    Wednesday, June 27, 2018 4:46 PM
  • What doesn't run?  You have to be specific about what code you are running.


    \_(ツ)_/

    Wednesday, June 27, 2018 5:08 PM
  • This will make it easier to manage and code:

    $arglist = @(
        '-s',
        "\\$ServerName",
        '-b',
        '-f',
        "$PrintServerBackupPath\$ServerName.bak"
    )
    $splatr = @{
        FilePath = 'c:\windows\system32\spool\tools\printbrm.exe' 
        ArgumentList = $arglist
        NoNewWindow = $true
    }
    Start-Process @splatr
    



    \_(ツ)_/


    • Edited by jrv Wednesday, June 27, 2018 5:15 PM
    Wednesday, June 27, 2018 5:14 PM
  • You are all trying too hard.

    PowerShell is, after all, a shell. It is designed to run commands that you type. Just type the command you want to run and press Enter.


    PS C:\> C:\Windows\System32\spool\tools\printbrm.exe -s \\$ServerName -b -f $PrintServerBackupPath\$ServerName.bak

    That's it.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, June 27, 2018 5:28 PM
    Moderator
  • Please do not post colorized code. Use the code posting tool instead you can find on the edit bar.

    $ServerName = $env:computername
    $NESLBINPath = "C:\Program Files\NESL\bin"
    $PrintServerBackupPath = "$NESLBINPath\PrintServer_Backup\"
    md "$NESLBINPath\PrintServer_Backup"
    remove-item -path $PrintServerBackupPath\$ServerName.bak-force
    cmd /c """c:\windows\system32\spool\tools\printbrm.exe"" -s \\$ServerName -b -f ""$PrintServerBackupPath\$ServerName.bak"""

    I recommend for you to start to learn the basics of Powershell from scratch.

    You don't need to start cmd from Powershell as Powershell already is command line interface and is able to start external tools.   ;-)

    The pure Powershell way to start an external tool would be something like this:

    Start-Process -FilePath 'c:\windows\system32\spool\tools\printbrm.exe' -ArgumentList "-s \\$ServerName -b -f ""$PrintServerBackupPath\$ServerName.bak"""


    Best regards,

    (79,108,97,102|%{[char]$_})-join''




    @jrv

    This won't run - the code BOfH_666 provided.

    I will try adding "-NoNewWindow".  Still working on PS skills.  Thanks for not being a PS snob :-)

    -Dave

    Wednesday, June 27, 2018 5:54 PM
  • I refer the honorable gentleman to my first response posted about 1 hour and 20 minutes ago.

    -- Bill Stewart [Bill_Stewart]

    Wednesday, June 27, 2018 6:49 PM
    Moderator
  • Bill - it's not the method we're using to run printbrm, it's that fact that there's a space in the target path.  As with most things in scripting, I can run it many ways.  So far, all I'm seeing is different methods to accomplish the same thing - the problem still remains and no one has suggested a solution for that.

    -Dave

     
    Wednesday, June 27, 2018 7:41 PM
  • Start-Process automatically accounts for spaces in an argument.


    \_(ツ)_/

    Wednesday, June 27, 2018 8:03 PM
  • You are correct, no one has offered a solution because the problem is not with Powershell.  It is with PrintBrm.  I have played with your script until I am sure it is sending the correct options to the program and still get the same error.  As a matter of fact I have typed all of the info directly into the command line.

    The problem is that PrintBrm simply will not accept a path with a space in it.  I even tried using the path specified in -d for directory option.  It simply will not accept a path with a space.

    You will have to change your directory or open a case with Microsoft.  This is not a scripting problem.

    JRussell97

    • Proposed as answer by jrv Wednesday, June 27, 2018 8:26 PM
    • Marked as answer by NESLDave Thursday, June 28, 2018 12:19 PM
    Wednesday, June 27, 2018 8:05 PM
  • You are correct, no one has offered a solution because the problem is not with Powershell.  It is with PrintBrm.  I have played with your script until I am sure it is sending the correct options to the program and still get the same error.  As a matter of fact I have typed all of the info directly into the command line.

    The problem is that PrintBrm simply will not accept a path with a space in it.  I even tried using the path specified in -d for directory option.  It simply will not accept a path with a space.

    You will have to change your directory or open a case with Microsoft.  This is not a scripting problem.

    JRussell97

    Yes.  PRINTTBRM does not allow spaces in file names.  The code posted above (most suggestions" works fine as long as there is no space in the file path.


    \_(ツ)_/

    Wednesday, June 27, 2018 8:27 PM
  • My answer was pointing out that you don't need to try so hard just to run an executable from PowerShell.

    If the executable doesn't correctly interpret its own command-line arguments, then obviously that's a different problem altogether.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, June 27, 2018 9:26 PM
    Moderator
  • Thanks all for confirming what I was experiencing.  I did eventually just change the directory in hopes that I would get a solution and change it back.

    Thanks also for suggestions, tips, etc. on PS scripting.  Every new script usually brings a new twist in the learning curve.

    -Dave

    Thursday, June 28, 2018 12:19 PM
  • Not sure if you still needed help with this but I had the same issue. I was looking for a more eloquent way of doing it but I just went back to basics and used the short names generated for non-8dot3 file formats. You can find the name of the directory in this format by opening a command prompt and executing "dir /ad /x". This will list the directories and in the middle you can see the short directory name. It will have the first 6 characters of the directory name followed by ~1. In my case the folder I wanted to write to was named "IT Folder" which became itfold~1 for he directory name using this. My full path looked something like "\\server\share\itfold~1\printerbackup\filename.printerExport".

    You can also use this for file names with spaces just remove the /ad for the directories attribute. 

    I hope this helped. 

    Tuesday, September 25, 2018 1:55 AM