#------------------------------------------------------------------------ # Source File Information (DO NOT MODIFY) # Source ID: 71c976ed-5ef1-475a-a5c7-a288af2929d6 # Source File: ADUserResetPassword_v1.0.psproj #------------------------------------------------------------------------ #region Project Recovery Data (DO NOT MODIFY) <#RecoveryData: EQIAAB+LCAAAAAAABACNkl1PgzAUhu+X7D+Q3vNRImMkpYkOZ7xQF5zeLkc4GEyhpIXp/r1FYGEx MV4+7XmfNz0pSzGTR1SnBFrgy4VlsZ2SH5i1P2DwFZUuZc2pQ5k7wXi3LQXeJzykWRSuMLcDLKh9 FQZgQ5CFNvjrNRR+5Ef5irnj8BgdW/anBrnH3DlOcilyU2e58zY9wohWigUqrDN8hApjQqybrhR5 TDzCn1tQbdc4jdZD+d/RDQhhP0BZb6WqDo0u5q7p3MiKf8vuhHwDYVR0prI2sqqgzm+/Wqz7XcZk rzokfJjWpoFeNAwwvPu8p4GeVPle1iD6gb6XXycvGlWKGtsdaP0pVX44Uscz0sYEmfsrsVww9+IL fAP9rj8kEQIAAA==#> #endregion <# .NOTES -------------------------------------------------------------------------------- Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2015 v4.2.99 Generated on: 2016-01-03 20:42 Generated by: ibelmans -------------------------------------------------------------------------------- .DESCRIPTION Script generated by PowerShell Studio 2015 #> #region Source: Startup.pss #region File Recovery Data (DO NOT MODIFY) <#RecoveryData: SwQAAB+LCAAAAAAABAC9lEtLAzEQgO+C/yH0vOzD7boWsgtS6UXQ4kr1mk1nS2geZZK07L93W0sV PYiFhlwyEzIfH8MMfQFutoD9A3OMDBcrjK5GN6P6+ooQ+oxiJTSTMyHhiSmoG8fQ+U28sZYmv14P f+6tBdVKAfYQf2X6WlluUIo2IosjaRyn+xORqZfOI1QavEMmIzL3Qw3+CP2rWYOu2rJkBS9us0k+ hvRuQpNT1Z+UprcOVAhG/Cb00uxsPDOobBDivk9hQMh2Qq/OYaV5V3Rll2XLImU5+5v1rmQYJ4HA ncG+AdwKDme17N92U4MQRO9oNUczqF3A7RR+zjZNvi+P+gNBqg7+SwQAAA==#> #endregion #---------------------------------------------- #region Import Assemblies #---------------------------------------------- [void][Reflection.Assembly]::Load('mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][Reflection.Assembly]::Load('System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][Reflection.Assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][Reflection.Assembly]::Load('System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][Reflection.Assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') [void][Reflection.Assembly]::Load('System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][Reflection.Assembly]::Load('System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') [void][Reflection.Assembly]::Load('System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][Reflection.Assembly]::Load('System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') #endregion Import Assemblies #################################################################################################### ### Begin: Script information ###################################################################### #################################################################################################### <# .SYNOPSIS PowerShell GUI script to reset an Active Directory user’s password. .DESCRIPTION PowerShell GUI script to reset an Active Directory user’s password. .NOTES Author : Ingvald Belmans Website : http://www.supersysadmin.com Version : 1.0 Changelog: - 1.0 (2016-01-03) Initial version. .LINK http://www.supersysadmin.com #> #################################################################################################### ### End: Script information ######################################################################## #################################################################################################### #################################################################################################### ### Begin: Main function ########################################################################### #################################################################################################### #region function Main function Main { <# .SYNOPSIS The Main function starts the project application. .PARAMETER Commandline $Commandline contains the complete argument string passed to the script packager executable. .NOTES Use this function to initialize your script and to call GUI forms. .NOTES To get the console output in the Packager (Forms Engine) use: $ConsoleOutput (Type: System.Collections.ArrayList) #> Param ( [String]$Commandline ) if((Call-MainForm_psf) -eq 'OK') { } $global:ExitCode = 0 #Set the exit code for the Packager } #endregion #################################################################################################### ### End: Main function ############################################################################# #################################################################################################### #endregion Source: Startup.pss #region Source: MainForm.psf function Call-MainForm_psf { #region File Recovery Data (DO NOT MODIFY) <#RecoveryData: PCkAAB+LCAAAAAAABADdWltv4jgUfl9p/4OVp1kJAQmlgESRKJ2uRst0qtKdmbfKBAPehhg5Tinz 6/c4ISU0DrG5TVtVQjU5V5/P33Fs2nfEZU+EL6+wwAj+CSjzLyzH6vz5B0Ltb5xOqI+9a+qRGzwj na+Y+teMz8rzYNyuZB7HSsP/iCuQWM7JhTVYBoLMyj+oP2KLoCx1488SUj0qoe+rGM7KVflXQr3Q EyEnFz4JBcdeCd2GQ4+6/5DlPXsk/sWw0cB1t35ut2pnpNpsWciHUC4saU+GayF3Sr0RB1Grx3zB mRfE6UGst5zNCRfLlU7Po8QXA/qLWJ16vVZCtabdriRCOUrSyVfihwPB6TyxDGJ3ZEzAq0sSuUQm jqqSmCu0T306C2erqM5bJXTmVAu1ZD2sTjIJheIDgbm4ZQEVMPlWpwfTQPjA5YQU696TZ2F1ulf/ BoTfkYCIWxwEC8ZH6MkuKyL9/ATWV7p9hkfrMB/ksF2JBFTSgylb+CnxaPxKvhh+f3MWzi/Z89Eh mDiSsX4LxTwU28CYndiu704Ztzr3bF5Cl0wIBsumT8aihO7oZCoyU5s10WcujktqA5zt85aGTgyd bPAaqiuQOk3w1dLxdY+HX/wReQYlPemBYLDIrrEXEB2FCJr54ReD5Y66U2nlFHhJ+dKFzEFAkzVy DY6ABZgfMA9Dis2yU5/rqa4R1yghBVHlI06ZvpY+EBXzvEvMg4gcXDKCmgjqYk9PPUZt/grZhlu9 DGMgpp4rldJcJzV6U+xPyChnah5SIpskKO3H0H5pMpvDN0qScTJJ+zAjyzXuag6E4zR3YrrNCLQZ z3FsWCTnRoRXOx7hxVmgbWkUI6A3Je7jKRCQOMrO/+aoK24guz6bsK2buu3gODckpR2CM+AcpypJ 8syQcrJ7Um0oICyQDBTpRwrbuu80CLE3EEuPXGL3sce8qMPwUAnJTa7RwtplCH3KPzrSYjdFpdwL XHUTcOnFY4wnFfVtw5Mm/jSpZX8EveqE8FbmPupO1kMk/THa4Q1Z7NsLbQf60m6tMOVduw/WqtAH G5pb+RX6nOP1QUhhzXyfxIK65K/dmuGpXgFSm7zU/DumlHSQ/Tu8xJ01DNgsJ3YT+mrqt2fTdggk FNcuxRuHbWK/FyP2b8GI6TteTuxGGNH3afqWthdG3klTkad0US326Cg7vlwlrg3aCSRdV21PzNjg QO0kiR99GuBZ13VZ6As5fj89Ra/4b48rtiDn+Dyx9zp/Ofk/eqlf3TGYrPAvENcmBuQ3W/HLmBc7 A69S+HjppcJS3KxkAomuqahH1rcsceHks1RZDU7PIWglNJTA3aiC/qm5vHBSngUYwlXJXTOIKZAx KS600oDeHGiQ2OlAUFjtnPupKxhesYX/CuFvFN/66O4OmbweqKQQvQnw955gn00+cnqfn2l++TQv eHONF9/4xjssdZNUc4jC7jumC4mu3eYWNDWn147O47KvwOr5VdpVnIRtCyx7/vWOSxQz3G5FinSP UqYcyyaFikx8qFJFZLZbpaSqbqHqjkGh1IZN6iQtFJWpGwRkBpNHgsTD6ptlZxa4jHt0eIACtCsv Vl97iUt+Ch8Hh1WxR/nDtNM44nhB/ckuvqq1cX3cGNv2qF7FNVzs6+fMO01OlANMGV8OCH+iLtmp ZMbZ9RgnJ0lvlRUscEjtCLm9DOO13a6kfy3Z+R/xYd7oPCkAAA==#> #endregion #---------------------------------------------- #region Import the Assemblies #---------------------------------------------- [void][reflection.assembly]::Load('mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][reflection.assembly]::Load('System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][reflection.assembly]::Load('System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][reflection.assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') [void][reflection.assembly]::Load('System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][reflection.assembly]::Load('System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') [void][reflection.assembly]::Load('System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][reflection.assembly]::Load('System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') #endregion Import Assemblies #---------------------------------------------- #region Generated Form Objects #---------------------------------------------- [System.Windows.Forms.Application]::EnableVisualStyles() $FormMain = New-Object 'System.Windows.Forms.Form' $GroupBoxMainOutput = New-Object 'System.Windows.Forms.GroupBox' $RichTextBoxMainOutput = New-Object 'System.Windows.Forms.RichTextBox' $GroupBoxMainChangePassword = New-Object 'System.Windows.Forms.GroupBox' $CheckBoxMainChangePasswordChangePasswordAtNextLogon = New-Object 'System.Windows.Forms.CheckBox' $ButtonMainChangePasswordChangePassword = New-Object 'System.Windows.Forms.Button' $GroupBoxMainNewPassword = New-Object 'System.Windows.Forms.GroupBox' $TextBoxMainNewPassword2 = New-Object 'System.Windows.Forms.TextBox' $TextBoxMainNewPassword1 = New-Object 'System.Windows.Forms.TextBox' $GroupBoxMainUserName = New-Object 'System.Windows.Forms.GroupBox' $TextBoxMainUserName = New-Object 'System.Windows.Forms.TextBox' $MenuStripMain = New-Object 'System.Windows.Forms.MenuStrip' $ToolStripMenuItemMainFile = New-Object 'System.Windows.Forms.ToolStripMenuItem' $ToolStripMenuItemMainFileLog = New-Object 'System.Windows.Forms.ToolStripMenuItem' $ToolStripMenuItemMainFileAbout = New-Object 'System.Windows.Forms.ToolStripMenuItem' $ToolStripMenuItemMainFileExit = New-Object 'System.Windows.Forms.ToolStripMenuItem' $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState' #endregion Generated Form Objects #---------------------------------------------- # User Generated Script #---------------------------------------------- #################################################################################################### ### Begin: Main form ############################################################################### #################################################################################################### $FormMain_Load = { # Create log file $SSALogFileTimeStamp = Get-Date -UFormat "%Y%m%d_%H%M%S" $global:SSALogFile = New-Item -ItemType File -Path "$env:USERPROFILE\Documents" -Name "SSA_ADResetUserPassword_$SSALogFileTimeStamp.log" Add-SSAOutput -OutputText "Creating log file." if (Test-Path -Path $SSALogFile) { Add-SSAOutput -OutputText "Logfile $SSALogFile created." } else { Add-SSAOutput -OutputText "Logfile $SSALogFile could not be created." } } $FormMain_Shown = { Import-SSAActiveDirectoryModule if ($SSAActiveDirectoryModuleLoaded -eq $false) { [System.Windows.Forms.MessageBox]::Show("The ActiveDirectory PowerShell module could not be loaded. You can review the log for more details. Please restart the application to try again.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error) } } $ToolStripMenuItemMainFileAbout_Click = { Start-Process -FilePath "http://supersysadmin.com/96/powershell-gui-script-to-reset-an-active-directory-users-password/" } $ToolStripMenuItemMainFileLog_Click = { Invoke-Item -Path $SSALogFile } $ToolStripMenuItemMainFileExit_Click = { $FormMain.Close() } $ButtonMainChangePasswordChangePassword_Click = { Add-SSAOutput -OutputText "Checking if ActiveDirectory PowerShell module is loaded." if ($SSAActiveDirectoryModuleLoaded -eq $true) { Add-SSAOutput -OutputText "ActiveDirectory PowerShell module is loaded." Get-SSAUserName if ($SSAUserName) { Add-SSAOutput -OutputText "Changing password of user $SSAUserName." try { $QueryADUser = Get-ADUser -Identity $SSAUserName -ErrorAction Stop Get-SSAPassword1 Get-SSAPassword2 if ($SSAPassword1 -and $SSAPassword2) { if ($SSAPassword1 -eq $SSAPassword2) { if ($CheckBoxMainChangePasswordChangePasswordAtNextLogon.Checked) { try { Set-ADAccountPassword -Identity $SSAUserName -NewPassword (ConvertTo-SecureString -String $SSAPassword1 -AsPlainText –Force) –Reset -ErrorAction Stop -PassThru Set-ADUser -Identity $SSAUserName -ChangePasswordAtLogon $True -ErrorAction Stop Add-SSAOutput -OutputText "Password for $SSAUserName has been updated and needs to be changed at next logon." } catch { Add-SSAOutput -OutputText "$_" } } else { try { Set-ADAccountPassword -Identity $SSAUserName -NewPassword (ConvertTo-SecureString -String $SSAPassword1 -AsPlainText –Force) –Reset -ErrorAction Stop Add-SSAOutput -OutputText "Password for $SSAUserName has been updated." } catch { Add-SSAOutput -OutputText "$_" } } } else { Add-SSAOutput -OutputText "Passwords do not match, please review your input." } } else { Add-SSAOutput -OutputText "One or both password fields are empty, please review your input." } } catch [exception] { Add-SSAOutput -OutputText "$_" } } else { Add-SSAOutput -OutputText "UserName field is empty, please review your input." } } else { Add-SSAOutput -OutputText "ActiveDirectory PowerShell module is currently not loaded, cannot proceed with the request. Restart the application to attempt load the module." } } $RichTextBoxMainOutput_TextChanged = { $RichTextBoxMainOutput.SelectionStart = $RichTextBoxMainOutput.Text.Length $RichTextBoxMainOutput.ScrollToCaret() } #################################################################################################### ### End: Main form ################################################################################# #################################################################################################### # --End User Generated Script-- #---------------------------------------------- #region Generated Events #---------------------------------------------- $Form_StateCorrection_Load= { #Correct the initial state of the form to prevent the .Net maximized form issue $FormMain.WindowState = $InitialFormWindowState } $Form_StoreValues_Closing= { #Store the control values $script:MainForm_RichTextBoxMainOutput = $RichTextBoxMainOutput.Text $script:MainForm_CheckBoxMainChangePasswordChangePasswordAtNextLogon = $CheckBoxMainChangePasswordChangePasswordAtNextLogon.Checked $script:MainForm_TextBoxMainNewPassword2 = $TextBoxMainNewPassword2.Text $script:MainForm_TextBoxMainNewPassword1 = $TextBoxMainNewPassword1.Text $script:MainForm_TextBoxMainUserName = $TextBoxMainUserName.Text } $Form_Cleanup_FormClosed= { #Remove all event handlers from the controls try { $RichTextBoxMainOutput.remove_TextChanged($RichTextBoxMainOutput_TextChanged) $ButtonMainChangePasswordChangePassword.remove_Click($ButtonMainChangePasswordChangePassword_Click) $FormMain.remove_Load($FormMain_Load) $FormMain.remove_Shown($FormMain_Shown) $ToolStripMenuItemMainFileLog.remove_Click($ToolStripMenuItemMainFileLog_Click) $ToolStripMenuItemMainFileAbout.remove_Click($ToolStripMenuItemMainFileAbout_Click) $ToolStripMenuItemMainFileExit.remove_Click($ToolStripMenuItemMainFileExit_Click) $FormMain.remove_Load($Form_StateCorrection_Load) $FormMain.remove_Closing($Form_StoreValues_Closing) $FormMain.remove_FormClosed($Form_Cleanup_FormClosed) } catch [Exception] { } } #endregion Generated Events #---------------------------------------------- #region Generated Form Code #---------------------------------------------- $FormMain.SuspendLayout() $GroupBoxMainOutput.SuspendLayout() $GroupBoxMainChangePassword.SuspendLayout() $GroupBoxMainNewPassword.SuspendLayout() $GroupBoxMainUserName.SuspendLayout() $MenuStripMain.SuspendLayout() # # FormMain # $FormMain.Controls.Add($GroupBoxMainOutput) $FormMain.Controls.Add($GroupBoxMainChangePassword) $FormMain.Controls.Add($GroupBoxMainNewPassword) $FormMain.Controls.Add($GroupBoxMainUserName) $FormMain.Controls.Add($MenuStripMain) $FormMain.ClientSize = '553, 381' $FormMain.MainMenuStrip = $MenuStripMain $FormMain.MinimumSize = '569, 420' $FormMain.Name = 'FormMain' $FormMain.StartPosition = 'CenterScreen' $FormMain.Text = 'ADUserResetPassword v1.0' $FormMain.add_Load($FormMain_Load) $FormMain.add_Shown($FormMain_Shown) # # GroupBoxMainOutput # $GroupBoxMainOutput.Controls.Add($RichTextBoxMainOutput) $GroupBoxMainOutput.Anchor = 'Top, Bottom, Left, Right' $GroupBoxMainOutput.Location = '13, 169' $GroupBoxMainOutput.Name = 'GroupBoxMainOutput' $GroupBoxMainOutput.Size = '528, 199' $GroupBoxMainOutput.TabIndex = 5 $GroupBoxMainOutput.TabStop = $False $GroupBoxMainOutput.Text = 'Output' # # RichTextBoxMainOutput # $RichTextBoxMainOutput.Anchor = 'Top, Bottom, Left, Right' $RichTextBoxMainOutput.Font = 'Consolas, 8.25pt' $RichTextBoxMainOutput.Location = '7, 20' $RichTextBoxMainOutput.Name = 'RichTextBoxMainOutput' $RichTextBoxMainOutput.ScrollBars = 'ForcedVertical' $RichTextBoxMainOutput.Size = '513, 169' $RichTextBoxMainOutput.TabIndex = 0 $RichTextBoxMainOutput.Text = '' $RichTextBoxMainOutput.add_TextChanged($RichTextBoxMainOutput_TextChanged) # # GroupBoxMainChangePassword # $GroupBoxMainChangePassword.Controls.Add($CheckBoxMainChangePasswordChangePasswordAtNextLogon) $GroupBoxMainChangePassword.Controls.Add($ButtonMainChangePasswordChangePassword) $GroupBoxMainChangePassword.Location = '320, 28' $GroupBoxMainChangePassword.Name = 'GroupBoxMainChangePassword' $GroupBoxMainChangePassword.Size = '221, 86' $GroupBoxMainChangePassword.TabIndex = 3 $GroupBoxMainChangePassword.TabStop = $False $GroupBoxMainChangePassword.Text = 'Change Password' # # CheckBoxMainChangePasswordChangePasswordAtNextLogon # $CheckBoxMainChangePasswordChangePasswordAtNextLogon.Location = '6, 20' $CheckBoxMainChangePasswordChangePasswordAtNextLogon.Name = 'CheckBoxMainChangePasswordChangePasswordAtNextLogon' $CheckBoxMainChangePasswordChangePasswordAtNextLogon.Size = '207, 24' $CheckBoxMainChangePasswordChangePasswordAtNextLogon.TabIndex = 1 $CheckBoxMainChangePasswordChangePasswordAtNextLogon.Text = 'Change Password at Next Logon' $CheckBoxMainChangePasswordChangePasswordAtNextLogon.UseVisualStyleBackColor = $True # # ButtonMainChangePasswordChangePassword # $ButtonMainChangePasswordChangePassword.Location = '6, 50' $ButtonMainChangePasswordChangePassword.Name = 'ButtonMainChangePasswordChangePassword' $ButtonMainChangePasswordChangePassword.Size = '207, 28' $ButtonMainChangePasswordChangePassword.TabIndex = 4 $ButtonMainChangePasswordChangePassword.Text = 'Change Password' $ButtonMainChangePasswordChangePassword.UseVisualStyleBackColor = $True $ButtonMainChangePasswordChangePassword.add_Click($ButtonMainChangePasswordChangePassword_Click) # # GroupBoxMainNewPassword # $GroupBoxMainNewPassword.Controls.Add($TextBoxMainNewPassword2) $GroupBoxMainNewPassword.Controls.Add($TextBoxMainNewPassword1) $GroupBoxMainNewPassword.Location = '12, 88' $GroupBoxMainNewPassword.Name = 'GroupBoxMainNewPassword' $GroupBoxMainNewPassword.Size = '301, 75' $GroupBoxMainNewPassword.TabIndex = 2 $GroupBoxMainNewPassword.TabStop = $False $GroupBoxMainNewPassword.Text = 'New Password (twice)' # # TextBoxMainNewPassword2 # $TextBoxMainNewPassword2.Font = 'Consolas, 8.25pt' $TextBoxMainNewPassword2.Location = '8, 47' $TextBoxMainNewPassword2.Name = 'TextBoxMainNewPassword2' $TextBoxMainNewPassword2.Size = '286, 20' $TextBoxMainNewPassword2.TabIndex = 1 $TextBoxMainNewPassword2.UseSystemPasswordChar = $True # # TextBoxMainNewPassword1 # $TextBoxMainNewPassword1.Font = 'Consolas, 8.25pt' $TextBoxMainNewPassword1.Location = '7, 20' $TextBoxMainNewPassword1.Name = 'TextBoxMainNewPassword1' $TextBoxMainNewPassword1.Size = '287, 20' $TextBoxMainNewPassword1.TabIndex = 0 $TextBoxMainNewPassword1.UseSystemPasswordChar = $True # # GroupBoxMainUserName # $GroupBoxMainUserName.Controls.Add($TextBoxMainUserName) $GroupBoxMainUserName.Location = '12, 28' $GroupBoxMainUserName.Name = 'GroupBoxMainUserName' $GroupBoxMainUserName.Size = '300, 54' $GroupBoxMainUserName.TabIndex = 1 $GroupBoxMainUserName.TabStop = $False $GroupBoxMainUserName.Text = 'UserName (SamAccountName)' # # TextBoxMainUserName # $TextBoxMainUserName.Font = 'Consolas, 8.25pt' $TextBoxMainUserName.Location = '7, 20' $TextBoxMainUserName.Name = 'TextBoxMainUserName' $TextBoxMainUserName.Size = '287, 20' $TextBoxMainUserName.TabIndex = 0 # # MenuStripMain # [void]$MenuStripMain.Items.Add($ToolStripMenuItemMainFile) $MenuStripMain.Location = '0, 0' $MenuStripMain.Name = 'MenuStripMain' $MenuStripMain.Size = '553, 24' $MenuStripMain.TabIndex = 0 $MenuStripMain.Text = 'menustrip1' # # ToolStripMenuItemMainFile # [void]$ToolStripMenuItemMainFile.DropDownItems.Add($ToolStripMenuItemMainFileAbout) [void]$ToolStripMenuItemMainFile.DropDownItems.Add($ToolStripMenuItemMainFileLog) [void]$ToolStripMenuItemMainFile.DropDownItems.Add($ToolStripMenuItemMainFileExit) $ToolStripMenuItemMainFile.Name = 'ToolStripMenuItemMainFile' $ToolStripMenuItemMainFile.Size = '37, 20' $ToolStripMenuItemMainFile.Text = 'File' # # ToolStripMenuItemMainFileLog # $ToolStripMenuItemMainFileLog.Name = 'ToolStripMenuItemMainFileLog' $ToolStripMenuItemMainFileLog.Size = '107, 22' $ToolStripMenuItemMainFileLog.Text = 'Log' $ToolStripMenuItemMainFileLog.add_Click($ToolStripMenuItemMainFileLog_Click) # # ToolStripMenuItemMainFileAbout # $ToolStripMenuItemMainFileAbout.Name = 'ToolStripMenuItemMainFileAbout' $ToolStripMenuItemMainFileAbout.Size = '107, 22' $ToolStripMenuItemMainFileAbout.Text = 'About' $ToolStripMenuItemMainFileAbout.add_Click($ToolStripMenuItemMainFileAbout_Click) # # ToolStripMenuItemMainFileExit # $ToolStripMenuItemMainFileExit.Name = 'ToolStripMenuItemMainFileExit' $ToolStripMenuItemMainFileExit.Size = '152, 22' $ToolStripMenuItemMainFileExit.Text = 'Exit' $ToolStripMenuItemMainFileExit.add_Click($ToolStripMenuItemMainFileExit_Click) $MenuStripMain.ResumeLayout() $GroupBoxMainUserName.ResumeLayout() $GroupBoxMainNewPassword.ResumeLayout() $GroupBoxMainChangePassword.ResumeLayout() $GroupBoxMainOutput.ResumeLayout() $FormMain.ResumeLayout() #endregion Generated Form Code #---------------------------------------------- #Save the initial state of the form $InitialFormWindowState = $FormMain.WindowState #Init the OnLoad event to correct the initial state of the form $FormMain.add_Load($Form_StateCorrection_Load) #Clean up the control events $FormMain.add_FormClosed($Form_Cleanup_FormClosed) #Store the control values when form is closing $FormMain.add_Closing($Form_StoreValues_Closing) #Show the Form return $FormMain.ShowDialog() } #endregion Source: MainForm.psf #region Source: Globals.ps1 #################################################################################################### ### Begin: Custom functions ######################################################################## #################################################################################################### #region function Add-SSAOutput function Add-SSAOutput { [CmdletBinding()] Param ( [Parameter( Mandatory = $true ) ] $OutputText ) Begin { } Process { $OutputDate = Get-Date -UFormat "%Y-%m-%d" $OutputTime = Get-Date -UFormat "%H:%M:%S" $RichTextBoxMainOutput.Text += "[$OutputDate][$OutputTime] $OutputText`n" Add-Content -Path $SSALogFile -Value "[$OutputDate][$OutputTime] $OutputText`n" } End { } } #endregion #region function Import-SSAActiveDirectoryModule function Import-SSAActiveDirectoryModule { [CmdletBinding()] Param ( ) Begin { } Process { Add-SSAOutput -OutputText "Loading ActiveDirectory PowerShell module." if ((Get-Module -name "ActiveDirectory") -eq $null) { Add-SSAOutput -OutputText "ActiveDirectory PowerShell module is currently not loaded." if (Get-Module -ListAvailable | Where-Object { $_.name -eq "ActiveDirectory" }) { Add-SSAOutput -OutputText "ActiveDirectory PowerShell module is available, importing module." Import-Module -Name "ActiveDirectory" if ((Get-Module -name "ActiveDirectory") -eq $null) { Add-SSAOutput -OutputText "ActiveDirectory PowerShell module could not be loaded." $global:SSAActiveDirectoryModuleLoaded = $false } else { Add-SSAOutput -OutputText "ActiveDirectory PowerShell module has been loaded." $global:SSAActiveDirectoryModuleLoaded = $true } } else { Add-SSAOutput -OutputText "ActiveDirectory PowerShell module is not available on this computer, attempting to import it from a Domain Controller." try { $DomainDNSName = (Get-WmiObject -Class WIN32_ComputerSystem -ErrorAction Stop).Domain $DomainNetBiosName = (Get-WmiObject Win32_NTDomain -Filter "DnsForestName = '$((Get-WmiObject Win32_ComputerSystem).Domain)'" -ErrorAction Stop).DomainName $DomainControllerName = ((Get-WmiObject -Class WIN32_NTDomain -Filter "DomainName = '$DomainNetBiosName'" -ErrorAction Stop).DomainControllerName) -replace "\\", "" $DomainController = "$DomainControllerName.$DomainDNSName" $DomainControllerSession = New-PSSession -Computername $DomainController -ErrorAction Stop Invoke-Command -Command { Import-Module -Name "ActiveDirectory" } -Session $DomainControllerSession -ErrorAction Stop $ImportSession = Import-PSSession -Session $DomainControllerSession -Module ActiveDirectory -AllowClobber -ErrorAction Stop if ($ImportSession.Name) { Add-SSAOutput -OutputText "ActiveDirectory module has been imported from Domain Controller $DomainController." $global:SSAActiveDirectoryModuleLoaded = $true } } catch { Add-SSAOutput -OutputText "ActiveDirectory module could not be imported. Possible reasons are: This workstation is not joined to the Active Directory domain, PowerShell remoting towards the Domain Controller does not work or is not setup, the current user does not have appropriate rights to open a PowerShell session to the Domain Controller." $global:SSAActiveDirectoryModuleLoaded = $false } } } else { Add-SSAOutput -OutputText "ActiveDirectory PowerShell module is already loaded." $global:SSAActiveDirectoryModuleLoaded = $true } } End { } } #endregion #region function Get-SSAUserName function Get-SSAUserName { [CmdletBinding()] Param ( ) Begin { } Process { $global:SSAUserName = $TextBoxMainUserName.text } End { } } #endregion #region function Get-SSAPassword1 function Get-SSAPassword1 { [CmdletBinding()] Param ( ) Begin { } Process { $global:SSAPassword1 = $TextBoxMainNewPassword1.text } End { } } #endregion #region function Get-SSAPassword2 function Get-SSAPassword2 { [CmdletBinding()] Param ( ) Begin { } Process { $global:SSAPassword2 = $TextBoxMainNewPassword2.text } End { } } #endregion #################################################################################################### ### End: Custom functions ########################################################################## #################################################################################################### #endregion Source: Globals.ps1 #Start the application Main ($CommandLine)