title: Progress bar powershell script doesn't work when called from a batch script
body: <p>I am facing this situation where, when i run my powershell script from PowershellISE it works as desired. But when the same script is called from a batch file the part of the powershell script with a progressbar function is written, it shows no response. I am unable to find out what is it that i am missing.
  The powershell script is :</p>
  
  <pre><code>[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
  [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null
  
  
  #FUNCTION- progress bar
  function progress-bar {
  $Runspace = [runspacefactory]::CreateRunspace()
  $PowerShell = [System.Management.Automation.PowerShell]::Create()
  $PowerShell.runspace = $Runspace
  $Runspace.Open()
  
  [void]$PowerShell.AddScript({
  
  $Form = New-Object System.Windows.Forms.Form
  $Form.width = 1000
  $Form.height = 200
  $Form.Text = "text"
  $Form.Font = New-Object System.Drawing.Font("Times New Roman" ,12, [System.Drawing.FontStyle]::Regular)
  $Form.MinimizeBox = $False
  $Form.MaximizeBox = $False
  $Form.WindowState = "Normal"
  $Form.StartPosition = "CenterScreen"
  
  $ProgressBar = New-Object System.Windows.Forms.ProgressBar
  $ProgressBar.Maximum = 100
  $ProgressBar.Minimum = 0
  $ProgressBar.Location = new-object System.Drawing.Size(10,70)
  $ProgressBar.size = new-object System.Drawing.Size(967,10)
  $ProgressBar.style = 'Marquee'
  $MessagesLabel = New-Object System.Windows.Forms.Label
  $MessagesLabel.AutoSize = $true
  $MessagesLabel.Location = New-Object System.Drawing.Point(10,45)
  $MessagesLabel.Text = "message for user"
  
  $ShownFormAction = {
      $Form.Activate()
  
     # $Form.Dispose()
  }
  
  $Form.Add_Shown($ShownFormAction)
  $Form.Controls.Add($MessagesLabel)
  $Form.Controls.Add($ProgressBar)
  
  $Form.ShowDialog()
  
  })
  $PowerShell.BeginInvoke()
  }
  #begin main process
  progress-bar
  Get-Date
  Start-Sleep 5
  #end main process
  </code></pre>
  
  <p>and the batch file which i am using to call this above script contains:</p>
  
  <pre><code>echo off
  SET HomeDir=%~dp0
  SET PowerShellScriptPath=%HomeDir%
  PowerShell -NoProfile -ExecutionPolicy Bypass -Command "&amp; '%HomeDir%\1.ps1'";
  exit
  </code></pre>
  
  <p>Please help with any pointer to solution.</p>