Powershell command fails when using PersonalFolder property (error I get: Get-Content : Cannot bind argument to parameter 'Path' because it is null.)

Donna 21 Reputation points
2021-11-05T14:17:54.88+00:00

Hello,

I have a window installer XML (WIX) installer. I run the bellow commands.

  1. when I use hard coded value of My document in the second part of the command - it works (see Command#1 below).
  2. when I use the [PersonalFolder] value in the second part of the command - it doesn't works (see Command#2 below).

<!--Command#1 - Work using hard coded value -->

<SetProperty Id="UpdateCsprojSamples2012"
                 Value="&quot;powershell&quot; Get-ChildItem -Path '[PersonalFolder]Visual Studio 2012\Projects\Micro Focus RDE Samples\' -Recurse -include *.csproj | &quot;ForEach-Object {((gc $_.FullName) -replace 'VS_MYDOCUMENTS', 'C:\Users\donnam\Documents\Visual Studio 2012') | Out-File $_.FullName -Encoding UTF8}&quot;"
                 Before="UpdateCsprojSamples2012" Sequence="execute" >NOT REMOVE="ALL"</SetProperty>
    <CustomAction Id="UpdateCsprojSamples2012" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="deferred" Impersonate="no"/>

<!-- Command#2 - Doesn't work using [PersonalFolder] -->

<SetProperty Id="UpdateCsprojSamples2012"
                 Value="&quot;powershell&quot; Get-ChildItem -Path '[PersonalFolder]Visual Studio 2012\Projects\Micro Focus RDE Samples\' -Recurse -include *.csproj | ForEach-Object {((gc $_.FullName) -replace 'VS_MYDOCUMENTS', '[PersonalFolder]') | Out-File $_.FullName -Encoding UTF8}"
                 Before="UpdateCsprojSamples2012" Sequence="execute" >NOT REMOVE="ALL"</SetProperty>
    <CustomAction Id="UpdateCsprojSamples2012" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="deferred" Impersonate="no"/>

Error I get from the second code section is:

WixQuietExec:  "powershell" Get-ChildItem -Path 'C:\Users\donnam\Documents\Visual Studio 2012\Projects\Micro Focus RDE Samples\' -Recurse -include *.csproj | ForEach-Object ((gc $_.FullName) -replace 'VS_MYDOCUMENTS', 'C:\Users\donnam\Documents\') | Out-File $_.FullName -Encoding UTF8
WixQuietExec:  Get-Content : Cannot bind argument to parameter 'Path' because it is null.
WixQuietExec:  At line:1 char:151
WixQuietExec:  + ...  -Recurse -include *.csproj | ForEach-Object ((gc $_.FullName) -repla ...
WixQuietExec:  +                                                       ~~~~~~~~~~~
WixQuietExec:      + CategoryInfo          : InvalidData: (:) , ParameterBindingValidationException
WixQuietExec:      + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetContentC 
WixQuietExec:     ommand
WixQuietExec:   
WixQuietExec:  Error 0x80070001: Command line returned an error.

why the second command fails?
I hope someone can help!

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,362 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 44,776 Reputation points
    2021-11-05T19:16:10.103+00:00

    Your problem is in the -replace.

    -replace 'VS_MYDOCUMENTS', '[PersonalFolder]')
    

    The replace works, but the replacement becomes '[PersonalFolder]' and when you use that string in a path the "[" and "]" together are interpreted as a set of characters to be used in sequence

    [PersonalFolder]\Documents\Visual Studio 2012
    

    So the Get-Content would try to get the contents of "P\Documents....", and then "e\Documents..." and then "r\Documents...", etc.

    In order for the substitution to work, you'd have to resolve the "[PersonalFolder]" and place that into a variable. Then replace "VS_MYDOCUMENTS" with the contents of the variable.

    0 comments No comments

0 additional answers

Sort by: Most helpful