Note that there are some explanatory texts on larger screens.

plurals
  1. POInvoking PowerShell commands from C# custom action in WiX installation
    primarykey
    data
    text
    <p><strong>Background:</strong> I'm writing an installation for a SharePoint component. In addition to getting the software onto the target machine, I want to properly configure it. SharePoint (esp. 2010) exposes its management functionality via PowerShell. So I wrote a C# custom action to invoke a series of commands, like this:</p> <pre><code>Runspace runSpace = RunspaceFactory.CreateRunspace(); runSpace.Open(); Pipeline pipeline = runSpace.CreatePipeline(); Command addSnapin = new Command("Add-PSSnapin"); addSnapin.Parameters.Add("Name", "Microsoft.SharePoint.Powershell"); pipeline.Commands.Add(addSnapin); pipeline.Invoke(); Command getSearchApp = new Command("Get-SPEnterpriseSearchServiceApplication"); pipeline = runSpace.CreatePipeline(); pipeline.Commands.Add(getSearchApp); Object searchApp = pipeline.Invoke().First().BaseObject; /* pass searchApp to other PS cmdlets */ </code></pre> <p><strong>Problem:</strong> When I run this code from a test executable, it works fine. However, it does not work when run from a custom action. It fails, and the log contains the message "The term 'Get-SPEnterpriseSearchServiceApplication' is not recognized as the name of a cmdlet...". This cmdlet is supposed to be imported by the <code>Add-PSSnapin</code> command (which succeeded, as far as I can tell).</p> <p><strong>Questions:</strong> Why can PS not find the function, when the same command sequence works in the PS console and when run in my test program? Is there any easier way to go about this process? WiX didn't seem to have much support for complex PS custom actions (not that mine is very complicated, but it's not a one-liner).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload