0

The issue is that I get no error, but I get a loading screen showing what appears to be PowerShell successfully called, but everything is suspended (no failures, it just lingers with Windows PowerShell [copyright info]. In digging around, I decided to just see if I could get it to write out a warning and it appears that it is setting the execution policy to unrestricted (which is how my system is currently set as well).

I did think that maybe the execution policy wasn't set to unrestricted, so I tried passing in the -Force parameter, but got an error about it being invalid.

The PS script:

Write-Warning "Called successfully.

The XML code to call it:

<Target Name="DoSomething">
    <PropertyGroup>
    <ponyone>FullOne</ponyone>
    <ponytwo>HalfOne</ponytwo>
    <ponytree>LatterExcen</ponytree>
    </PropertyGroup>
    <Exec Command="powershell.exe -NonInteractive -executionpolicy Unrestricted" />
    <Exec Command="powershell.exe .\Do-Something.ps1 FullOne HalfOne LatterExcen" />
</Target>

Confirmed that this is because of the executionpolicy; when I only run the second script, it errors due to scripts being disabled, even though PowerShell shows the execution policy is unrestricted.

1
  • What is your question and wich of the two invokations you show have a problem? Commented May 25, 2016 at 7:48

1 Answer 1

2

Using the following msbuild project:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
    <Target Name="RunPSScript">
        <Exec Command="powershell.exe -NonInteractive -executionpolicy Unrestricted -command &quot;.\Do-Something.ps1&quot;"/>  
    </Target>
</Project>

The PS script is executed as expected, given the following output:

Microsoft (R) Build Engine version 14.0.25123.0
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 5/25/2016 1:43:41 PM.
Project "D:\lab\my.proj" on node 1 (default targets).
RunPSScript:
  powershell.exe -NonInteractive -executionpolicy Unrestricted -command ".\Do-Something.ps1"
EXEC : warning : Called successfully. [D:\lab\my.proj]
Done Building Project "D:\lab\my.proj" (default targets).


Build succeeded.

"D:\lab\my.proj" (default target) (1) ->
(RunPSScript target) ->
  EXEC : warning : Called successfully. [D:\lab\my.proj]

    1 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.36

More details here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.