Я получаю следующую ошибку:
This command cannot be run due to the error: The system cannot find the file specified. + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand + PSComputerName : XXXXXX.yyy.com
Вот фрагмент кода:
if (($ToolsStatus -eq 'toolsOk' -OR $ToolsStatus -eq 'toolsOld') -AND $VMVSSStatus -eq $null -AND $OperatingSystem -match "64-bit" ) {
try{
Copy-Item -Path ".\64bit\$ToolsVersion.exe" -Destination "\\$FQDN\c$\" -Container -Recurse -Force -ErrorAction Stop
"File $ToolsVersion.exe copied on $vmName" | Do-Log
try {
Invoke-Command -ComputerName $FQDN -ScriptBlock {
Start-Process "C:\$ToolsVersion.exe" -ArgumentList '/s /v "/qn reboot=r ADDLOCAL=all"' -Wait
Start-Process "C:\$ToolsVersion.exe" -ArgumentList '/s /v "/qn reboot=r REMOVE=VSS"' -Wait
Start-Process "C:\$ToolsVersion.exe" -ArgumentList '/s /v "/qn reboot=r ADDLOCAL=VSS"' -Wait
"Installation completed on $vmName" | Do-Log
taskkill /IM vmtoolsd.exe /F
"VMtools process killed on $vmName" | Do-Log
Start-Service -Name VMTools
"VMware Tools service was started on $vmName" | Do-Log
}
}
catch [System.Management.Automation.RuntimeException]#PSRemotingTransportException
{
"Unable to install on $vmName. Following error was encountered:" +$_.Exception.GetType().FullName | Do-Log
}
Пожалуйста помоги.
Я предполагаю, что переменная $ToolsVersion
не определена в области действия Invoke-Command
, поскольку область действия выполняется на удаленной машине.
Пытаться:
Start-Process "C:\$Using:ToolsVersion.exe" -ArgumentList '/s /v "/qn reboot=r ADDLOCAL=all"' -Wait
вместо.
USING LOCAL VARIABLES
You can also use local variables in remote commands, but you must indicate that the variable is defined in the local session.
Beginning in Windows PowerShell 3.0, you can use the Using scope modifier to identify a local variable in a remote command. ...
ОБНОВЛЕНИЕ 1:
Чтобы получить журналы с пульта, вы должны изменить свой код на:
Invoke-Command -ComputerName $FQDN -ScriptBlock {
$computerName = $env:COMPUTERNAME
Start-Process "C:\$ToolsVersion.exe" -ArgumentList '/s /v "/qn reboot=r ADDLOCAL=all"' -Wait
Start-Process "C:\$ToolsVersion.exe" -ArgumentList '/s /v "/qn reboot=r REMOVE=VSS"' -Wait
Start-Process "C:\$ToolsVersion.exe" -ArgumentList '/s /v "/qn reboot=r ADDLOCAL=VSS"' -Wait
$logging = @()
$logging = "$computerName: Installation completed on $vmName"
taskkill /IM vmtoolsd.exe /F
$logging += "$computerName: VMtools process killed on $vmName"
Start-Service -Name VMTools
$logging += "$computerName: VMware Tools service was started on $vmName"
$logging
} | Do-Log
Здесь массив $logging
будет сериализован по сети. На вашем компьютере он десериализован, и каждая запись массива отправляется в ваш локальный конвейер.
Надеюсь, это поможет.
Спасибо, это сработало как шарм. Как вы видите выше, я пытаюсь вызвать функцию фильтра под названием «Do-Log» внутри блока сценария, но она не распознается. Как я могу заставить его работать?