Password Generator

During my time as a help desk/service center rep, we had a tool which would generate a password via a form and button and then was able to print out the form to give to each customer to take with them so they would not forget their password.  During my time there I was given the task to update the password requirements and wording on the form.  Visual Studio was the tool that I used to make this happen. Now during that time, I had to locate the source files and grab a temporary license to use Visual Studio to make the modifications to the code in order to make the changes required. Now approximately 4 years after the last time I worked on the vb code, I was asked again to perform some work on it in my new position.

Long story short, I spent a little bit of time working with Visual Studio 2005 and was able to get it working only on my machine, but it would not work on anyone elses machine.  I decided there that Powershell would be the way to go.

The easiest way to build the front end form was using Primal Forms Community Edition to build it out.  Once I had the form looking exactly like the original form, I was then able to export the code without much effort to a .ps1 file which I could then finish coding the rest of the tool.

I then used Powershells own ISE editor to finish adding the required code to finish out the tool.

The first piece I wanted to work on was the Password generation function that would create a randomly generated password using some specified parameters in the code.  For this instance, I wanted to have a minimum amount of 14 characters and have at least 3 characters for Upper, Lower, numerical and symbols.

Function Create-Password {
#How many characters in the password
[int]$passwordlength = 14

##Make sure that number of characters below are not greater than $passwordlength!!

#Minimum Upper Case characters in password
[int]$min_upper = 3

#Minimum Lower Case characters in password
[int]$min_lower = 3

#Minimum Numerical characters in password
[int]$min_number = 3

#Minimum Symbol/Puncutation characters in password
[int]$min_symbol = 3

#Misc password characters in password
[int]$min_misc = ($passwordlength – ($min_upper + $min_lower + $min_number + $min_symbol))

#Characters for the password
$upper = @(“A”,”B”,”C”,”D”,”E”,”F”,”G”,”H”,”I”,”J”,”K”,”L”,”M”,”N”,”O”,”P”,”Q”,”R”,”S”,”T”,”U”,”V”,”W”,”X”,”Y”,”Z”)
$lower = @(“a”,”b”,”c”,”d”,”e”,”f”,”g”,”h”,”i”,”j”,”k”,”l”,”m”,”n”,”o”,”p”,”q”,”r”,”s”,”t”,”u”,”v”,”w”,”x”,”y”,”z”)
$number = @(1,2,3,4,5,6,7,8,9,0)
$symbol = @(“!”,”@”,”#”,”%”,”&”,”(“,”)”,”`””,”.”,”<“,”>”,”+”,”=”,”-“,”_”)
$combine = $upper + $lower + $number + $symbol

$password = @()

#Start adding upper case into password
1..$min_upper | % {$password += Get-Random $upper}
#Add lower case into password
1..$min_lower | % {$password += Get-Random $lower}
#Add numbers into password
1..$min_number | % {$password += Get-Random $number}

#Add symbols into password
1..$min_symbol | % {$password += Get-Random $symbol}

#Fill out the rest of the password length
1..$min_misc | % {$password += Get-Random $combine}

#Randomize password
Get-Random $password -count $passwordlength | % {[string]$randompassword += $_}
Return $randompassword
}

I can then call this function when the Generate Password button is pressed and the Password text is then modified from NOTVALID1 to whatever the randomly generated password is.  During the time the password is also copied to clipboard via the following lines of code:

[Windows.Forms.Clipboard]::SetText($password)

With this, the help desk work can then paste the password into the account reset dialog in active directory.

Another feature that I fought with for a week or so was trying to emulate the printing of the windows form that I created with the password that can be given to the user. During my research I found ways to print the entire screen, print a set area of the screen, but nothing that would print the active window or the actual windows form.  VB has the capability of doing this, but powershell, with Windows.Forms namespace does not. After some searching, I was able to find some C# code that does this, but using the handle of a window.  I am by no means a C# programmer and I was able to locate the window form handle but could not effectively replicate the form printing.
Doing some further research I was able to find a piece of code that would allow me to grab the active window:

GetForegroundWindow()
[DllImport(“user32.dll”)]
public static extern IntPtr GetForegroundWindow();

Here is the complete C# code:

using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
namespace ScreenShotDemo
{
/// <summary>
/// Provides functions to capture the entire screen, or a particular window, and save it to a file.
/// </summary>
public class ScreenCapture
{
/// <summary>
/// Creates an Image object containing a screen shot the active window
/// </summary>
/// <returns></returns>
public Image CaptureActiveWindow()
{
return CaptureWindow( User32.GetForegroundWindow() );
}
/// <summary>
/// Creates an Image object containing a screen shot of the entire desktop
/// </summary>
/// <returns></returns>
public Image CaptureScreen()
{
return CaptureWindow( User32.GetDesktopWindow() );
}
/// <summary>
/// Creates an Image object containing a screen shot of a specific window
/// </summary>
/// <param name=”handle”>The handle to the window. (In windows forms, this is obtained by the Handle property)</param>
/// <returns></returns>
private Image CaptureWindow(IntPtr handle)
{
// get te hDC of the target window
IntPtr hdcSrc = User32.GetWindowDC(handle);
// get the size
User32.RECT windowRect = new User32.RECT();
User32.GetWindowRect(handle,ref windowRect);
int width = windowRect.right – windowRect.left;
int height = windowRect.bottom – windowRect.top;
// create a device context we can copy to
IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
// create a bitmap we can copy it to,
// using GetDeviceCaps to get the width/height
IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc,width,height);
// select the bitmap object
IntPtr hOld = GDI32.SelectObject(hdcDest,hBitmap);
// bitblt over
GDI32.BitBlt(hdcDest,0,0,width,height,hdcSrc,0,0,GDI32.SRCCOPY);
// restore selection
GDI32.SelectObject(hdcDest,hOld);
// clean up
GDI32.DeleteDC(hdcDest);
User32.ReleaseDC(handle,hdcSrc);
// get a .NET image object for it
Image img = Image.FromHbitmap(hBitmap);
// free up the Bitmap object
GDI32.DeleteObject(hBitmap);
return img;
}
/// <summary>
/// Captures a screen shot of the active window, and saves it to a file
/// </summary>
/// <param name=”filename”></param>
/// <param name=”format”></param>
public void CaptureActiveWindowToFile(string filename, ImageFormat format)
{
Image img = CaptureActiveWindow();
img.Save(filename,format);
}
/// <summary>
/// Captures a screen shot of the entire desktop, and saves it to a file
/// </summary>
/// <param name=”filename”></param>
/// <param name=”format”></param>
public void CaptureScreenToFile(string filename, ImageFormat format)
{
Image img = CaptureScreen();
img.Save(filename,format);
}

/// <summary>
/// Helper class containing Gdi32 API functions
/// </summary>
private class GDI32
{

public const int SRCCOPY = 0x00CC0020; // BitBlt dwRop parameter
[DllImport(“gdi32.dll”)]
public static extern bool BitBlt(IntPtr hObject,int nXDest,int nYDest,
int nWidth,int nHeight,IntPtr hObjectSource,
int nXSrc,int nYSrc,int dwRop);
[DllImport(“gdi32.dll”)]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC,int nWidth,
int nHeight);
[DllImport(“gdi32.dll”)]
public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
[DllImport(“gdi32.dll”)]
public static extern bool DeleteDC(IntPtr hDC);
[DllImport(“gdi32.dll”)]
public static extern bool DeleteObject(IntPtr hObject);
[DllImport(“gdi32.dll”)]
public static extern IntPtr SelectObject(IntPtr hDC,IntPtr hObject);
}

/// <summary>
/// Helper class containing User32 API functions
/// </summary>
private class User32
{
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[DllImport(“user32.dll”)]
public static extern IntPtr GetDesktopWindow();
[DllImport(“user32.dll”)]
public static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport(“user32.dll”)]
public static extern IntPtr ReleaseDC(IntPtr hWnd,IntPtr hDC);
[DllImport(“user32.dll”)]
public static extern IntPtr GetWindowRect(IntPtr hWnd,ref RECT rect);
[DllImport(“user32.dll”)]
public static extern IntPtr GetForegroundWindow();
}
}
}

