{"id":24,"date":"2015-11-01T22:37:48","date_gmt":"2015-11-01T17:07:48","guid":{"rendered":"http:\/\/vmwareenterprise.com\/?page_id=24"},"modified":"2015-11-01T22:37:48","modified_gmt":"2015-11-01T17:07:48","slug":"powershell","status":"publish","type":"page","link":"http:\/\/jeevanbobba.uk\/?page_id=24","title":{"rendered":"Powershell"},"content":{"rendered":"<h1 style=\"line-height: 16pt; list-style-type: disc; margin: 24pt 0in 0pt; clear: none\">\n\t<font face=\"Cambria\"><font color=\"#365f91\" style=\"font-size: 14pt\"><font style=\"font-weight: bold\">The Simplest Form<\/font><\/font><\/font><br \/>\n<\/h1>\n<p>\n\t&nbsp;\n<\/p>\n<h1 style=\"list-style-type:disc;clear:none;\">\n\tThe Simplest Form<br \/>\n<\/h1>\n<p style=\"list-style-type:disc;\">\n\tThere are only three things required to launch a form from PowerShell:\n<\/p>\n<ol style=\"list-style-type:disc;\">\n<li>\n\t\tYou must load the System.Windows.Forms assembly (if not already done);\n\t<\/li>\n<li>\n\t\tYou must create a new object of type system.windows.forms.form; and,\n\t<\/li>\n<li>\n\t\tYou must call the ShowDialog() method on your new object. Note&mdash;don&rsquo;t try calling the Show() method, unless you want your script to hang.\n\t<\/li>\n<\/ol>\n<p style=\"list-style-type:disc;\">\n\tFor example:\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tAdd-Type -AssemblyName System.Windows.Forms\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form = New-Object system.Windows.Forms.Form\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.ShowDialog()\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tDepending on your Windows shell environment, this is what your form might look like:\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t<a href=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/4478.clip_5F00_image001_5F00_0FE1765B.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"clip_image001\" border=\"0\" height=\"300\" src=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/2728.clip_5F00_image001_5F00_thumb_5F00_03DF8627.png\" style=\"border-bottom:0px;border-left:0px;border-top:0px;border-right:0px;\" title=\"clip_image001\" width=\"300\" \/><\/a>\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tOf course, that&rsquo;s not terribly useful, so we&rsquo;ll keep going.\n<\/p>\n<h1 style=\"list-style-type:disc;clear:none;\">\n\tAdding Some Text<br \/>\n<\/h1>\n<p style=\"list-style-type:disc;\">\n\tText will be helpful in adding some purpose to our form. There are a couple of pieces of text we&rsquo;ll add.\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tFirst, let&rsquo;s add a window title for the form by setting the form&rsquo;s Text property. This will show up in the top of the form and will also serve as the window title as shown in the task bar.\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tThen we&rsquo;ll add some text in the main window by adding a label control. In order to add a label, we need to create a new Label object, set the relevant properties and add it to the Controls collection of the form. For now, we&rsquo;ll set only two properties&mdash;Text and AutoSize. Enabling AutoSize will ensure that our label is large enough to display all our text.\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tAdd-Type -AssemblyName System.Windows.Forms\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form = New-Object system.Windows.Forms.Form\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Text = &quot;Sample Form&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label = New-Object System.Windows.Forms.Label\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label.Text = &quot;This form is very simple.&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label.AutoSize = $True\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Controls.Add($Label)\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.ShowDialog()\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t<a href=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/2235.clip_5F00_image002_5F00_14E3B40A.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"clip_image002\" border=\"0\" height=\"300\" src=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/4314.clip_5F00_image002_5F00_thumb_5F00_01C2875E.png\" style=\"border-bottom:0px;border-left:0px;border-top:0px;border-right:0px;\" title=\"clip_image002\" width=\"300\" \/><\/a>\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tNote &ndash; Most forms will contain at least several controls. Usually there would be at least one button. We&rsquo;ll add more controls later in this series, but for now we&rsquo;ll just stick with a single label.\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tWe might want to change the font used by the form. In order to change the font, we need to create a new font object with the appropriate properties and assign the new font object to the form&rsquo;s Font property.\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tAdd-Type -AssemblyName System.Windows.Forms\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form = New-Object system.Windows.Forms.Form\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Text = &quot;Sample Form&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Font = New-Object System.Drawing.Font(&quot;Times New Roman&quot;,18,[System.Drawing.FontStyle]::Italic)\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t# Font styles are: Regular, Bold, Italic, Underline, Strikeout\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Font = $Font\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label = New-Object System.Windows.Forms.Label\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label.Text = &quot;This form is very simple.&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label.AutoSize = $True\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Controls.Add($Label)\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.ShowDialog()\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t<a href=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/2251.clip_5F00_image003_5F00_40B407F9.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"clip_image003\" border=\"0\" height=\"300\" src=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/5554.clip_5F00_image003_5F00_thumb_5F00_235EB02F.png\" style=\"border-bottom:0px;border-left:0px;border-top:0px;border-right:0px;\" title=\"clip_image003\" width=\"300\" \/><\/a>\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tNow we have a bit of a problem because the text is too large to fit on the form in its default size. There are a few different ways we could address this:\n<\/p>\n<ul style=\"list-style-type:disc;\">\n<li>\n\t\tSpecify a form size &ndash; we could set a particular height and width that would be large enough. This would work, but it&rsquo;s somewhat difficult to figure out what the appropriate size should be.\n\t<\/li>\n<\/ul>\n<p style=\"list-style-type:disc;\">\n\t$Form.Width = 500\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Height = 200\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t<a href=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/4786.clip_5F00_image004_5F00_5DD9B003.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"clip_image004\" border=\"0\" height=\"173\" src=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/1830.clip_5F00_image004_5F00_thumb_5F00_4EC2D129.png\" style=\"border-bottom:0px;border-left:0px;border-top:0px;border-right:0px;\" title=\"clip_image004\" width=\"426\" \/><\/a>\n<\/p>\n<ul style=\"list-style-type:disc;\">\n<li>\n\t\tEnable scroll bars &ndash; By enabling AutoScroll, we allow the user to scroll over to see the remaining text. This is obviously not an optimum solution, but scroll bars are probably a good idea when necessary.\n\t<\/li>\n<\/ul>\n<p style=\"list-style-type:disc;\">\n\t$Form.AutoScroll = $True\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t<a href=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/4061.clip_5F00_image005_5F00_6D994507.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"clip_image005\" border=\"0\" height=\"300\" src=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/4477.clip_5F00_image005_5F00_thumb_5F00_5A78185B.png\" style=\"border-bottom:0px;border-left:0px;border-top:0px;border-right:0px;\" title=\"clip_image005\" width=\"300\" \/><\/a>\n<\/p>\n<ul style=\"list-style-type:disc;\">\n<li>\n\t\tEnable AutoSize &ndash; This is a much better idea for our purposes.&nbsp; By enabling AutoSize on the form, it will automatically resize to accommodate whatever controls we add to it.\n\t<\/li>\n<\/ul>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<ul style=\"list-style-type:disc;\">\n<li>\n\t\t.AutoSize = $True\n\t<\/li>\n<li>\n\t\t.AutoSizeMode = &quot;GrowAndShrink&quot;\n\t<\/li>\n<\/ul>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;&nbsp;&nbsp; # or GrowOnly\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tHowever, you should know that enabling AutoSize in this way will prevent the user from manually resizing the form.&nbsp; The strategy you choose will depend on your specific requirements.\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tHere is the new form code:\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tAdd-Type -AssemblyName System.Windows.Forms\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form = New-Object system.Windows.Forms.Form\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Text = &quot;Sample Form&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tForm.AutoScroll = $True\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.AutoSize = $True\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.AutoSizeMode = &quot;GrowAndShrink&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;&nbsp;&nbsp; # or GrowOnly\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tFont = New-Object System.Drawing.Font(&quot;Times New Roman&quot;,24,[System.Drawing.FontStyle]::Italic)\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;&nbsp;&nbsp; # Font styles are: Regular, Bold, Italic, Underline, Strikeout\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Font = $Font\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label = New-Object System.Windows.Forms.Label\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label.Text = &quot;This form is very simple.&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label.AutoSize = $True\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Controls.Add($Label)\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.ShowDialog()\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t<a href=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/2313.clip_5F00_image006_5F00_4B613981.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"clip_image006\" border=\"0\" height=\"81\" src=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/5140.clip_5F00_image006_5F00_thumb_5F00_6384A3DC.png\" style=\"border-bottom:0px;border-left:0px;border-top:0px;border-right:0px;\" title=\"clip_image006\" width=\"355\" \/><\/a>\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tIt&rsquo;s looking better.&nbsp; Now let&rsquo;s keep going.\n<\/p>\n<h1 style=\"list-style-type:disc;clear:none;\">\n\tWindow Settings<br \/>\n<\/h1>\n<p style=\"list-style-type:disc;\">\n\tThere are a number of window settings we can customize for our form.&nbsp; Here we&rsquo;ll experiment with the following:\n<\/p>\n<ul style=\"list-style-type:disc;\">\n<li>\n\t\tDisabling the minimize and maximize functionality\n\t<\/li>\n<li>\n\t\tSetting the window state to normal (versus maximized or minimized)\n\t<\/li>\n<li>\n\t\tHiding the size grip (usually in the lower right corner of the window)\n\t<\/li>\n<li>\n\t\tSetting the opacity to 70%, making the window partially transparent\n\t<\/li>\n<li>\n\t\tSetting the window start position so that the window will open in the middle of the visible screen\n\t<\/li>\n<\/ul>\n<p style=\"list-style-type:disc;\">\n\tAdd-Type -AssemblyName System.Windows.Forms\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form = New-Object system.Windows.Forms.Form\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Text = &quot;Sample Form&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tForm.AutoScroll = $True\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.AutoSize = $True\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.AutoSizeMode = &quot;GrowAndShrink&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;&nbsp;&nbsp; # or GrowOnly\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.MinimizeBox = $False\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.MaximizeBox = $False\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.WindowState = &quot;Normal&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;&nbsp;&nbsp; # Maximized, Minimized, Normal\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.SizeGripStyle = &quot;Hide&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;&nbsp;&nbsp; # Auto, Hide, Show\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.ShowInTaskbar = $False\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Opacity = 0.7\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;&nbsp;&nbsp; # 1.0 is fully opaque; 0.0 is invisible\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.StartPosition = &quot;CenterScreen&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;&nbsp;&nbsp; # CenterScreen, Manual, WindowsDefaultLocation, WindowsDefaultBounds, CenterParent\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tFont = New-Object System.Drawing.Font(&quot;Times New Roman&quot;,24,[System.Drawing.FontStyle]::Italic)\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;&nbsp;&nbsp; # Font styles are: Regular, Bold, Italic, Underline, Strikeout\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Font = $Font\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label = New-Object System.Windows.Forms.Label\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label.Text = &quot;This form is very simple.&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label.AutoSize = $True\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Controls.Add($Label)\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.ShowDialog()\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t<a href=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/3487.clip_5F00_image007_5F00_5782B3A8.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"clip_image007\" border=\"0\" height=\"81\" src=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/5554.clip_5F00_image007_5F00_thumb_5F00_36230E0C.png\" style=\"border-bottom:0px;border-left:0px;border-top:0px;border-right:0px;\" title=\"clip_image007\" width=\"355\" \/><\/a>\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tNote &ndash; I&rsquo;ve positioned this form over the well-known sample image penguins.jpg to demonstrate that the form is 30% transparent.\n<\/p>\n<h1 style=\"list-style-type:disc;clear:none;\">\n\tVisual Stimulation<br \/>\n<\/h1>\n<p style=\"list-style-type:disc;\">\n\tNote &ndash; for this section, we&rsquo;ll revert the window settings changes we made to the form in the previous section.\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tThere are a few things we can do to make our form pop visually.&nbsp; The easiest way to change the look and feed is to change the background color of the form.\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tAdd-Type -AssemblyName System.Windows.Forms\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form = New-Object system.Windows.Forms.Form\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Text = &quot;Sample Form&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.AutoSize = $True\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.AutoSizeMode = &quot;GrowAndShrink&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;&nbsp;&nbsp; # or GrowOnly\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.BackColor = &quot;Lime&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;&nbsp;&nbsp; # color names are static properties of System.Drawing.Color\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;&nbsp;&nbsp; # you can also use ARGB values, such as &quot;#FFFFEBCD&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Font = New-Object System.Drawing.Font(&quot;Times New Roman&quot;,24,[System.Drawing.FontStyle]::Italic)\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;&nbsp;&nbsp; # Font styles are: Regular, Bold, Italic, Underline, Strikeout\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Font = $Font\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label = New-Object System.Windows.Forms.Label\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label.Text = &quot;This form is very simple.&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label.AutoSize = $True\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Controls.Add($Label)\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.ShowDialog()\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t<a href=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/7610.clip_5F00_image008_5F00_14C36870.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"clip_image008\" border=\"0\" height=\"81\" src=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/5037.clip_5F00_image008_5F00_thumb_5F00_2CE6D2CB.png\" style=\"border-bottom:0px;border-left:0px;border-top:0px;border-right:0px;\" title=\"clip_image008\" width=\"355\" \/><\/a>\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tHmmm, interesting, but maybe not quite what we were looking for.\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tLet&rsquo;s try adding a visually pleasing background image for our form.&nbsp; In order to do that, we need to do the following:\n<\/p>\n<ul style=\"list-style-type:disc;\">\n<li>\n\t\tCreate a new system.drawing.image object from an image file (in this the sample picture &ldquo;Oryx Antelope.jpg) and assign it to the BackgroundImage property of the form\n\t<\/li>\n<li>\n\t\tSet the BackgroundImageLayout to None (The default is Tile, which tiles the image across the form as many times as it will fit.)\n\t<\/li>\n<li>\n\t\tRemove the AutoSize feature from the form and instead set the size of the form to mage the image dimensions.\n\t<\/li>\n<li>\n\t\tConfigure the label so that it&rsquo;s background is transparent, so as not to obstruct the picture\n\t<\/li>\n<\/ul>\n<p style=\"list-style-type:disc;\">\n\tAdd-Type -AssemblyName System.Windows.Forms\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form = New-Object system.Windows.Forms.Form\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Text = &quot;Sample Form&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Image = [system.drawing.image]::FromFile(&quot;$($Env:Public)\\Pictures\\Sample Pictures\\Oryx Antelope.jpg&quot;)\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.BackgroundImage = $Image\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.BackgroundImageLayout = &quot;None&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;&nbsp;&nbsp; # None, Tile, Center, Stretch, Zoom\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Width = $Image.Width\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Height = $Image.Height\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Font = New-Object System.Drawing.Font(&quot;Times New Roman&quot;,24,[System.Drawing.FontStyle]::Italic)\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;&nbsp;&nbsp; # Font styles are: Regular, Bold, Italic, Underline, Strikeout\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Font = $Font\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label = New-Object System.Windows.Forms.Label\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label.Text = &quot;This form is very simple.&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label.BackColor = &quot;Transparent&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label.AutoSize = $True\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Controls.Add($Label)\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.ShowDialog()\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t<a href=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/8171.clip_5F00_image010_5F00_0BF36024.jpg\"><img loading=\"lazy\" decoding=\"async\" alt=\"clip_image010\" border=\"0\" height=\"468\" src=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/2620.clip_5F00_image010_5F00_thumb_5F00_2AC9D402.jpg\" style=\"border-bottom:0px;border-left:0px;border-top:0px;border-right:0px;\" title=\"clip_image010\" width=\"624\" \/><\/a>\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tVery nice.\n<\/p>\n<h1 style=\"list-style-type:disc;clear:none;\">\n\tFinishing Touch<br \/>\n<\/h1>\n<p style=\"list-style-type:disc;\">\n\tOne last thing we can do to refine our form is to add a customized icon.&nbsp; We can load an icon from an image file (in this case GRAPH.ICO which is part of Office).&nbsp; A good resource for creating custom icon files is <a href=\"http:\/\/www.xiconeditor.com\/\"><u>http:\/\/www.xiconeditor.com\/<\/u><\/a>.&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Icon = New-Object system.drawing.icon (&quot;C:\\Program Files\\Microsoft Office\\Office14\\GRAPH.ICO&quot;)\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Icon = $Icon\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t<a href=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/1738.clip_5F00_image011_5F00_34AEC56D.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"clip_image011\" border=\"0\" height=\"250\" src=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/5432.clip_5F00_image011_5F00_thumb_5F00_1276B9E7.png\" style=\"border-bottom:0px;border-left:0px;border-top:0px;border-right:0px;\" title=\"clip_image011\" width=\"470\" \/><\/a>\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tAlternatively, we can extract an icon from an associated file, such as PowerShell.exe.\n<\/p>\n<p style=\"list-style-type:disc;\">\n\tAdd-Type -AssemblyName System.Windows.Forms\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form = New-Object system.Windows.Forms.Form\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Text = &quot;Sample Form&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Icon = [system.drawing.icon]::ExtractAssociatedIcon($PSHOME + &quot;\\powershell.exe&quot;)\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Icon = $Icon\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Image = [system.drawing.image]::FromFile(&quot;$($Env:Public)\\Pictures\\Sample Pictures\\Oryx Antelope.jpg&quot;)\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.BackgroundImage = $Image\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.BackgroundImageLayout = &quot;None&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;&nbsp;&nbsp; # None, Tile, Center, Stretch, Zoom\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Width = $Image.Width\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Height = $Image.Height\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Font = New-Object System.Drawing.Font(&quot;Times New Roman&quot;,24,[System.Drawing.FontStyle]::Italic)\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;&nbsp;&nbsp; # Font styles are: Regular, Bold, Italic, Underline, Strikeout\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Font = $Font\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label = New-Object System.Windows.Forms.Label\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label.Text = &quot;This form is very simple.&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label.BackColor = &quot;Transparent&quot;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Label.AutoSize = $True\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.Controls.Add($Label)\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t$Form.ShowDialog()\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t&nbsp;\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t<a href=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/7178.clip_5F00_image012_5F00_3727D15E.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"clip_image012\" border=\"0\" height=\"349\" src=\"http:\/\/blogs.technet.com\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-75-92-metablogapi\/4530.clip_5F00_image012_5F00_thumb_5F00_544D7968.png\" style=\"border-bottom:0px;border-left:0px;border-top:0px;border-right:0px;\" title=\"clip_image012\" width=\"470\" \/><\/a>\n<\/p>\n<p style=\"list-style-type:disc;\">\n\t<a href=\"http:\/\/blogs.technet.com\/b\/stephap\/archive\/2012\/04\/23\/building-forms-with-powershell-part-1-the-form.aspx\">SOURCE<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>The Simplest Form &nbsp; The Simplest Form There are only three things required to launch a form from PowerShell: You must load the System.Windows.Forms assembly <a class=\"mh-excerpt-more\" href=\"http:\/\/jeevanbobba.uk\/?page_id=24\" title=\"Powershell\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-24","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/jeevanbobba.uk\/index.php?rest_route=\/wp\/v2\/pages\/24","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/jeevanbobba.uk\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/jeevanbobba.uk\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/jeevanbobba.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/jeevanbobba.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=24"}],"version-history":[{"count":0,"href":"http:\/\/jeevanbobba.uk\/index.php?rest_route=\/wp\/v2\/pages\/24\/revisions"}],"wp:attachment":[{"href":"http:\/\/jeevanbobba.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}