Like this:
Add-Type -AssemblyName System.Windows.Forms $currentForm = New-Object System.Windows.Forms.Form
You can see the available properties of the form object, as well as their current values, like this:
Write-Output $currentForm
Result of performance:
AcceptButton : ActiveMdiChild : AllowTransparency : False AutoScale : True AutoScaleBaseSize : {Width=5, Height=13} AutoScroll : False AutoSize : False AutoSizeMode : GrowOnly AutoValidate : EnablePreventFocusChange BackColor : Color [Control] FormBorderStyle : Sizable CancelButton : ClientSize : {Width=284, Height=262} ControlBox : True DesktopBounds : {X=125,Y=125,Width=300,Height=300} DesktopLocation : {X=125,Y=125} DialogResult : None HelpButton : False Icon : (Значок) IsMdiChild : False IsMdiContainer : False IsRestrictedWindow : False KeyPreview : False Location : {X=125,Y=125} MaximumSize : {Width=0, Height=0} MainMenuStrip : Margin : {Left=3,Top=3,Right=3,Bottom=3} Menu : MinimumSize : {Width=0, Height=0} MaximizeBox : True MdiChildren : {} MdiParent : MergedMenu : MinimizeBox : True Modal : False Opacity : 1 OwnedForms : {} Owner : RestoreBounds : {X=125,Y=125,Width=300,Height=300} RightToLeftLayout : False ShowInTaskbar : True ShowIcon : True Size : {Width=300, Height=300} SizeGripStyle : Auto StartPosition : WindowsDefaultLocation TabIndex : 0 TabStop : True Text : TopLevel : True TopMost : False TransparencyKey : Color [Empty] WindowState : Normal AutoScaleDimensions : {Width=0, Height=0} AutoScaleMode : Inherit BindingContext : {} ActiveControl : CurrentAutoScaleDimensions : {Width=0, Height=0} ParentForm : AutoScrollMargin : {Width=0, Height=0} AutoScrollPosition : {X=0,Y=0} AutoScrollMinSize : {Width=0, Height=0} DisplayRectangle : {X=0,Y=0,Width=284,Height=262} HorizontalScroll : System.Windows.Forms.HScrollProperties VerticalScroll : System.Windows.Forms.VScrollProperties DockPadding : AccessibilityObject : ControlAccessibleObject: Owner = System.Windows.Forms.Form, Text: AccessibleDefaultActionDescription : AccessibleDescription : AccessibleName : AccessibleRole : Default AllowDrop : False Anchor : Top, Left AutoScrollOffset : {X=0,Y=0} LayoutEngine : System.Windows.Forms.Layout.DefaultLayout BackgroundImage : BackgroundImageLayout : Tile Bottom : 425 Bounds : {X=125,Y=125,Width=300,Height=300} CanFocus : False CanSelect : False Capture : False CausesValidation : True ClientRectangle : {X=0,Y=0,Width=284,Height=262} CompanyName : Microsoft Corporation ContainsFocus : False ContextMenu : ContextMenuStrip : Controls : {} Created : False Cursor : [Cursor: Default] DataBindings : {} IsDisposed : False Disposing : False Dock : None Enabled : True Focused : False Font : [Font: Name=Microsoft Sans Serif, Size=8,25, Units=3, GdiCharSet=204, GdiVerticalFont=F alse] ForeColor : Color [ControlText] Handle : 10029516 HasChildren : False Height : 300 IsHandleCreated : True InvokeRequired : False IsAccessible : False IsMirrored : False Left : 125 Name : Parent : ProductName : Microsoft® .NET Framework ProductVersion : 4.0.30319.34251 RecreatingHandle : False Region : Right : 425 RightToLeft : No Site : Tag : Top : 125 TopLevelControl : System.Windows.Forms.Form, Text: UseWaitCursor : False Visible : False Width : 300 WindowTarget : System.Windows.Forms.Control+ControlNativeWindow PreferredSize : {Width=16, Height=38} Padding : {Left=0,Top=0,Right=0,Bottom=0} ImeMode : NoControl Container :
We can also change the current properties of the object, say, change the size of the form by setting the value of height and width to 100:
$currentForm.Height = 100 $currentForm.Width = 100
The window is called by the ShowDialog method, like this:
$currentForm.ShowDialog()
On the Internet there are many examples describing the creation of certain forms using PowerShell. For example, Windows PowerShell Tip: Creating a Custom Input Box