0

I am trying to set a task sequence variable using a PowerShell form.

Setting the task sequence variable and controlling the ProgressUI was straightforward but when it comes to the form itself, it just does not appear.

Reducing my script to the minimum, these four lines of code open a blank form when run from PowerShell, but running the same script from an MDT task sequence action "Run PowerShell Script" does not display the form and the task sequence is blocked at that point. My guess is that the form is open but just not visible.

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$form = New-Object System.Windows.Forms.Form
$form.Add_Shown({$form.Activate()}) 
$dialogResult = $form.ShowDialog()

Accidentally I found that if I added the following line anywhere before the ShowDialog() call the form is displayed correctly (as is an empty GridView)

"" | Out-GridView

Looking at this example online, http://www.scconfigmgr.com/2015/07/17/windows-forms-powershell-gui-template/, I can't see a material difference and setting the extra $form properties doesn't help.

Can anyone offer any suggestion on this?

I'm using MDT 6.3.8443.1000

Mark Elvers
  • 570
  • 2
  • 9

1 Answers1

0

From my time with System Center and MDT, this was a MDT specific issue and has been a pain point for a long time. The only consistent workaround is to call an external script that has the form/dialog in that you want to use.

cmd.exe /c powershell.exe "full path to script.ps1"

Back in the day, there have been those who tried to use MDT Studio http://mdtwizardstudio.codeplex.com but it was not as successful as it was hoped.

Full disclosure, I have not been anywhere near System Center and or MDT since circa 2009 - 2014, so, I have no way of really looking at this further. Yet, I've always shelled out to a script when I could not get X or Y done.

postanote
  • 15,138
  • 2
  • 14
  • 25