Using a piece of code given to me by super Powershell writer MOW, I was able to grab the captured image in its raw format and print it out to the default printer:

$pd = New-Object System.Drawing.Printing.PrintDocument
$pd.Add_PrintPage({$_.Graphics.DrawImage(([System.Drawing.Image]$img), 0, 0)})
$pd.Print()

To avoid having the border included in the print screen, I removed the border for the duration of the screen capture and print job. I also gave the form 1 second to make the change and refresh before performing the screen capture, otherwise the password would not show up correctly on the print-out as shown:

This quite a fun challenge as I am not into building a GUI using Powershell.  But the challenge of making it completely like the old tool and still keeping all of the features of the old tool to include printing of the form made this a great learning experience for me and also taught me more on using C# code to make the script do more things such as capturing the active window.

I have this script uploaded to the following sites:
PoshCode.org
Microsoft Technet Script Repository

Here is the complete code:

Function Create-Password {
#How many characters in the password
[int]$passwordlength = 14

##Make sure that number of characters below are not greater than $passwordlength!!

#Minimum Upper Case characters in password
[int]$min_upper = 3

#Minimum Lower Case characters in password
[int]$min_lower = 3

#Minimum Numerical characters in password
[int]$min_number = 3

#Minimum Symbol/Puncutation characters in password
[int]$min_symbol = 3

#Misc password characters in password
[int]$min_misc = ($passwordlength – ($min_upper + $min_lower + $min_number + $min_symbol))

#Characters for the password
$upper = @(“A”,”B”,”C”,”D”,”E”,”F”,”G”,”H”,”I”,”J”,”K”,”L”,”M”,”N”,”O”,”P”,”Q”,”R”,”S”,”T”,”U”,”V”,”W”,”X”,”Y”,”Z”)
$lower = @(“a”,”b”,”c”,”d”,”e”,”f”,”g”,”h”,”i”,”j”,”k”,”l”,”m”,”n”,”o”,”p”,”q”,”r”,”s”,”t”,”u”,”v”,”w”,”x”,”y”,”z”)
$number = @(1,2,3,4,5,6,7,8,9,0)
$symbol = @(“!”,”@”,”#”,”%”,”&”,”(“,”)”,”`””,”.”,”<“,”>”,”+”,”=”,”-“,”_”)
$combine = $upper + $lower + $number + $symbol

$password = @()

#Start adding upper case into password
1..$min_upper | % {$password += Get-Random $upper}
#Add lower case into password
1..$min_lower | % {$password += Get-Random $lower}
#Add numbers into password
1..$min_number | % {$password += Get-Random $number}

#Add symbols into password
1..$min_symbol | % {$password += Get-Random $symbol}

#Fill out the rest of the password length
1..$min_misc | % {$password += Get-Random $combine}

#Randomize password
Get-Random $password -count $passwordlength | % {[string]$randompassword += $_}
Return $randompassword
}
#Generated Form Function
function GenerateForm {

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname(“System.Windows.Forms”) | Out-Null
[reflection.assembly]::loadwithpartialname(“System.Drawing”) | Out-Null
#endregion

#Show popup if not running in -STA mode
If (((get-host).RunSpace).ApartmentState -ne “STA”) {
[System.Windows.Forms.MessageBox]::Show(“You are not running Powershell in (Single Threaded Apartment) STA mode! Please restart powershell in STA mode (powershell.exe -STA)”,”Warning”) | Out-Null
Break
}

#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$textBox1 = New-Object System.Windows.Forms.TextBox
$lbl_summary = New-Object System.Windows.Forms.Label
$lbl_passwordlabel = New-Object System.Windows.Forms.Label
$btn_generate = New-Object System.Windows.Forms.Button
$chk_printreport = New-Object System.Windows.Forms.CheckBox
$lbl_bottomheader = New-Object System.Windows.Forms.Label
$lbl_topheader = New-Object System.Windows.Forms.Label
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

#———————————————-
#Generated Event Script Blocks
#———————————————-
#Provide Custom Code for events specified in PrimalForms.
$btn_generate_OnClick= {
#Saving password to variable
$password = Create-Password

#Displaying password to screen
$textBox1.Text = $password
Start-Sleep -Seconds 1

If ($($chk_printreport.Checked) -eq $True) {
#Define Printer – Uses Default printer

$code = @’
using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
namespace ScreenShotDemo
{
/// <summary>
/// Provides functions to capture the entire screen, or a particular window, and save it to a file.
/// </summary>
public class ScreenCapture
{
/// <summary>
/// Creates an Image object containing a screen shot of the entire desktop
/// </summary>
/// <returns></returns>
public Image CaptureScreen()
{
return CaptureWindow( User32.GetForegroundWindow() );
}
/// <summary>
/// Creates an Image object containing a screen shot of a specific window
/// </summary>
/// <param name=”handle”>The handle to the window. (In windows forms, this is obtained by the Handle property)</param>
/// <returns></returns>
public Image CaptureWindow(IntPtr handle)
{
// get te hDC of the target window
IntPtr hdcSrc = User32.GetWindowDC(handle);
// get the size
User32.RECT windowRect = new User32.RECT();
User32.GetWindowRect(handle,ref windowRect);
int width = windowRect.right – windowRect.left;
int height = windowRect.bottom – windowRect.top;
// create a device context we can copy to
IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
// create a bitmap we can copy it to,
// using GetDeviceCaps to get the width/height
IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc,width,height);
// select the bitmap object
IntPtr hOld = GDI32.SelectObject(hdcDest,hBitmap);
// bitblt over
GDI32.BitBlt(hdcDest,0,0,width,height,hdcSrc,0,0,GDI32.SRCCOPY);
// restore selection
GDI32.SelectObject(hdcDest,hOld);
// clean up
GDI32.DeleteDC(hdcDest);
User32.ReleaseDC(handle,hdcSrc);
// get a .NET image object for it
Image img = Image.FromHbitmap(hBitmap);
// free up the Bitmap object
GDI32.DeleteObject(hBitmap);
return img;
}
/// <summary>
/// Captures a screen shot of a specific window, and saves it to a file
/// </summary>
/// <param name=”handle”></param>
/// <param name=”filename”></param>
/// <param name=”format”></param>
public void CaptureWindowToFile(IntPtr handle, string filename, ImageFormat format)
{
Image img = CaptureWindow(handle);
img.Save(filename,format);
}
/// <summary>
/// Captures a screen shot of the entire desktop, and saves it to a file
/// </summary>
/// <param name=”filename”></param>
/// <param name=”format”></param>
public void CaptureScreenToFile(string filename, ImageFormat format)
{
Image img = CaptureScreen();
img.Save(filename,format);
}

/// <summary>
/// Helper class containing Gdi32 API functions
/// </summary>
private class GDI32
{

public const int SRCCOPY = 0x00CC0020; // BitBlt dwRop parameter
[DllImport(“gdi32.dll”)]
public static extern bool BitBlt(IntPtr hObject,int nXDest,int nYDest,
int nWidth,int nHeight,IntPtr hObjectSource,
int nXSrc,int nYSrc,int dwRop);
[DllImport(“gdi32.dll”)]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC,int nWidth,
int nHeight);
[DllImport(“gdi32.dll”)]
public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
[DllImport(“gdi32.dll”)]
public static extern bool DeleteDC(IntPtr hDC);
[DllImport(“gdi32.dll”)]
public static extern bool DeleteObject(IntPtr hObject);
[DllImport(“gdi32.dll”)]
public static extern IntPtr SelectObject(IntPtr hDC,IntPtr hObject);
}

/// <summary>
/// Helper class containing User32 API functions
/// </summary>
private class User32
{
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[DllImport(“user32.dll”)]
public static extern IntPtr GetDesktopWindow();
[DllImport(“user32.dll”)]
public static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport(“user32.dll”)]
public static extern IntPtr ReleaseDC(IntPtr hWnd,IntPtr hDC);
[DllImport(“user32.dll”)]
public static extern IntPtr GetWindowRect(IntPtr hWnd,ref RECT rect);
[DllImport(“user32.dll”)]
public static extern IntPtr GetForegroundWindow();
}
}
}
‘@

add-type $code -ReferencedAssemblies ‘System.Windows.Forms’,’System.Drawing’

#Print Form
$form1.FormBorderStyle = 0
$form1.Activate()
$fph = New-Object ScreenShotDemo.ScreenCapture
$img = $fph.CaptureScreen()
$pd = New-Object System.Drawing.Printing.PrintDocument
$pd.Add_PrintPage({$_.Graphics.DrawImage(([System.Drawing.Image]$img), 0, 0)})
$pd.Print()

$form1.FormBorderStyle = 5
}
#Pasting password to clipboard
#This will only work if Powershell is running in Single Threaded Apartment (STA): powershell.exe -sta or run from ISE
#You can check by running the following command: ((get-host).RunSpace).ApartmentState
[Windows.Forms.Clipboard]::SetText($password)

}

