Using Scripting in Powershell

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RalphS
    New User
    • Jul 2018
    • 2

    Using Scripting in Powershell

    Hi Guys,

    I'm pretty new to scripting with Beyond Compare and Power shell (only done about 4 hours of work!) and I've come across an issue.

    I want to be able to run Beyond compare commands directly within power shell. From what I can see, this can only be done via external scripts. Is it not possible to run all my commands directly within Powershell?

    In this case, I'm trying to do a BC on two folders and like to have the result displayed in a nicely formatted HTML page.

    Running this on Powershell works for which it compares in BC:
    & "C:\Program Files\Beyond Compare 4\BCompare.exe" "$folder1" "$folder2"

    But if I then try and view it as HTML, I do the following:
    & "C:\Program Files\Beyond Compare 4\BCompare.exe" "$folder1" "$folder2" "criteria rules-based" "load" "$folder1" "$folder2" "expand all" "select all.files" "folder-report layout:side-by-side options:include-file-links" "output-to:\ output-options:html-color"

    This doesn't work.

    So am I right in assuming, I'll have to generate an external script and link it to my powershell file or is it possible to run these commands within Powershell directly?

    Thank you!
  • Aaron
    Team Scooter
    • Oct 2007
    • 16000

    #2
    Hello,

    BC4's scripting support loads a specific script file (c:\bcscript.txt) which then contains a series of script commands separated by newlines. It's a specific syntax, and executing script mode requires the "@" parameter in front of the file.

    bcompare.exe "@c:\bcscript.txt"

    You might be able to create a single line that generates and then calls to this script file, but it would probably be easier to create the script file separately. It can also accept parameter text, such as:

    bcompare.exe "@c:\bcscript.txt" "c:\folder1" "c:\folder2" "c:\reports\bcreport.html"

    where this text can be loaded in bcscript.txt with $1 and $2 etc

    criteria rules-based
    load" "%1" "%2"
    expand all
    folder-report layout:side-by-side options:include-file-links output-to:"%3" output-options:html-color
    Last edited by Aaron; 11-Jul-2018, 03:45 PM. Reason: update $ to %
    Aaron P Scooter Software

    Comment

    • RalphS
      New User
      • Jul 2018
      • 2

      #3
      Thanks Aaron.
      After taking on your changes I had to make one final update to the script you provided by replacing the $ with %

      All is working as expected!

      Comment

      • Aaron
        Team Scooter
        • Oct 2007
        • 16000

        #4
        Ah, you're right. Whoops! I used the wrong character, and it should indeed be %1, %2, %3, %4, etc, for each parameter.
        Aaron P Scooter Software

        Comment

        • rmcmillin
          New User
          • Jan 2020
          • 2

          #5
          i am trying to write a similar script and keep getting errors here is what i have :

          this is my compare.txt


          criteria binary

          load "%1" "%2"

          expand all

          select all

          folder-report layout:side-by-side output-to:c:\temp\report.html output-options:html-color


          here is the command i am trying to run:


          "C:\Program Files\Beyond Compare 4\Bcompare.exe" "@c:\temp\compare.txt" "\\ordwebfe10\E$\application_code\production_fe\pr oduction_session" "\\ordwebfe02\E$\application_code\production_fe\pr oduction_session" "C:\temp\FolderReport.txt"


          am i missing something?


          here are the errors i am getting:"

          At line:4 char:50
          + ... m Files\Beyond Compare 4\Bcompare.exe" "@c:\temp\compare.txt" "\\ordw ...
          + ~~~~~~~~~~~~~~~~~~~~~~
          Unexpected token '"@c:\temp\compare.txt"' in expression or statement.
          At line:4 char:73
          + ... ompare.txt" "\\ordwebfe10\E$\application_code\production_fe\pr oductio ...
          + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
          Unexpected token '"\\ordwebfe10\E$\application_code\production_fe\p roduction_session"' in expression or statement.
          At line:4 char:141
          + ... on_session" "\\ordwebfe02\E$\application_code\production_fe\pr oductio ...
          + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
          Unexpected token '"\\ordwebfe02\E$\application_code\production_fe\p roduction_session"' in expression or statement.
          At line:4 char:209
          + ... ion_code\production_fe\production_session" "C:\temp\FolderReport.txt"
          + ~~~~~~~~~~~~~~~~~~~~~~~~~~
          Unexpected token '"C:\temp\FolderReport.txt"' in expression or statement.
          + CategoryInfo : ParserError: ( [], ParentContainsErrorRecordException
          + FullyQualifiedErrorId : UnexpectedToken

          thanks for any assitance



          Comment

          • rmcmillin
            New User
            • Jan 2020
            • 2

            #6
            also is there a way to use one location as the main source and compare multiple folders on multiple servers?

            Comment

            • Aaron
              Team Scooter
              • Oct 2007
              • 16000

              #7
              It looks like from the logs you have a space between p and r in production. If that is a forum issue, you can use the CODE tags around it to capture exact text, or email [email protected] with a link back to this forum thread and the actual .txt files and .txt log files as attachments.

              You can also replace the output-to:"%3" or remove the 3rd variable from the command line. You currently have it in the command line but then don't use it in the script.

              Lastly, as a folder-report, you don't need to select all, so you can delete that line, too, although it is not causing any of the errors.

              We don't support a one to many comparison, but you can sequentially call a the script with each pair:
              bcompare @script.txt c:\main c:\folder1
              bcompare @script.txt c:\main c:\folder2
              bcompare @script.txt c:\main c:\folder3
              etc
              Aaron P Scooter Software

              Comment

              Working...