Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell with winform and install-windowsfeature

$
0
0

hi,

I have this strange issue with a powershell GUI I am creating. Basically I am building a small GUI that will install features and roles on windows 2012 servers. Here is the sample code:

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

#the form
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Powershell - test"
$objForm.Size = New-Object System.Drawing.Size(400,400)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
[System.Windows.Forms.Application]::EnableVisualStyles()

$btncmd = New-Object system.windows.forms.Button
$btncmd.name = "btncmd"
$btncmd.Location = New-Object System.Drawing.Size(156,230)
$btncmd.Size = New-Object System.Drawing.Size(116,43)
$btncmd.Text = "powershell"
$btncmd.BackColor = [System.Drawing.SystemColors]::ControlDark
$btncmd.ForeColor = [System.Drawing.Color]::White
$objForm.Controls.Add($btncmd)

$btncmd.add_Click( {install-windowsfeature dns -IncludeManagementTools -verbose} )

[void] $objForm.ShowDialog()

Now to the strange part. The progressbar for the install-windowsfeature cmdlet stops at 10% and does not continue. If I run the command:

install-windowsfeature dns -IncludeManagementTools -verbose

in a regular powershell window, it completes as normal. When I execute the command with a button on a form, this is the result:

Verbose output shows it is stuck at "Prerequisite processing started..."

Please help, I am completely stuck and am unable to continue until this is resolved or I have a workaround.

I have tried launching it as STA and as 32/64 powershell, no avail.

Cheers 

Tore




Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>