$handler_form1_Load=
{
$form1.TopMost = $True
$form1.Activate()

}

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}

#———————————————-
#region Generated Form Code
$form1.Font = New-Object System.Drawing.Font(“Microsoft Sans Serif”,9.75,1,3,0)
$form1.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,255)
$form1.Text = “Password Generator”
$form1.AllowDrop = $True
$form1.Name = “form1”
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 685
$System_Drawing_Size.Height = 496
$form1.ClientSize = $System_Drawing_Size
$form1.FormBorderStyle = 5
$form1.add_Load($handler_form1_Load)

$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 227
$System_Drawing_Size.Height = 19
$textBox1.Size = $System_Drawing_Size
$textBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$textBox1.ReadOnly = $True
$textBox1.BorderStyle = 0
$textBox1.Text = “NOTVALID1”
$textBox1.Font = New-Object System.Drawing.Font(“Microsoft Sans Serif”,12,1,3,0)
$textBox1.Name = “textBox1”
$textBox1.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,255)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 304
$System_Drawing_Point.Y = 268
$textBox1.Location = $System_Drawing_Point
$textBox1.TabIndex = 7
$textBox1.add_TextChanged($handler_textBox1_TextChanged)

$form1.Controls.Add($textBox1)

$lbl_summary.TabIndex = 6
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 619
$System_Drawing_Size.Height = 156
$lbl_summary.Size = $System_Drawing_Size
$lbl_summary.Text = “Ensure your password contains at least 3 special characters, 3 numbers, 3 uppercase and 3 lowercase letters for a total of at least 14 characters long. You will be unable to change this password for the next 24 hours.”
$lbl_summary.Font = New-Object System.Drawing.Font(“Microsoft Sans Serif”,12,1,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 41
$System_Drawing_Point.Y = 85
$lbl_summary.Location = $System_Drawing_Point
$lbl_summary.DataBindings.DefaultDataSourceUpdateMode = 0
$lbl_summary.Name = “lbl_summary”

$form1.Controls.Add($lbl_summary)

$lbl_passwordlabel.TabIndex = 4
$lbl_passwordlabel.TextAlign = 64
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 111
$System_Drawing_Size.Height = 47
$lbl_passwordlabel.Size = $System_Drawing_Size
$lbl_passwordlabel.Text = “Password:”
$lbl_passwordlabel.Font = New-Object System.Drawing.Font(“Microsoft Sans Serif”,12,1,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 184
$System_Drawing_Point.Y = 254
$lbl_passwordlabel.Location = $System_Drawing_Point
$lbl_passwordlabel.DataBindings.DefaultDataSourceUpdateMode = 0
$lbl_passwordlabel.Name = “lbl_passwordlabel”

$form1.Controls.Add($lbl_passwordlabel)

$btn_generate.TabIndex = 3
$btn_generate.Name = “btn_generate”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 104
$System_Drawing_Size.Height = 39
$btn_generate.Size = $System_Drawing_Size
$btn_generate.UseVisualStyleBackColor = $True

$btn_generate.Text = “Generate”
$btn_generate.Font = New-Object System.Drawing.Font(“Microsoft Sans Serif”,8.25,1,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 304
$System_Drawing_Point.Y = 364
$btn_generate.Location = $System_Drawing_Point
$btn_generate.DataBindings.DefaultDataSourceUpdateMode = 0
$btn_generate.add_Click($btn_generate_OnClick)

$form1.Controls.Add($btn_generate)

$chk_printreport.UseVisualStyleBackColor = $True
$chk_printreport.Font = New-Object System.Drawing.Font(“Microsoft Sans Serif”,9,1,3,0)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 104
$System_Drawing_Size.Height = 24
$chk_printreport.Size = $System_Drawing_Size
$chk_printreport.TabIndex = 2
$chk_printreport.Text = “Print Report”
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 304
$System_Drawing_Point.Y = 323
$chk_printreport.Location = $System_Drawing_Point
$chk_printreport.DataBindings.DefaultDataSourceUpdateMode = 0
$chk_printreport.Name = “chk_printreport”
$chk_printreport.checked = $True

$form1.Controls.Add($chk_printreport)

$lbl_bottomheader.TabIndex = 1
$lbl_bottomheader.ImageAlign = 512
$lbl_bottomheader.TextAlign = 32
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 662
$System_Drawing_Size.Height = 59
$lbl_bottomheader.Size = $System_Drawing_Size
$lbl_bottomheader.Text = “FOR OFFICIAL USE ONLY”
$lbl_bottomheader.Font = New-Object System.Drawing.Font(“Microsoft Sans Serif”,20.25,1,3,0)
$lbl_bottomheader.ForeColor = [System.Drawing.Color]::FromKnownColor(“Green”)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 11
$System_Drawing_Point.Y = 425
$lbl_bottomheader.Location = $System_Drawing_Point
$lbl_bottomheader.DataBindings.DefaultDataSourceUpdateMode = 0
$lbl_bottomheader.Name = “lbl_bottomheader”
$lbl_bottomheader.add_Click($handler_label2_Click)

$form1.Controls.Add($lbl_bottomheader)

$lbl_topheader.TabIndex = 0
$lbl_topheader.ImageAlign = 512
$lbl_topheader.TextAlign = 32
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 662
$System_Drawing_Size.Height = 59
$lbl_topheader.Size = $System_Drawing_Size
$lbl_topheader.Text = “FOR OFFICIAL USE ONLY”
$lbl_topheader.Font = New-Object System.Drawing.Font(“Microsoft Sans Serif”,20.25,1,3,0)
$lbl_topheader.ForeColor = [System.Drawing.Color]::FromKnownColor(“Green”)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 11
$System_Drawing_Point.Y = 6
$lbl_topheader.Location = $System_Drawing_Point
$lbl_topheader.DataBindings.DefaultDataSourceUpdateMode = 0
$lbl_topheader.Name = “lbl_topheader”
$lbl_topheader.add_Click($handler_label1_Click)

$form1.Controls.Add($lbl_topheader)

#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function

#Call the Function
GenerateForm

About Boe Prox

Microsoft Cloud and Datacenter MVP working as a SQL DBA.
This entry was posted in powershell, scripts and tagged , , , . Bookmark the permalink.

2 Responses to Password Generator

  1. Oliver Lipkau says:

    Cool code 🙂
    I like how you can choose how many lower, upper and numbers to put in the password.
    I use
    $null = [Reflection.Assembly]::LoadWithPartialName(“System.Web”)
    [System.Web.Security.Membership]::GeneratePassword($length,$NumberOfNonAlphanumericCharacters)

    to bad the .net namespace doesn’t do more character specification =/

    Regards
    Oliver

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s