Problem with plugin calling PowerShell

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MikeC
    New User
    • Feb 2011
    • 1

    Problem with plugin calling PowerShell

    Hi,

    I'm trying to create a conversion plug-in which uses Powershell to perform some custom normalization on xml documents before comparing them, but I'm having some trouble getting it to work properly.

    I think the problem is to do with the security context that BeyondCompare launches external programs in, and my Powershell execution policy, but I've run out of ideas on what it might be.

    Starting from the beginning, I created a File Format which handles the xml extension as follows:

    Name: Xml (Loose Comparison)
    Mask: *.config; *.xml
    Conversion: External program (Unicode filenames)
    Loading: C:\temp\myscript.cmd "%s" "%t"

    And the batch file "myscript.cmd" contains the following line which calls the PowerShell script and pipes the output to the temp file passed in by BeyondCompare:

    %powershell% "&'C:\temp\myscipt.ps1'" "%1" ^> "%2"

    I've used SysInternals Procmon to check what's going on and the following process gets started:

    cmd /c ""C:\temp\myscript.cmd" "c:\docs\myfile.xml" "C:\Users\myaccount\AppData\Local\Temp\BC35FC1.tmp ""

    which then launches the powershell script:

    "C:\Windows\System32\WindowsPowerShell\v1.0\powers hell.exe" "&'C:\temp\myscript.ps1'" ""c:\docs\myfile.xml""

    and the temp file gets created but it contains the following text:

    "File F:\temp\normalize-xml.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for
    more details.
    At line:1 char:2
    + & <<<< 'C:\temp\myscript.ps1' c:\docs\myfile.xml
    + CategoryInfo : NotSpecified: ( [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException"

    If I try running the same command "cmd /c ""C:\temp\myscript.cmd" "c:\docs\myfile.xml" "C:\Users\myaccount\AppData\Local\Temp\BC35FC1.tmp """ from the command line it works and the temp file creates the converted xml.

    The execution policy for Powershell on my machine is set to "RemoteSigned", but I tried "Unrestricted" and got the same problem. I've also tried running BeyondCompare as an administrator but again it still puts the error message into the temp file.

    I'm not sure what else to try at this point - does anyone have any suggestions?

    Cheers,

    Mike
  • Aaron
    Team Scooter
    • Oct 2007
    • 16000

    #2
    Hello,

    Your general setup looks to be following our guidelines, as detailed in this KB article:
    http://www.scootersoftware.com/suppo...rnalconversion

    The first thing to try is to place all helper files into the BC3 Helpers\ directory. I would suggest creating a subfolder, and your myscript.cmd and myscript.ps1 in the subfolder. You can then use a relative path in BC3's File Format's dialog, similar to our XML Tidy rules:
    Helpers\HtmlTidy\XML_sorted.bat %s %t

    Would typing %powershell% "&'C:\temp\myscipt.ps1'" "%1" ^> "%2" directly into the command line work? If so, can this line be directly used as the External Conversion?
    Aaron P Scooter Software

    Comment

    Working...