LucD,
I am sorry, If my question was confusing.
I am able to capture the output of correct VM information in the output excel file using the below script.
$code = @'
$versionInfo = (Get-Item (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe').'(Default)').VersionInfo
$versionInfo | Select ProductVersion,FileVersion,FileName | ConvertTo-Csv
'@
$report1 = @()
Import-Csv -Path $reportlocation1 -UseCulture -PipelineVariable row |
ForEach-Object -Process {
$sInvoke = @{
VM = $_.Name
GuestCredential = $Creds
ScriptTYpe = 'powershell'
ScriptText = $code
}
$result = Invoke-VMScript @sInvoke
$report1 += $result.ScriptOutput | ConvertFrom-Csv |
Add-Member -MemberType NoteProperty -Name 'VM' -Value $row.Name -PassThru |
Select VM,ProductVersion,FileVersion,FileName
}
$report1 | ft -auto
$report1 | Export-Csv -Path $reportlocation1 -UseCulture -NoTypeInformation
I am unable to get the output from few of the VMs and I am unable to know which VM failed. I would like to capture the VM Name in the output file where the script was unable to get the requested information.
Invoke-VMScript : 01/18/2021 10:20:49 AM Invoke-VMScript Timeout error while waiting for VMware Tools to start in the guest.
At D:\myreports\Chrome_List_Install_Uninstall\get_chrome_versions_1.0.ps1:41 char:19
+ $result = Invoke-VMScript @sInvoke
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationTimeout: (:) [Invoke-VMScript], VimException
+ FullyQualifiedErrorId : Client20_VmGuestServiceImpl_WaitProcessInGuest_OperationTimeout,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript
ConvertFrom-Csv : Cannot validate argument on parameter 'InputObject'. The argument is null. Provide a valid value for the argument, and then try running the command again.
At D:\myreports\Chrome_List_Install_Uninstall\get_chrome_versions_1.0.ps1:42 char:44
+ $report1 += $result.ScriptOutput | ConvertFrom-Csv |
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [ConvertFrom-Csv], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ConvertFromCsvCommand