question

Donna-5028 avatar image
0 Votes"
Donna-5028 asked RichMatheisen-8856 answered

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

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.