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

This topic contains 2 replies, has 2 voices, and was last updated by  Olaf Soyk 1 year, 9 months ago.

  • Author
  • #54220

    Kyle Wilcox

    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. 🙂 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}
  • #54221

    Olaf Soyk

    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.

    • #54224

      Olaf Soyk

      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

You must be logged in to reply to this topic.