Ampersand behavior changed in Powershell 3.0?

I got the following error when installing windirstat and ilmerge on Chocolatey . I suspect that the behavior of ampersands has changed in PowerShell 3.0.

Running powershell -NoProfile -ExecutionPolicy unrestricted -Command "& import-module -name 'C:\NuGet\chocolateyInstall\helpers\chocolateyInstaller.psm1'; & 'C:\NuGet\lib\ilmerge.2.10.526.4\tools\chocolateyInstall.ps1'". This may take awhile and permissions may need to be elevated, depending on the package. ilmerge did not finish successfully. Boo to the chocolatey gods! ----------------------- [ERROR] The expression after '&' in a pipeline element produced an invalid object. It must result in a command name, script block or Command Info object. ----------------------- 
+4
source share
2 answers

The problem was not the ampersand, but the replacement $oc = Get-Command 'Write-Host' | ?{$_.ModuleName -eq 'Microsoft.PowerShell.Utility'} $oc = Get-Command 'Write-Host' | ?{$_.ModuleName -eq 'Microsoft.PowerShell.Utility'} with $oc = Get-Command 'Write-Host' -Module 'Microsoft.PowerShell.Utility' I replaced $oc = Get-Command 'Write-Host' -Module 'Microsoft.PowerShell.Utility' similar replacement for the Write-Error wrapper.

+4
source

How about starting PowerShell with the -version 1.0 or 2.0 option? Then run the above command and see if there is any difference.

At the command line

PowerShell -version 2.0

+2
source

Source: https://habr.com/ru/post/1381003/


All Articles