title: Find exit code for executing a cmd command through PowerShell
body: <p>I am using a silent installation command to install software. I am running this command from PowerShell 3.0.</p>
  
  <pre><code>$silentInstall = C:\Users\Admin\Documents\Setup-2.0.exe exe /s /v"EULAACCEPTED=\"Yes\" /l*v c:\install.log /qn"
  
  Invoke-Expression $silentInstall
  </code></pre>
  
  <p>This runs the command which installs the software, but it does not wait for it to complete and goes ahead with the next lines of code. I want to have control over the installation so that I would know if it's completed or not.</p>
  
  <p>How do I get an error code for the <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-expression?view=powershell-6" rel="nofollow noreferrer">Invoke-Expression</a> cmdlet so that I can get to know if the cmd executed successfully or not?</p>