Ryan G
Ryan G

Reputation: 1

opening windows form in powershell

I am attempting to create a powershell script that will ask the user to restart the computer after a certain number of days. I'm building the script in VS 2012, and would like the script to open a windows form I'm building in the project.

$lastboot = (Get-CimInstance -Class win32_operatingsystem).lastbootuptime
$cutoff = (Get-Date).AddDays(-30)
If(($lastboot) -le ($cutoff)) {
    Write-Output "Reboot Required"
    }
Else{
    Write-Output "No Reboot Required at this time"
}

Any advice on how I can get the script to call up the restart windows form (restartForm.cs).

Upvotes: 0

Views: 2338

Answers (2)

postanote
postanote

Reputation: 16086

FYI... There are tools you can add to VS to help with this.

Just add PowerShell to you VS project and add to your existing project. You just download and use the PowerShell VS integration add-in. Use your form designer.

PowerShell Windows Forms Designer Demo in Visual Studio https://www.youtube.com/watch?v=418sH2lcZ1w -Updated- https://www.youtube.com/watch?v=q4CsFblKotc&list=UUIrhSHyw-ySF4eQFkt6fQSA&index=10

PowerShell Tools for Visual Studio – Now Available

Over the past few months we (at Microsoft) have been working with Adam Driscoll, a Microsoft MVP who started this extension back in 2013. Adam released it as open source on GitHub and a few months ago Microsoft created a fork to join community and contribute to the project.

https://blogs.msdn.microsoft.com/powershell/2015/04/19/powershell-tools-for-visual-studio-now-available

PowerShell Tools for Visual Studio 2012

PowerShell Tools for Visual Studio adds language support for PowerShell in Visual Studio 2012.

https://marketplace.visualstudio.com/items?itemName=AdamRDriscoll.PowerShellToolsforVisualStudio2012

PowerShell Pro Tools for Visual Studio PowerShell Pro Tools supports Visual Studio Community. Get a full featured PowerShell IDE with UI development and packaging https://poshtools.com/powershell-pro-tools-for-visual-studio

Upvotes: 0

Palle Due
Palle Due

Reputation: 6292

Why don't you build the GUI in powershell?

Add-Type -AssemblyName System.Windows.Forms

$form = New-Object system.Windows.Forms.Form
$form.Text = "My Fancy Windows Form"
[void]$form.ShowDialog()
$form.Dispose()

Upvotes: 1

Related Questions