Почему я не могу использовать блок скрипта с параметром значения set-content? (отложенное связывание) - PullRequest
1 голос
/ 24 мая 2019

Хм, а почему это не работает? Обычно, если параметр принимает входные данные конвейера, я могу использовать блок скрипта с ним.

PS C:\users\js> (Get-Content -Path file) | Set-Content -Path file -Value { $_ -Replace 1,2 }

Set-Content : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the
input and its properties do not match any of the parameters that take pipeline input.
At line:1 char:28
+ ... ntent -path file) | set-content -path file -value { $_ -replace 1,2 }
+                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (111:PSObject) [Set-Content], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.SetContentCommand

Set-Content : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the
input and its properties do not match any of the parameters that take pipeline input.
At line:1 char:28
+ ... ntent -path file) | set-content -path file -value { $_ -replace 1,2 }
+                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (111:PSObject) [Set-Content], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.SetContentCommand

Set-Content : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the
input and its properties do not match any of the parameters that take pipeline input.
At line:1 char:28
+ ... ntent -path file) | set-content -path file -value { $_ -replace 1,2 }
+                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (111:PSObject) [Set-Content], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.SetContentCommand

Такого рода работы, но это не тот результат, которого я хочу. Он принимает блок скрипта буквально.

PS C:\users\js> (Get-Content -Path file) | Set-Content -Value { $_ -Replace 1,2 }
PS C:\users\js> Get-Content -Path file
 $_ -Replace 1,2

Я бы ожидал, что это будет работать так:

PS C:\users\js> Write-Output -InputObject 111,111,111 | Write-Output -InputObject { $_ -Replace 1,2 }

222
222
222
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...