title: PowerShell function not running as expected
body: <p>I have a curious case that I cannot fathom the reason for...</p>
  
  <p>Please know I am a novice to PowerShell.</p>
  
  <p>I am working on a PowerShell menu system to help automate building out new computers in my environment. I have a PS1 file that holds the script for an app install. When I use the script to reference this I am able to run it and have no issue. However, when I try inserting this into a function and referencing it does not.</p>
  
  <p>This works:</p>
  
  <pre><code>4       #   Microsoft Office 32-bit
              {
                  Write-Host "`nMicrosoft Office 32-bit..." -ForegroundColor Yellow
  
                  # {installMS32Bit}
                  Invoke-Expression "cmd /c start powershell -NoExit -File '\\**SERVERPATH**\menuItems\ms_office\32-bit\install.ps1'"
  
                  Start-Sleep -seconds 2
              }
  </code></pre>
  
  <p>This does not:</p>
  
  <pre><code>function installMS32Bit(){
  
  Invoke-Expression "cmd /c start powershell -NoExit -File '\\**SERVERPATH**\menuItems\ms_office\32-bit\install.ps1'"
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>4       #   Microsoft Office 32-bit
              {
                  Write-Host "`nMicrosoft Office 32-bit..." -ForegroundColor Yellow
  
                  {installMS32Bit}
  
                  Start-Sleep -seconds 2}
  </code></pre>
  
  <p>install.ps1 file:</p>
  
  <pre><code>    # Copy MS Office uninstall and setup to local then run and install 32-bit Office
  Copy-Item -Path '\\**SERVERPATH**\menuItems\ms_office\setup.exe' -Destination 'C:\temp\' -Force
  Copy-Item -Path '\\**SERVERPATH**\menuItems\ms_office\uninstall.xml' -Destination 'C:\temp\' -Force
  Copy-Item -Path '\\**SERVERPATH**\menuItems\ms_office\32-bit\Setup.exe' -Destination 'C:\temp' -Force
  
  Invoke-Expression ("cmd /c 'C:\temp\setup.exe' /configure 'C:\temp\uninstall.xml'")
  
  Start-Process -FilePath 'C:\temp\Setup.exe'
  </code></pre>
  
  <p>Secondary question and a little explanation for Invoke-Expression...</p>
  
  <p>I like to see progress and like to have secondary windows open to monitor the new process being run. I was unable to find a solution with a persistent window that worked for me to do this without Invoke-Expression.</p>
  
  <p>If there is a better way to do this in PowerShell I am all ears!</p>