Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $formBHSADAccountPassword_Load={
- #TODO: Initialize Form Controls here
- }
- #region Variables for Warning Box
- $MessageBoxTitle = "Warning: AD Module Missing"
- $Messageboxbody = "The Active Directory Powershell Module is not installed. Please install in order to use this tool."
- $MessageIcon = "Warning"
- $ADMod = Get-Module -ListAvailable -Name ActiveDirectory
- #endregion
- #region Test for AD Powershell Module install
- if (-not ($ADMod))
- {
- [System.Windows.MessageBox]::Show($Messageboxbody, $MessageboxTitle, $ButtonType, $messageicon)
- }
- else
- {
- Import-Module ActiveDirectory
- }
- #endregion
- #region Button actions
- $buttonLookup_Click={
- $OutputBox1.Text = Do-Lookup -Username "$($LookupField1.Text)" |
- Format-List @{ Label = "Full Name"; Expression = { ($_.Name) } }, @{ Label = "Username"; Expression = { ($_.SamAccountName) } }, @{ Label = "Dept"; Expression = { ($_.Department) } }, @{ Label = "Locked Out"; Expression = { ($_.LockedOut) } } |
- Out-String
- }
- $buttonUnlockReset_Click = {
- if ($unlock.checked -eq $true)
- {
- $Outputbox1.Text = Do-Unlock -Username "$($UsernameField.Text)"
- }
- else
- {
- $Outputbox1.Text = Do-Reset -Username "$($UsernameField.Text)"
- }
- }
- #endregion
- #region Lookup Function
- function Do-Lookup
- {
- Param(
- $Username
- )
- Get-ADUser -Filter * -Properties SamAccountName, Department, LockedOut | where { $_.Name -like "*$Username*" } | select SamAccountName, Name, Department, LockedOut
- }
- #endregion
- #region Unlock and reset password function
- function Do-Reset
- {
- Param (
- $Username
- )
- Unlock-ADAccount -Identity "$Username"
- Set-ADAccountPassword "$Username" -Newpassword (ConvertTo-SecureString Bournewood1 -AsPlainText -Force) -Reset -PassThru | Set-ADuser -ChangePasswordAtLogon $True
- }
- #endregion
- #region Unlock only function
- function Do-Unlock
- {
- Param (
- $Username
- )
- Unlock-ADAccount -Identity "$Username"
- }
- #endregion
- #region Don't know why these are here, PowerShell Studio bitches when I remove them.
- $UsernameField_TextChanged={
- #TODO: Place custom script here
- }
- $LookupField1_TextChanged={
- #TODO: Place custom script here
- }
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement