Невозможно преобразовать System.Object [] в тип {System.String, System.Management.Automation.ScriptBlock} - PullRequest
0 голосов
/ 19 апреля 2019

Когда я использую Invoke-команду в Powershell, Select-object генерирует ошибку в программе.

$pc='server1','server2'

$csv = "\\mypc\c$\Users\me\Desktop\Script\PC2\Length.csv"
$command=Get-ChildItem -Path C:\Users -Exclude C:\Users\*\AppData -Recurse -Force -File | 
where Length -gt 300mb | Sort-Object -Property Length -descending | 
Out-String -stream | Select-Object -Property $pc,Directory,Name,$properties | 
Export-Csv -Path $csv -Delimiter ';' -Encoding UTF8 -NoTypeInformation

Invoke-Command -Computername $pc -ScriptBlock {$command}

Вот код ошибки:

Select-Object : Impossible de convertir System.Object[] dans l’un des types suivants {System.String, System.Management.Automation.ScriptBlock}.
Au caractère C:\Users\me\Desktop\Script\ScanPC.ps1:40 : 22
+ ... ng -stream | Select-Object -Property $pc,Directory,Name,$properties |

1 Ответ

0 голосов
/ 20 апреля 2019

Наконец-то я нашел свою ошибку, моя переменная не была объявлена ​​в «Invoke-Command».

Однако, когда я запускаю команду на удаленном сервере с помощью Invoke-Command, я получаю эту ошибку на нескольких серверах:

Impossible de trouver un paramètre correspondant au nom « File ».
+ CategoryInfo          : InvalidArgument : (:) [Get-ChildItem], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
+ PSComputerName        : Server1

Команда, которую я посылаю:

Get-ChildItem -Path C:\Users -Recurse -Force -File | 
Sort-Object -Property Length -descending | 
Select-Object -Property Directory,Name,$properties | 
Export-Csv -Path \\Server2\c$\script\LogER\file.csv -Delimiter ';' -Encoding UTF8 - 
NoTypeInformation

Когда я запускаю команду элемента Get-Child на Server2 и сохраняю вывод в файл Server2, он работает, но Server1 на Server2 не работает

...