here is the full script, GUI and all
PowerShell Code
Double-click the code block to select all.
#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
# Generated On: 11/11/2014 3:32 PM
# Generated By: gdavies
########################################################################
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
#region Generated Form Objects
$SDQueryForm = New-Object System.Windows.Forms.Form
$Info = New-Object System.Windows.Forms.Label
$BULogo = New-Object System.Windows.Forms.Label
$LastLogonLabel = New-Object System.Windows.Forms.Label
$LastLogonSurround = New-Object System.Windows.Forms.Label
$ExitButton = New-Object System.Windows.Forms.Button
$ExitButtonSurround = New-Object System.Windows.Forms.Label
$NameSearchButton = New-Object System.Windows.Forms.Button
$NameSearchButtonSurround = New-Object System.Windows.Forms.Label
$NameLabel = New-Object System.Windows.Forms.Label
$NameLabelSurround = New-Object System.Windows.Forms.Label
$IDSearchButton = New-Object System.Windows.Forms.Button
$ButtonSurround = New-Object System.Windows.Forms.Label
$EntryBox = New-Object System.Windows.Forms.TextBox
$EntryBoxSurround = New-Object System.Windows.Forms.Label
$IDLabel = New-Object System.Windows.Forms.Label
$IDLabelSurround = New-Object System.Windows.Forms.Label
$Results = New-Object System.Windows.Forms.TextBox
$ResultsSurrond = New-Object System.Windows.Forms.Label
$Instructions = New-Object System.Windows.Forms.Label
$InstructionsSurround = New-Object System.Windows.Forms.Label
$toolTip1 = New-Object System.Windows.Forms.ToolTip
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
$LastLogonButton = New-Object System.Windows.Forms.Button
$LastLogonButtonSurround = New-Object System.Windows.Forms.Label
#endregion Generated Form Objects
#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$NameSearchButton_OnClick=
{
$results.Text=Get-ADUser -Filter "DisplayName -eq '$($EntryBox.text)'" -Properties DisplayName, sAMAccountName, mail, extensionattribute5, PasswordLastSet, PasswordExpired, PasswordNeverExpires, buMemberOf, msExchOmaAdminWirelessEnable, whenCreated | select givenName, surname, DisplayName, sAMAccountName, mail, extensionattribute5, PasswordLastSet, PasswordExpired, PasswordNeverExpires, buMemberOf, msExchOmaAdminWirelessEnable, whenCreated | Out-String
$results.Focus()
}
$LoadMiodule=
{
import-module activedirectory
set-location ad:
}
$IDSearchButton_OnClick=
{
$results.Text=Get-ADUser -Filter "sAMAccountName -eq '$($EntryBox.text)'" -Properties DisplayName, sAMAccountName, mail, extensionattribute5, msExchHomeServerName, PasswordLastSet, PasswordExpired, PasswordNeverExpires, buMemberOf, msExchOmaAdminWirelessEnable, whenCreated | select givenName, surname, DisplayName, sAMAccountName, mail, extensionattribute5, msExchHomeServerName, PasswordLastSet, PasswordExpired, PasswordNeverExpires, buMemberOf, msExchOmaAdminWirelessEnable, whenCreated | Out-String
$results.Focus()
}
$LastLogonButton_OnClick=
{
$results.Text=$logons=@()
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().DomainControllers |
ForEach{
$logonInt=(Get-Aduser -Filter "sAMAccountName -eq '$($EntryBox.text)'" -server $_.Name -properties lastlogon).lastlogon
$logons+=[datetime]::FromFileTime($logonInt)
}
$newestLogon=($logons| Measure-Object -Max).Maximum
$newestLogon | Out-string $results.Focus()
}
$ExitButton_OnClick=
{
$SDQueryForm.Close()
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$SDQueryForm.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$SDQueryForm.AutoScaleMode = 0
$SDQueryForm.BackColor = [System.Drawing.Color]::FromArgb(255,90,110,205)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 691
$System_Drawing_Size.Width = 984
$SDQueryForm.ClientSize = $System_Drawing_Size
$SDQueryForm.DataBindings.DefaultDataSourceUpdateMode = 0
$SDQueryForm.MaximizeBox = $False
$SDQueryForm.MinimizeBox = $False
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 728
$System_Drawing_Size.Width = 1150
$SDQueryForm.MaximumSize = $System_Drawing_Size
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 678
$System_Drawing_Size.Width = 1150
$SDQueryForm.MinimumSize = $System_Drawing_Size
$SDQueryForm.Name = "SDQueryForm"
$SDQueryForm.ShowIcon = $False
$SDQueryForm.SizeGripStyle = 2
$SDQueryForm.StartPosition = 1
$SDQueryForm.Text = "Service Desk AD Queries"
$SDQueryForm.add_Load($LoadMiodule)
$Info.DataBindings.DefaultDataSourceUpdateMode = 0
$Info.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",6,0,3,0)
$Info.ForeColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 205
$System_Drawing_Point.Y = 680
$Info.Location = $System_Drawing_Point
$Info.Name = "Info"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 10
$System_Drawing_Size.Width = 798
$Info.Size = $System_Drawing_Size
$Info.TabIndex = 20
$Info.Text = "Developed by Gareth Davies - Bellevue university Server Administrator"
$Info.TextAlign = 512
$SDQueryForm.Controls.Add($Info)
$BULogo.BackColor = [System.Drawing.Color]::FromArgb(255,248,248,255)
$BULogo.DataBindings.DefaultDataSourceUpdateMode = 0
$BULogo.Image = [System.Drawing.Image]::FromFile('S:\bulogo.jpg')
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 10
$System_Drawing_Point.Y = 613
$BULogo.Location = $System_Drawing_Point
$BULogo.Name = "BULogo"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 70
$System_Drawing_Size.Width = 180
$BULogo.Size = $System_Drawing_Size
$BULogo.TabIndex = 19
$SDQueryForm.Controls.Add($BULogo)
$LastLogonLabel.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,255)
$LastLogonLabel.BorderStyle = 2
$LastLogonLabel.DataBindings.DefaultDataSourceUpdateMode = 0
$LastLogonLabel.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,1,3,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 10
$System_Drawing_Point.Y = 210
$LastLogonLabel.Location = $System_Drawing_Point
$LastLogonLabel.Name = "label12"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 100
$LastLogonLabel.Size = $System_Drawing_Size
$LastLogonLabel.TabIndex = 18
$LastLogonLabel.Text = "Last Logon"
$LastLogonLabel.TextAlign = 32
$SDQueryForm.Controls.Add($LastLogonLabel)
$LastLogonSurround.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$LastLogonSurround.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 7
$System_Drawing_Point.Y = 207
$LastLogonSurround.Location = $System_Drawing_Point
$LastLogonSurround.Name = "NameLabelSurround"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 46
$System_Drawing_Size.Width = 106
$LastLogonSurround.Size = $System_Drawing_Size
$LastLogonSurround.TabIndex = 12
$SDQueryForm.Controls.Add($LastLogonSurround)
$ExitButton.BackColor = [System.Drawing.Color]::FromArgb(255,255,99,71)
$ExitButton.DataBindings.DefaultDataSourceUpdateMode = 0
$ExitButton.FlatStyle = 1
$ExitButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,1,3,0)
$ExitButton.ForeColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$ExitButton.Image = [System.Drawing.Image]::FromFile('S:\exit.jpg')
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 1024
$System_Drawing_Point.Y = 628
$ExitButton.Location = $System_Drawing_Point
$ExitButton.Name = "ExitButton"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 100
$ExitButton.Size = $System_Drawing_Size
$ExitButton.TabIndex = 17
$ExitButton.UseVisualStyleBackColor = $False
$ExitButton.add_Click($ExitButton_OnClick)
$SDQueryForm.Controls.Add($ExitButton)
$ExitButtonSurround.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$ExitButtonSurround.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 1021
$System_Drawing_Point.Y = 625
$ExitButtonSurround.Location = $System_Drawing_Point
$ExitButtonSurround.Name = "ExitButtonSurround"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 46
$System_Drawing_Size.Width = 106
$ExitButtonSurround.Size = $System_Drawing_Size
$ExitButtonSurround.TabIndex = 16
$SDQueryForm.Controls.Add($ExitButtonSurround)
$NameSearchButton.BackColor = [System.Drawing.Color]::FromArgb(255,90,110,205)
$NameSearchButton.DataBindings.DefaultDataSourceUpdateMode = 0
$NameSearchButton.FlatStyle = 1
$NameSearchButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,1,3,0)
$NameSearchButton.ForeColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 1024
$System_Drawing_Point.Y = 155
$NameSearchButton.Location = $System_Drawing_Point
$NameSearchButton.Name = "NameSearchButton"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 100
$NameSearchButton.Size = $System_Drawing_Size
$NameSearchButton.TabIndex = 15
$NameSearchButton.Text = "Name Search"
$NameSearchButton.UseVisualStyleBackColor = $False
$NameSearchButton.add_Click($NameSearchButton_OnClick)
$SDQueryForm.Controls.Add($NameSearchButton)
$NameSearchButtonSurround.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$NameSearchButtonSurround.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 1021
$System_Drawing_Point.Y = 152
$NameSearchButtonSurround.Location = $System_Drawing_Point
$NameSearchButtonSurround.Name = "NameSearchButtonSurround"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 46
$System_Drawing_Size.Width = 106
$NameSearchButtonSurround.Size = $System_Drawing_Size
$NameSearchButtonSurround.TabIndex = 14
$SDQueryForm.Controls.Add($NameSearchButtonSurround)
$LastLogonButton.BackColor = [System.Drawing.Color]::FromArgb(255,90,110,205)
$LastLogonButton.DataBindings.DefaultDataSourceUpdateMode = 0
$LastLogonButton.FlatStyle = 1
$LastLogonButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,1,3,0)
$LastLogonButton.ForeColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 1024
$System_Drawing_Point.Y = 210
$LastLogonButton.Location = $System_Drawing_Point
$LastLogonButton.Name = "LastLogonButton"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 100
$LastLogonButton.Size = $System_Drawing_Size
$LastLogonButton.TabIndex = 15
$LastLogonButton.Text = "Last Logon Search"
$LastLogonButton.UseVisualStyleBackColor = $False
$LastLogonButton.add_Click($LastLogonButton_OnClick)
$SDQueryForm.Controls.Add($LastLogonButton)
$LastLogonButtonSurround.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$LastLogonButtonSurround.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 1021
$System_Drawing_Point.Y = 207
$LastLogonButtonSurround.Location = $System_Drawing_Point
$LastLogonButtonSurround.Name = "LastLogonButtonSurround"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 46
$System_Drawing_Size.Width = 106
$LastLogonButtonSurround.Size = $System_Drawing_Size
$LastLogonButtonSurround.TabIndex = 14
$SDQueryForm.Controls.Add($LastLogonButtonSurround)
$NameLabel.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,255)
$NameLabel.BorderStyle = 2
$NameLabel.DataBindings.DefaultDataSourceUpdateMode = 0
$NameLabel.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,1,3,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 10
$System_Drawing_Point.Y = 155
$NameLabel.Location = $System_Drawing_Point
$NameLabel.Name = "NameLabel"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 100
$NameLabel.Size = $System_Drawing_Size
$NameLabel.TabIndex = 13
$NameLabel.Text = "Full Name"
$NameLabel.TextAlign = 32
$SDQueryForm.Controls.Add($NameLabel)
$NameLabelSurround.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$NameLabelSurround.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 7
$System_Drawing_Point.Y = 152
$NameLabelSurround.Location = $System_Drawing_Point
$NameLabelSurround.Name = "NameLabelSurround"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 46
$System_Drawing_Size.Width = 106
$NameLabelSurround.Size = $System_Drawing_Size
$NameLabelSurround.TabIndex = 12
$SDQueryForm.Controls.Add($NameLabelSurround)
$IDSearchButton.BackColor = [System.Drawing.Color]::FromArgb(255,90,110,205)
$IDSearchButton.DataBindings.DefaultDataSourceUpdateMode = 0
$IDSearchButton.FlatStyle = 1
$IDSearchButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,1,3,0)
$IDSearchButton.ForeColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 1024
$System_Drawing_Point.Y = 100
$IDSearchButton.Location = $System_Drawing_Point
$IDSearchButton.Name = "IDSearchButton"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 100
$IDSearchButton.Size = $System_Drawing_Size
$IDSearchButton.TabIndex = 11
$IDSearchButton.Text = "ID Search"
$IDSearchButton.UseVisualStyleBackColor = $False
$IDSearchButton.add_Click($IDSearchButton_OnClick)
$SDQueryForm.Controls.Add($IDSearchButton)
$ButtonSurround.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$ButtonSurround.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 1021
$System_Drawing_Point.Y = 97
$ButtonSurround.Location = $System_Drawing_Point
$ButtonSurround.Name = "ButtonSurround"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 46
$System_Drawing_Size.Width = 106
$ButtonSurround.Size = $System_Drawing_Size
$ButtonSurround.TabIndex = 10
$SDQueryForm.Controls.Add($ButtonSurround)
$EntryBox.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 133
$System_Drawing_Point.Y = 155
$EntryBox.Location = $System_Drawing_Point
$EntryBox.Multiline = $True
$EntryBox.Name = "EntryBox"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 870
$EntryBox.Size = $System_Drawing_Size
$EntryBox.TabIndex = 9
$EntryBox.TextAlign = 2
$SDQueryForm.Controls.Add($EntryBox)
$EntryBoxSurround.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$EntryBoxSurround.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 130
$System_Drawing_Point.Y = 152
$EntryBoxSurround.Location = $System_Drawing_Point
$EntryBoxSurround.Name = "EntryBoxSurround"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 46
$System_Drawing_Size.Width = 876
$EntryBoxSurround.Size = $System_Drawing_Size
$EntryBoxSurround.TabIndex = 8
$SDQueryForm.Controls.Add($EntryBoxSurround)
$IDLabel.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,255)
$IDLabel.BorderStyle = 2
$IDLabel.DataBindings.DefaultDataSourceUpdateMode = 0
$IDLabel.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,1,3,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 10
$System_Drawing_Point.Y = 100
$IDLabel.Location = $System_Drawing_Point
$IDLabel.Name = "IDLabel"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 100
$IDLabel.Size = $System_Drawing_Size
$IDLabel.TabIndex = 7
$IDLabel.Text = "User or Student ID"
$IDLabel.TextAlign = 32
$SDQueryForm.Controls.Add($IDLabel)
$IDLabelSurround.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$IDLabelSurround.DataBindings.DefaultDataSourceUpdateMode = 0
$IDLabelSurround.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 = 7
$System_Drawing_Point.Y = 97
$IDLabelSurround.Location = $System_Drawing_Point
$IDLabelSurround.Name = "IDLabelSurround"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 46
$System_Drawing_Size.Width = 106
$IDLabelSurround.Size = $System_Drawing_Size
$IDLabelSurround.TabIndex = 6
$IDLabelSurround.TextAlign = 32
$SDQueryForm.Controls.Add($IDLabelSurround)
$Results.BackColor = [System.Drawing.Color]::FromArgb(255,0,0,0)
$Results.DataBindings.DefaultDataSourceUpdateMode = 0
$Results.Font = New-Object System.Drawing.Font("Lucida Console",8.25,0,3,0)
$Results.ForeColor = [System.Drawing.Color]::FromArgb(255,128,255,128)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 10
$System_Drawing_Point.Y = 263
$Results.Location = $System_Drawing_Point
$Results.Multiline = $True
$Results.Name = "Results"
$Results.ReadOnly = $True
$Results.ScrollBars = 2
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 340
$System_Drawing_Size.Width = 1114
$Results.Size = $System_Drawing_Size
$Results.TabIndex = 5
$SDQueryForm.Controls.Add($Results)
$ResultsSurrond.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$ResultsSurrond.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 7
$System_Drawing_Point.Y = 260
$ResultsSurrond.Location = $System_Drawing_Point
$ResultsSurrond.Name = "ResultsSurrond"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 346
$System_Drawing_Size.Width = 1120
$ResultsSurrond.Size = $System_Drawing_Size
$ResultsSurrond.TabIndex = 4
$SDQueryForm.Controls.Add($ResultsSurrond)
$Instructions.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,255)
$Instructions.BorderStyle = 2
$Instructions.DataBindings.DefaultDataSourceUpdateMode = 0
$Instructions.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,1,3,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 10
$System_Drawing_Point.Y = 10
$Instructions.Location = $System_Drawing_Point
$Instructions.Name = "Instructions"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 70
$System_Drawing_Size.Width = 1114
$Instructions.Size = $System_Drawing_Size
$Instructions.TabIndex = 2
$Instructions.Text = "Enter the User, student ID or the FULL NAME in the box below and hit the relevant search button. You will see the details of the account, including the First name, Last name, Email address - student email is listed as extensionattribute5, date the password was last set, if the password has expired and if ActiveSync is disabled - This will appear as msExchOmaAdminWirelessEnable, if the value is 4 it is disabled, no value means it is enabled. The Last Logon search will display the last time the user account was authenticated by a DC."
$Instructions.TextAlign = 32
$SDQueryForm.Controls.Add($Instructions)
$InstructionsSurround.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$InstructionsSurround.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 7
$System_Drawing_Point.Y = 7
$InstructionsSurround.Location = $System_Drawing_Point
$InstructionsSurround.Name = "InstructionsSurround"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 76
$System_Drawing_Size.Width = 1120
$InstructionsSurround.Size = $System_Drawing_Size
$InstructionsSurround.TabIndex = 1
$InstructionsSurround.Text = "label2"
$SDQueryForm.Controls.Add($InstructionsSurround)
$toolTip1.IsBalloon = $False
$tooltip1.SetToolTip($EntryBox, “Enter the user/student ID or the persons FULL NAME. Part names will not work, just first or last name will not work.”)
$tooltip1.SetToolTip($IDSearchButton, “Click here to search for User or student ID details.”)
$tooltip1.SetToolTip($NameSearchButton, “Click here to search for User or student name details.”)
$tooltip1.SetToolTip($Results, “Search results will appear here. If no data is displayed you will need to check the ID or name you searched for.”)
$tooltip1.SetToolTip($ExitButton, “Click to Close the app.”)
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $SDQueryForm.WindowState
#Init the OnLoad event to correct the initial state of the form
$SDQueryForm.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$SDQueryForm.ShowDialog()| Out-Null
} #End Function
#Call the Function
# add a helper
$showWindowAsync = Add-Type –memberDefinition @”
[DllImport("user32.dll")]
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
“@ -name “Win32ShowWindowAsync” -namespace Win32Functions –passThru
function Show-PowerShell()
{
[void]$showWindowAsync::ShowWindowAsync((Get-Process –id $pid).MainWindowHandle, 10)
}
function Hide-PowerShell()
{
[void]$showWindowAsync::ShowWindowAsync((Get-Process –id $pid).MainWindowHandle, 2)
}
Hide-PowerShell
GenerateForm
Lines 48 to 51 are what is behind one button, this works and displays in the output window called $results
Lines 60 to 63 are the code executed when another button is clicked, this works and displays the results in the same output window as the first button.
Both of these use Out-string $results.Focus() as the command to output to this location.
Lines 66 to 76 show the code behind the third button, again this is told to display the results in the same location using the exact same code, this fails. It clears any previously returned results from the output window but does NOT display the results obtained when the script is executed.
All 3 use the same code to point the output to the same location, 2 work, the third clears the window but does not populate it with new data.
Changing the code in the third button to Out-host displays the results in the native powershell window, but this is not acceptable as the people using this tool are NOT to have easy access to the command line. Changing it to out-file exports the results to the location and file specified. Out-printer prints the results to my default printer, so clearly the script works and gets what I want, it even sends it to anywhere I can tell it APART from the one location I want, which is the same place as the other commands have no issue sending the results to.
So before telling me Out-string $results.Focus() does nothing and is s syntax error please test the code above so you can see it WORKS everywhere apart from this one place. Out-string tells it to use the output location specified at the start of the code block, the .Focus() highlights the results so the service desk tech can just hit ctrl+c and copy the results into the ticket they are creating. Removing this bit of code makes no difference to the outcome for the third button, removing the entire pipe makes no changes either.