PowerShellWixExtension icon indicating copy to clipboard operation
PowerShellWixExtension copied to clipboard

Issues with [\[] [\]] with using [XML] class

Open Mobe1969 opened this issue 5 years ago • 4 comments

I'm really struggling to get this working properly with XML objects [[]xml[]]. So if I have as a simple example. I also tried an external powershell file and got an error also, but no less detail in the log.

if ($null -eq $null) { [[]xml[]](Get-Content $CurrentConfig) }

It is transformed to this in the msiexec log where it prints the script being run: if ($null -eq $null) (Get-Content $CurrentConfig) } So it is now missing "{ [[]xml[]]", so both the opening brace of the block, and the expected [xml] are gone.

Looking at the msiexec verbose log, the powershell script being executed is logged, and the script not only has the [[]xml[]] removed, the preceding { on the if statement has been removed also.

See the attached fragment 1.txt - It doesn't paste as code

The log section from msiexec is in the fragment 2.txt. It won't paste inline.

If I run the script from a file (using directly [xml]), I get this: MSI (s) (DC:F4) [12:45:15:932]: Executing op: CustomActionSchedule(Action=PowerShellFilesDeferred,ActionType=1025,Source=BinaryData,Target=PowerShellFilesDeferred,CustomActionData=xml=<r> <d Id="UpdateBindings" file="" args="" IgnoreErrors="0" /> </r>) MSI (s) (DC:F8) [12:45:15:934]: Invoking remote custom action. DLL: C:\WINDOWS\Installer\MSI18D1.tmp, Entrypoint: PowerShellFilesDeferred SFXCA: Extracting custom action to temporary directory: C:\WINDOWS\Installer\MSI18D1.tmp-\ SFXCA: Binding to CLR version v4.0.30319 Calling custom action PowerShellActions!PowerShellActions.CustomActions.PowerShellFilesDeferred PowerShellFilesDeferred start PowerShell terminating error, returning Failure System.Management.Automation.RuntimeException: The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object. at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input) at PowerShellActions.PowerShellTask.Execute() at PowerShellActions.CustomActions.FilesDeferred(Session session, String deferredProperty) CustomAction PowerShellFilesDeferred returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox) Action ended 12:45:16: InstallFinalize. Return value 3. MSI (s) (DC:F4) [12:45:16:724]: Note: 1: 2265 2: 3: -2147287035

Mobe1969 avatar Feb 06 '20 22:02 Mobe1969

OK, I'll try attach as txt files... Fragment 2.txt fragment1.txt

Mobe1969 avatar Feb 06 '20 22:02 Mobe1969

PS - I get the same script file error with the & one when I use the Test.ps1 from this codebase

Mobe1969 avatar Feb 07 '20 03:02 Mobe1969

Not exactly sure, but I'd suggest starting with the examples in https://github.com/flcdrg/PowerShellWixExtension/tree/master/Tests (that do have escaped square brackets), and confirm that you can get those to work correctly.

flcdrg avatar Feb 08 '20 10:02 flcdrg

I too get a problem with the square brackets:

<!-- Original script -->
</powershell:Script>

<powershell:Script Id="A" Elevated="yes"><![CDATA[
try{
  $myProcess = Start-Process -NoNewWindow -PassThru -FilePath $Env:Programfiles'\A\A.exe'
  Start-Sleep -Seconds 20

  Stop-Process -Id  $myProcess.Id[\[]0[\]] -ErrorAction SilentlyContinue

  echo "Have fun"
}
catch{
	Write-Host $_
}
]]>
</powershell:Script>

Which becomes the following when launched from the MSI:

<!-- Distorted script -->
</powershell:Script>

<powershell:Script Id="A" Elevated="yes"><![CDATA[
try{
  $myProcess = Start-Process -NoNewWindow -PassThru -FilePath $Env:Programfiles'\A\A.exe'
  Start-Sleep -Seconds 20

  Stop-Process -Id  $myProcess.Id[0] -ErrorAction SilentlyContinue

  echo "Have fun"
}
catch{
	Write-Host $_
}
 -ErrorAction SilentlyContinue

  echo "Have fun"
}
catch{
	Write-Host $_
}
]]>
</powershell:Script>

cz-dev-ge avatar Jan 30 '24 10:01 cz-dev-ge