How can I know if Invoke-Command succeeded on multiple computers?

In the code below I can copy the Google Drive client to a remote computer and silently install it. I know it’s not much, but its the coolest thing I have created with PowerShell and I am kind of proud of it. :slight_smile: Anyway, what can I do to see if the command succeeded or not? I work at a school and I might use this to target all teacher computers or a specific computer lab.

$pc_names = @(Get-ADComputer -Filter {name -like '*OrgPC01*'} | select -expand name)
Foreach ($pc in $pc_names)
{
             Copy-Item -Path C:\Users\kyle\Downloads\gsync_enterprise.msi -Destination "\\$pc\C$\software" -Recurse
             Invoke-Command -ComputerName $pc -ScriptBlock {Start-Process "msiexec.exe" -ArgumentList "/i C:\software\gsync_enterprise.msi /qn" -Wait}


}

How would check on your local pc if a certain program is installed? The same cmdlets usually support the option ‘-ComputerName’.
You could try something like this:

Get-CimInstance -ClassName CIM_Product -ComputerName $Env:COMPUTERNAME | Where-Object -Property Name -Value *java* -Like

You just should change $Env:COMPUTERNAME to the pc you want to query and java to the product name you are looking for.

Or … to answer your actually initial question:

You could catch the exit code the msiexec.exe usually throws at the end of an installation:

$ExitCode = Start-Process -FilePath msiexec.exe … 

The possible exit codes for msiexec.exe are available here: Msiexec.exe