Building a Fully Functional Active Directory User Management Tool with PowerShell and XAML
- Vicky Kadam

- Jul 24
- 26 min read
Updated: Jul 31
Creating an efficient user management tool for Active Directory (AD) is essential for organizations that need strict control over user permissions and roles. This blog post will guide you through building a fully functional GUI using PowerShell and XAML, specifically designed for Level 1 (L1) engineers. L1 engineers typically require limited access to execute tasks, ensuring they can manage user roles without risking accidental changes to critical components like users, groups, and organizational units (OUs).
In this guide, we will discuss the whole process of developing this tool from the ground up, including practical examples, code snippets, and vital features that boost usability.
Understanding the Basics of PowerShell and XAML
PowerShell is a task automation and configuration management framework that combines a command-line shell with a powerful scripting language. XAML (Extensible Application Markup Language) is an XML-based language used for initializing structured values or objects in .NET applications. When these two tools are combined, they create effective user interfaces that streamline AD management tasks.
PowerShell is known for its flexibility and efficiency, allowing system administrators to automate repetitive tasks and manage systems seamlessly. However, for novice users, the standard command-line interface might seem daunting. This is where XAML steps in, providing a user-friendly graphical interface.
Key Features of the User Management Tool
The Active Directory User Management Tool we are about to create will encompass several critical features for L1 engineers:
User Creation: Quickly add new users to the AD.
User Modification: Change details for existing users without errors.
User Deactivation: Temporarily disable users during leave or termination.
Group Management: Assign and manage user groups effectively.
These features assure that L1 engineers can manage users reliably without the risk of unintentional changes to essential AD components. As a result, organizations can monitor their user base effectively, safeguarding against potential security breaches.
Setting Up the Development Environment
Before creating our GUI, ensure you have the following prerequisites installed on your system:
Operating System: Windows 10 or later.
PowerShell: Version 5.1 or later is necessary for compatibility.
Text Editor: Use Visual Studio Code or Notepad++ for coding.
Do not forget to run PowerShell with administrative privileges, especially when modifying Active Directory data.
Building the GUI with XAML
Let’s start by creating the graphical interface using XAML.
Creating the XAML Layout
Create a new file named `Form.xaml` and open it in your text editor. Below is a basic layout for our AD User Management Tool:
```xml
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="User Managment Tool" Width="1900" Height="800"
WindowStartupLocation ="CenterScreen"
ResizeMode="CanMinimize">
<Grid Background="#3f52c2">
<TabControl Margin="10,6,16,23"><TabItem Header="Find User and Computers ">
<Grid Background="#e5efff">
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="User Name:" Margin="15,24,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtUserName}"/>
<TextBox Name="txtUserName" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="111,25,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Computer Name:" Margin="459,25,0,0" FontSize="12" FontWeight="Bold" Target="{Binding ElementName=txtComputerName}"/>
<TextBox Name="txtComputerName" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="588,25,0,0" FontSize="14"/>
<Button Name="btFindNow" Content="Find Now" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1100,17.984375,0,0" FontWeight="Bold" FontSize="12"/>
<Button Name="btClearAll" Content="Clear All" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1300,20,0,0" FontSize="12" FontWeight="Bold"/>
<Button Name="btPwdReset" Content="Pwd Reset" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1500,19,0,0" FontSize="12" FontWeight="Bold"/>
<Button Name="btUpdateUser" Content="Update User" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1700,19,0,0" FontSize="12" FontWeight="Bold"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Operating System:" Margin="457,120,0,0" FontSize="12" FontWeight="Bold" Target="{Binding ElementName=txtOperatingSystem}"/>
<TextBox Name="txtOperatingSystem" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="590,120,0,0" FontSize="14"/>
<Button Name="btUserUnlock" Content="User Unlock" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1100,108,0,0" FontSize="12" FontWeight="Bold"/>
<Button Name="btUserEnable" Content="User Enable" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1300,108,0,0" FontSize="12" FontWeight="Bold"/>
<Button Name="btUserDisable" Content="User Disable" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1500,108,0,0" FontSize="12" FontWeight="Bold"/>
<Button Name="btExport" Content="Export" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1700,105,0,0" FontSize="12" FontWeight="Bold"/>
<DataGrid Name="dgFindUsers" HorizontalAlignment="Left" VerticalAlignment="Top" Width="1830" Height="390" Margin="10,300,0,0" AutoGenerateColumns="True" ColumnWidth="*" IsReadOnly="True" >
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontWeight" Value="Bold"/>
</Style>
</DataGrid.ColumnHeaderStyle>
</DataGrid>
</Grid></TabItem>
<TabItem Header="User Creation"><Grid Background="#e5efff">
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="User Name:" Margin="15,24,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtUserName2}" />
<TextBox Name="txtUserName2" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="111,25,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Initials:" Margin="500,24,0,0" FontSize="14" FontWeight="Bold" Target="{Binding ElementName=txtInitials}"/>
<TextBox Name="txtInitials" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="570,25,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Last Name:" Margin="1000,24,0,0" FontSize="12" FontWeight="Bold" Target="{Binding ElementName=txtLastName}"/>
<TextBox Name="txtLastName" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="1100,25,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Full Name:" Margin="15,100,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtFullName}" />
<TextBox Name="txtFullName" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="111,100,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="User Logon Name:" Margin="500,100,0,0" FontSize="12" FontWeight="Bold" Target="{Binding ElementName=txtUserLogonName}"/>
<TextBox Name="txtUserLogonName" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="650,100,0,0" FontSize="14" />
<ComboBox Name="cbUserLogonName" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="400" Margin="1000,100,0,0" FontSize="14" />
<TextBox Name="txtPreLogonName" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="200" TextWrapping="Wrap" Margin="300,190,0,0" FontSize="14" IsReadOnly="True"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="User Logon Name (pre-Windows 2000):" Margin="15,190,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtPreLogonName2}" />
<TextBox Name="txtPreLogonName2" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="530,190,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="OU:" Margin="850,190,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=cbOU}" />
<ComboBox Name="cbOU" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="500" Margin="900,190,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Password:" Margin="1440,190,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtGeneratePwd}"/>
<TextBox Name="txtGeneratePwd" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="1530,190,0,0" FontSize="14"/>
<StackPanel Orientation="Horizontal">
<CheckBox Name="chkboxPwdChangeatLogon" HorizontalAlignment="Left" VerticalAlignment="Top" Content="User must change Password at next logon" Margin="15,260,0,0"/>
<CheckBox Name="chkboxPwdNeverExpire" HorizontalAlignment="Left" VerticalAlignment="Top" Content="Password never Expire" Margin="40,260,0,0" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Account Expire:" Margin="15,320,0,0" />
<RadioButton Name="Never" HorizontalAlignment="Left" VerticalAlignment="Top" Content="Never" Margin="25,326,0,0" IsChecked="True" />
<RadioButton Name="EndOf" HorizontalAlignment="Left" VerticalAlignment="Top" Content="End Of" Margin="30,326,0,0"/>
<DatePicker Name="DateSelected" HorizontalAlignment="Left" VerticalAlignment="Top" Height="25" Width="110" Margin="50,320,0,0" />
</StackPanel>
<Button Name="btGeneratePwd" Content="Generate Pwd" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1300,300,0,0" FontSize="12" FontWeight="Bold"/>
<Button Name="btCreate" Content="Create" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1530,300,0,0" FontSize="12" FontWeight="Bold"/>
<TextBox Background="#F0F0F0" Name="txtUserCreation" HorizontalAlignment="Left" VerticalAlignment="Top" Width="1830" Height="289" Margin="10,400,0,0" FontWeight="Normal" FontSize="14" TextWrapping="Wrap" IsReadOnly="True" />
</Grid></TabItem>
<TabItem Header="Group Modification and Account Modification"><Grid Background="#FFE5E5E5">
<Grid Background="#e5efff">
<GroupBox Header="Find Groups and Add Members" HorizontalAlignment="Left" Height="123" Margin="10,20,0,0" VerticalAlignment="Top" Width="1830" FontWeight="Bold" FontSize="12" BorderThickness="1" BorderBrush="#FF0C0D0D">
<StackPanel>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Group Name:" Margin="15,30,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtFindGroup}"/>
<TextBox Name="txtFindGroup" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="500" TextWrapping="Wrap" Margin="115,-25,0,0" FontWeight="Normal" FontSize="14"/>
<Button Name="btFindGroup" Content="Find Group" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1200,-35,0,0" FontSize="12" FontWeight="Bold"/>
<Button Name="btUpdateGroup" Content="Update" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1400,-40,0,0" FontSize="12" FontWeight="Bold"/>
</StackPanel>
</GroupBox>
<GroupBox Header="Create Groups" HorizontalAlignment="Left" Height="300" Margin="10,150,0,0" VerticalAlignment="Top" Width="1830" FontWeight="Bold" FontSize="12" BorderThickness="1" BorderBrush="#FF0C0D0D">
<StackPanel>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Group Name:" Margin="15,25,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtGroupName}"/>
<TextBox Name="txtGroupName" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="500" TextWrapping="Wrap" Margin="115,-25,0,0" FontWeight="Normal" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Group Name(pre-Windows 2000):" Margin="650,-30,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtGroupNamePre2000}"/>
<TextBox Name="txtGroupNamePre2000" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="500" TextWrapping="Wrap" Margin="870,-30,0,0" FontWeight="Normal" FontSize="14" />
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="OU Path:" Margin="15,30,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtOUPath}"/>
<ComboBox Name="cbOUPath" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="500" Margin="115,-25,0,0" FontWeight="Normal" FontSize="14"/>
<GroupBox Header="Group Scope" HorizontalAlignment="Left" Height="120" Margin="115,20,0,0" VerticalAlignment="Top" Width="500" FontSize="12" BorderThickness="1" BorderBrush="#FF0C0D0D">
<StackPanel>
<RadioButton Name="rdbDomainLocal" HorizontalAlignment="Left" VerticalAlignment="Top" Content="Domain Local" Margin="10,15,0,0" GroupName="Group1" />
<RadioButton Name="rdbGlobal" HorizontalAlignment="Left" VerticalAlignment="Top" Content="Global" Margin="10,15,0,0" GroupName="Group1"/>
<RadioButton Name="rdbUniversal" HorizontalAlignment="Left" VerticalAlignment="Top" Content="Universal" Margin="10,15,0,0" GroupName="Group1"/>
</StackPanel>
</GroupBox>
<GroupBox Header="Group Type" HorizontalAlignment="Left" Height="120" Margin="870,-120,0,0" VerticalAlignment="Top" Width="500" FontSize="12" BorderThickness="1" BorderBrush="#FF0C0D0D">
<StackPanel>
<RadioButton Name="rdbSecurity" HorizontalAlignment="Left" VerticalAlignment="Top" Content="Security" Margin="10,15,0,0" GroupName="Group2"/>
<RadioButton Name="rdbDistribution" HorizontalAlignment="Left" VerticalAlignment="Top" Content="Distribution" Margin="10,15,0,0" GroupName="Group2"/>
</StackPanel>
</GroupBox>
<Button Name="btCreateGroup" Content="Create" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1690,-40,0,0" FontSize="12" FontWeight="Bold"/>
</StackPanel>
</GroupBox>
<DataGrid Name="dgFindGroupName" HorizontalAlignment="Left" VerticalAlignment="Top" Width="1830" Height="230" Margin="10,460,0,0" AutoGenerateColumns="True" ColumnWidth="*" IsReadOnly="True" >
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontWeight" Value="Bold"/>
</Style>
</DataGrid.ColumnHeaderStyle>
</DataGrid>
<TextBox Name="txtDataOutBox" HorizontalAlignment="Left" VerticalAlignment="Top" Height="230" Width="1830" TextWrapping="Wrap" Margin="10,460,0,0" FontSize="14" Visibility="Collapsed" />
</Grid>
</Grid></TabItem></TabControl>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="©vtechie.co.in" Margin="1800,737,0,0" Foreground="#FFE0E0E0" FontWeight="Bold" FontSize="11" />
</Grid>
</Window>
```
Explanation of the Layout
The layout includes:
A title label for identification.
A TextBox for L1 engineers to enter usernames.
Buttons for different user management tasks: creation, modification, and deactivation.
These controls provide a straightforward way for users to interact with Active Directory without needing to rely on complex PowerShell commands, significantly lowering the risk of accidental changes.
Integrating PowerShell with the GUI
Now we will integrate PowerShell functionality into our GUI by creating the code-behind file `ADUserManager.xaml.cs`. Below is an example of how to handle button clicks:
```Powershell
#Load Assemblies
Add-Type -AssemblyName PresentationFramework, presentationcore
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
Add-Type -AssemblyName System.Web
# Enable Visual Styles
[System.Windows.Forms.Application]::EnableVisualStyles()
$form = @{}
[xml]$xaml = Get-Content -Path ".\Form.xaml"
$Reader = New-Object System.Xml.XmlNodeReader $xaml
$Window = [Windows.Markup.XamlReader]::Load($Reader)
$namedNodes = $xaml.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]")
$namedNodes | ForEach-Object {$form.Add($_.Name, $Window.FindName($_.Name))}
##################### Your Code goes here #############################
############### Function Code Start ##################
function Get-folder {
$SaveFileDialog = New-Object Windows.Forms.FolderBrowserDialog
$SaveFileDialog.RootFolder = "MyComputer"
if ($SaveFileDialog.ShowDialog() -eq 'OK') {
$SelectedFolderPath = $SaveFileDialog.SelectedPath
# Process the selected folder path as needed
return $SelectedFolderPath }
}
Function ExcelGrid {
If ( ($form.txtUserName.Text -ne "") -and ($form.txtComputerName.Text -eq "") -and ($form.txtOperatingSystem.Text -eq "")) {
$ServerName = Get-PDC
$Name = $form.txtUserName.Text
$UserObj = Get-ADUser -Server $ServerName -Filter * -Properties Name, SamAccountName, Mail,Enabled,LockedOut,PasswordExpired,PasswordLastSet,Modified,AccountExpirationDate | Where-Object { ($_.samAccountName -eq $name) -or ($_.Name -match $name) -or ($_.mail -eq $name) } | select Name, SamAccountName, Mail,Enabled,LockedOut,PasswordExpired,PasswordLastSet,Modified,AccountExpirationDate
$UserNameObj = New-Object System.collections.ArrayList
$UserNameObj.AddRange(@($UserObj))
$Form.dgFindUsers.ItemsSource = $UserNameObj
}elseif( ($form.txtUserName.Text -eq "") -and- ($form.txtComputerName.Text -ne "") -and ($form.txtOperatingSystem.Text -eq "")){
$CompObjName = $form.txtComputerName.Text
$CompObj = Get-ADComputer -Filter * -Properties Name,IPv4Address,Enabled,Created,LastLogonDate,OperatingSystem,DistinguishedName | Where-Object { ($_.Name -match $CompObjName) } | select Name,IPv4Address,Enabled,Created,LastLogonDate,OperatingSystem,DistinguishedName
$Obj = New-Object System.collections.ArrayList
$Obj.AddRange(@($CompObj))
$Form.dgFindUsers.ItemsSource = $Obj
}elseif( ($form.txtUserName.Text -eq "") -and- ($form.txtComputerName.Text -eq "") -and ($form.txtOperatingSystem.Text -ne "")) {
$CompObjName = $form.txtOperatingSystem.Text
$CompObj = Get-ADComputer -Filter * -Properties Name,IPv4Address,Enabled,Created,LastLogonDate,OperatingSystem,DistinguishedName | Where-Object { ($_.OperatingSystem -match $CompObjName) } | select Name,IPv4Address,Enabled,Created,LastLogonDate,OperatingSystem,DistinguishedName
$Obj = New-Object System.collections.ArrayList
$Obj.AddRange(@($CompObj))
$Form.dgFindUsers.ItemsSource = $Obj
}elseif( ($form.txtUserName.Text -eq "") -and ($form.txtComputerName.Text -eq "") -and ($form.txtOperatingSystem.Text -eq "")){
$Name = $form.txtUserName.Text
$UserObj = Get-ADUser -Filter * -Properties Name, SamAccountName, Mail,Enabled,LockedOut,PasswordExpired,PasswordLastSet,Modified,AccountExpirationDate | Where-Object { ($_.samAccountName -eq $name) -or ($_.Name -match $name) -or ($_.mail -eq $name) } | select Name, SamAccountName, Mail,Enabled,LockedOut,PasswordExpired,PasswordLastSet,Modified,AccountExpirationDate
$UserNameObj = New-Object System.collections.ArrayList
$UserNameObj.AddRange(@($UserObj))
$Form.dgFindUsers.ItemsSource = $UserNameObj
}
}
function Get-PDC {
$PDC = Get-ADDomainController -Filter * | Where {$_.OperationMasterRoles -like 'PDCEmulator'} | Select -ExpandProperty Name
$online = Test-Connection -ComputerName $PDC -Count 1 -Quiet
$Server = If ($online){return $PDC
}else{
Get-ADDomainController |Select Name
#return $DC
}
$Server
}
function Create-User {
$ServerName = Get-PDC
$Name = $form.txtUserName2.Text
$Initials = If($form.txtInitials.Text -eq ""){$form.txtInitials.Text = $null} else{$form.txtInitials.Text}
$AdLogin = (Get-ADUser $form.txtPreLogonName2.Text -Server $ServerName |Select SamAccountName -ErrorAction SilentlyContinue)
If($AdLogin){$form.txtUserCreation.Text = Write-Output samAccountName $form.txtPreLogonName2.Text already exists. Try using another samAccountName}Else{
If (($form.chkboxPwdChangeatLogon.IsChecked -eq $false) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $false) -and ($form.EndOf.IsChecked) -and ($form.DateSelected.SelectedDate) ){
New-Aduser -Server $ServerName -Name $form.txtFullName.Text -GivenName $form.txtUserName2.Text -Initials $Initials -Surname $form.txtLastName.Text -DisplayName $form.txtFullName.Text -UserPrincipalName ($form.txtUserLogonName.Text + $form.cbUserLogonName.Text) -SamAccountName $form.txtPreLogonName2.Text -Path $form.cbOU.Text -AccountPassword (ConvertTo-secureString $form.txtGeneratePwd.Text -AsPlainText -Force) -ChangePasswordAtLogon $false -PasswordNeverExpires $false -CannotChangePassword $false -Enabled $true
Set-ADAccountExpiration -Identity $form.txtPreLogonName2.Text -Server $ServerName -DateTime $form.DateSelected.SelectedDate
$form.txtUserCreation.Text = Write-Output Created $form.txtPreLogonName2.Text user in $form.cbOU.Text
}ElseIf(($form.chkboxPwdChangeatLogon.IsChecked -eq $true) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $false) -and ($form.EndOf.IsChecked) -and ($form.DateSelected.SelectedDate) ){
New-Aduser -Server $ServerName -Name $form.txtFullName.Text -GivenName $form.txtUserName2.Text -Initials $Initials -Surname $form.txtLastName.Text -DisplayName $form.txtFullName.Text -UserPrincipalName ($form.txtUserLogonName.Text + $form.cbUserLogonName.Text) -SamAccountName $form.txtPreLogonName2.Text -Path $form.cbOU.Text -AccountPassword (ConvertTo-secureString $form.txtGeneratePwd.Text -AsPlainText -Force) -ChangePasswordAtLogon $true -PasswordNeverExpires $false -CannotChangePassword $false -Enabled $true
Set-ADAccountExpiration -Identity $form.txtPreLogonName2.Text -Server $ServerName -DateTime $form.DateSelected.SelectedDate
$form.txtUserCreation.Text = Write-Output Created $form.txtPreLogonName2.Text user in $form.cbOU.Text
}ElseIf(($form.chkboxPwdChangeatLogon.IsChecked -eq $false) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $true) -and ($form.EndOf.IsChecked) -and ($form.DateSelected.SelectedDate) ){
New-Aduser -Server $ServerName -Name $form.txtFullName.Text -GivenName $form.txtUserName2.Text -Initials $Initials -Surname $form.txtLastName.Text -DisplayName $form.txtFullName.Text -UserPrincipalName ($form.txtUserLogonName.Text + $form.cbUserLogonName.Text) -SamAccountName $form.txtPreLogonName2.Text -Path $form.cbOU.Text -AccountPassword (ConvertTo-secureString $form.txtGeneratePwd.Text -AsPlainText -Force) -ChangePasswordAtLogon $false -PasswordNeverExpires $true -CannotChangePassword $false -Enabled $true
Set-ADAccountExpiration -Identity $form.txtPreLogonName2.Text -Server $ServerName -DateTime $form.DateSelected.SelectedDate
$form.txtUserCreation.Text = Write-Output Created $form.txtPreLogonName2.Text user in $form.cbOU.Text
}ElseIf(($form.chkboxPwdChangeatLogon.IsChecked -eq $true) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $true) -and ($form.EndOf.IsChecked) -and ($form.DateSelected.SelectedDate) ){
$form.txtUserCreation.Text = Write-Output Error: Cannot use both '"User must change Password at next logon"' and '"Password never Expire"'
####################################################################################################
}ElseIf(($form.chkboxPwdChangeatLogon.IsChecked -eq $false) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $false) -and ($form.EndOf.IsChecked) -and ($form.DateSelected.SelectedDate)){
New-Aduser -Server $ServerName -Name $form.txtFullName.Text -GivenName $form.txtUserName2.Text -Initials $Initials -Surname $form.txtLastName.Text -DisplayName $form.txtFullName.Text -UserPrincipalName ($form.txtUserLogonName.Text + $form.cbUserLogonName.Text) -SamAccountName $form.txtPreLogonName2.Text -Path $form.cbOU.Text -AccountPassword (ConvertTo-secureString $form.txtGeneratePwd.Text -AsPlainText -Force) -ChangePasswordAtLogon $false -PasswordNeverExpires $false -CannotChangePassword $false -Enabled $true
Set-ADAccountExpiration -Identity $form.txtPreLogonName2.Text -Server $ServerName -DateTime $form.DateSelected.SelectedDate
$form.txtUserCreation.Text = Write-Output Created $form.txtPreLogonName2.Text user in $form.cbOU.Text
}ElseIf(($form.chkboxPwdChangeatLogon.IsChecked -eq $true) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $false) -and ($form.EndOf.IsChecked) -and ($form.DateSelected.SelectedDate)){
New-Aduser -Server $ServerName -Name $form.txtFullName.Text -GivenName $form.txtUserName2.Text -Initials $Initials -Surname $form.txtLastName.Text -DisplayName $form.txtFullName.Text -UserPrincipalName ($form.txtUserLogonName.Text + $form.cbUserLogonName.Text) -SamAccountName $form.txtPreLogonName2.Text -Path $form.cbOU.Text -AccountPassword (ConvertTo-secureString $form.txtGeneratePwd.Text -AsPlainText -Force) -ChangePasswordAtLogon $true -PasswordNeverExpires $false -CannotChangePassword $false -Enabled $true
Set-ADAccountExpiration -Identity $form.txtPreLogonName2.Text -Server $ServerName -DateTime $form.DateSelected.SelectedDate
$form.txtUserCreation.Text = Write-Output Created $form.txtPreLogonName2.Text user in $form.cbOU.Text
}ElseIf(($form.chkboxPwdChangeatLogon.IsChecked -eq $false) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $true) -and ($form.EndOf.IsChecked) -and ($form.DateSelected.SelectedDate)){
New-Aduser -Server $ServerName -Name $form.txtFullName.Text -GivenName $form.txtUserName2.Text -Initials $Initials -Surname $form.txtLastName.Text -DisplayName $form.txtFullName.Text -UserPrincipalName ($form.txtUserLogonName.Text + $form.cbUserLogonName.Text) -SamAccountName $form.txtPreLogonName2.Text -Path $form.cbOU.Text -AccountPassword (ConvertTo-secureString $form.txtGeneratePwd.Text -AsPlainText -Force) -ChangePasswordAtLogon $false -PasswordNeverExpires $true -CannotChangePassword $false -Enabled $true
Set-ADAccountExpiration -Identity $form.txtPreLogonName2.Text -Server $ServerName -DateTime $form.DateSelected.SelectedDate
$form.txtUserCreation.Text = Write-Output Created $form.txtPreLogonName2.Text user in $form.cbOU.Text
}ElseIf(($form.chkboxPwdChangeatLogon.IsChecked -eq $true) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $true) -and ($form.EndOf.IsChecked) -and ($form.DateSelected.SelectedDate) ){
$form.txtUserCreation.Text = Write-Output Error: Cannot use both '"User must change Password at next logon"' and '"Password never Expire"'
####################################################################################################
}ElseIf(($form.chkboxPwdChangeatLogon.IsChecked -eq $false) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $false) -and ($form.EndOf.IsChecked) ){
$form.txtUserCreation.Text = Write-Output Error: Account expire date must be selected
}ElseIf(($form.chkboxPwdChangeatLogon.IsChecked -eq $true) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $false) -and ($form.EndOf.IsChecked) ){
$form.txtUserCreation.Text = Write-Output Error: Account expire date must be selected
}ElseIf(($form.chkboxPwdChangeatLogon.IsChecked -eq $false) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $true) -and ($form.EndOf.IsChecked) ){
$form.txtUserCreation.Text = Write-Output Error: Account expire date must be selected
}ElseIf(($form.chkboxPwdChangeatLogon.IsChecked -eq $false) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $false) -and ($form.EndOf.IsChecked)){
$form.txtUserCreation.Text = Write-Output Error: Account expire date must be selected
}ElseIf(($form.chkboxPwdChangeatLogon.IsChecked -eq $true) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $false) -and ($form.EndOf.IsChecked)){
$form.txtUserCreation.Text = Write-Output Error: Account expire date must be selected
}ElseIf(($form.chkboxPwdChangeatLogon.IsChecked -eq $false) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $true) -and ($form.EndOf.IsChecked)){
$form.txtUserCreation.Text = Write-Output Error: Account expire date must be selected
####################################################################################################
}ElseIf(($form.chkboxPwdChangeatLogon.IsChecked -eq $false) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $false) ){
New-Aduser -Server $ServerName -Name $form.txtFullName.Text -GivenName $form.txtUserName2.Text -Initials $Initials -Surname $form.txtLastName.Text -DisplayName $form.txtFullName.Text -UserPrincipalName ($form.txtUserLogonName.Text + $form.cbUserLogonName.Text) -SamAccountName $form.txtPreLogonName2.Text -Path $form.cbOU.Text -AccountPassword (ConvertTo-secureString $form.txtGeneratePwd.Text -AsPlainText -Force) -ChangePasswordAtLogon $false -PasswordNeverExpires $false -CannotChangePassword $false -Enabled $true
$form.txtUserCreation.Text = Write-Output Created $form.txtPreLogonName2.Text user in $form.cbOU.Text
}Elseif(($form.chkboxPwdChangeatLogon.IsChecked -eq $true) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $false) ){
New-Aduser -Server $ServerName -Name $form.txtFullName.Text -GivenName $form.txtUserName2.Text -Initials $Initials -Surname $form.txtLastName.Text -DisplayName $form.txtFullName.Text -UserPrincipalName ($form.txtUserLogonName.Text + $form.cbUserLogonName.Text) -SamAccountName $form.txtPreLogonName2.Text -Path $form.cbOU.Text -AccountPassword (ConvertTo-secureString $form.txtGeneratePwd.Text -AsPlainText -Force) -ChangePasswordAtLogon $true -PasswordNeverExpires $false -CannotChangePassword $false -Enabled $true
$form.txtUserCreation.Text = Write-Output Created $form.txtPreLogonName2.Text user in $form.cbOU.Text
}Elseif(($form.chkboxPwdChangeatLogon.IsChecked -eq $false) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $true) ){
New-Aduser -Server $ServerName -Name $form.txtFullName.Text -GivenName $form.txtUserName2.Text -Initials $Initials -Surname $form.txtLastName.Text -DisplayName $form.txtFullName.Text -UserPrincipalName ($form.txtUserLogonName.Text + $form.cbUserLogonName.Text) -SamAccountName $form.txtPreLogonName2.Text -Path $form.cbOU.Text -AccountPassword (ConvertTo-secureString $form.txtGeneratePwd.Text -AsPlainText -Force) -ChangePasswordAtLogon $false -PasswordNeverExpires $true -CannotChangePassword $false -Enabled $true
$form.txtUserCreation.Text = Write-Output Created $form.txtPreLogonName2.Text user in $form.cbOU.Text
}Elseif(($form.chkboxPwdChangeatLogon.IsChecked -eq $true) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $true) ){
$form.txtUserCreation.Text = Write-Output Error: Cannot use both '"User must change Password at next logon"' and '"Password never Expire"'
####################################################################################################
}ElseIf(($form.chkboxPwdChangeatLogon.IsChecked -eq $false) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $false)){
New-Aduser -Server $ServerName -Name $form.txtFullName.Text -GivenName $form.txtUserName2.Text -Initials $Initials -Surname $form.txtLastName.Text -DisplayName $form.txtFullName.Text -UserPrincipalName ($form.txtUserLogonName.Text + $form.cbUserLogonName.Text) -SamAccountName $form.txtPreLogonName2.Text -Path $form.cbOU.Text -AccountPassword (ConvertTo-secureString $form.txtGeneratePwd.Text -AsPlainText -Force) -ChangePasswordAtLogon $false -PasswordNeverExpires $false -CannotChangePassword $false -Enabled $true
$form.txtUserCreation.Text = Write-Output Created $form.txtPreLogonName2.Text user in $form.cbOU.Text
}Elseif(($form.chkboxPwdChangeatLogon.IsChecked -eq $true) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $false)){
New-Aduser -Server $ServerName -Name $form.txtFullName.Text -GivenName $form.txtUserName2.Text -Initials $Initials -Surname $form.txtLastName.Text -DisplayName $form.txtFullName.Text -UserPrincipalName ($form.txtUserLogonName.Text + $form.cbUserLogonName.Text) -SamAccountName $form.txtPreLogonName2.Text -Path $form.cbOU.Text -AccountPassword (ConvertTo-secureString $form.txtGeneratePwd.Text -AsPlainText -Force) -ChangePasswordAtLogon $true -PasswordNeverExpires $false -CannotChangePassword $false -Enabled $true
$form.txtUserCreation.Text = Write-Output Created $form.txtPreLogonName2.Text user in $form.cbOU.Text
}Elseif(($form.chkboxPwdChangeatLogon.IsChecked -eq $false) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $true)){
New-Aduser -Server $ServerName -Name $form.txtFullName.Text -GivenName $form.txtUserName2.Text -Initials $Initials -Surname $form.txtLastName.Text -DisplayName $form.txtFullName.Text -UserPrincipalName ($form.txtUserLogonName.Text + $form.cbUserLogonName.Text) -SamAccountName $form.txtPreLogonName2.Text -Path $form.cbOU.Text -AccountPassword (ConvertTo-secureString $form.txtGeneratePwd.Text -AsPlainText -Force) -ChangePasswordAtLogon $false -PasswordNeverExpires $true -CannotChangePassword $false -Enabled $true
$form.txtUserCreation.Text = Write-Output Created $form.txtPreLogonName2.Text user in $form.cbOU.Text
}Elseif(($form.chkboxPwdChangeatLogon.IsChecked -eq $true) -and ($form.chkboxPwdNeverExpire.IsChecked -eq $true)){
$form.txtUserCreation.Text = Write-Output Error: Cannot use both '"User must change Password at next logon"' and '"Password never Expire"'
####################################################################################################
}
}
}
############### Function Code End ##############
##################################################
###################### TAB 1 Code Below ########################
$form.btFindNow.add_Click({
ExcelGrid
})
$form.btClearAll.add_Click({
If (($form.txtUserName.Text -ne "") -or ($form.txtComputerName.Text -ne "") -or ($form.txtUserName.Text -eq "" -and $form.txtComputerName.Text -eq "")){
$form.txtUserName.Text = ""
$form.txtComputerName.Text = ""
$form.txtOperatingSystem.Text = ""
$Form.dgFindUsers.ItemsSource = $null
}
})
$form.btPwdReset.add_Click({
[XML]$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Width="1530" Height="600">
<Grid Background="#3f52c2">
<TabControl Margin="10,6,16,23"><TabItem Header="Generate New Password "><Grid Background="#e5efff">
<TextBox Name="txtGeneratPwd" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="500" TextWrapping="Wrap" Margin="111,100,0,0" FontSize="14"/>
<Button Name="btGeneratePwd" Content="GeneratePwd" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="800,95,0,0" FontSize="12" FontWeight="Bold"/>
<Button Name="btSetPwd" Content="SetPwd" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1000,95,0,0" FontSize="12" FontWeight="Bold"/>
<TextBox Name="txtGeneratePassword" HorizontalAlignment="Left" VerticalAlignment="Top" Width="1460" Height="284" Margin="10,200,0,0" FontSize="14" />
</Grid></TabItem>
</TabControl>
</Grid>
</Window>
"@
$Reader = (New-Object System.Xml.XmlNodeReader $xaml)
$PwdResetWindow = [Windows.Markup.XamlReader]::Load($Reader)
$PwdResetWindow.FindName
$xaml.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | %{Set-Variable -Name ($_.Name) -Value $PwdResetWindow.FindName($_.Name)}
$btGeneratePwd.add_Click({
$Psswd = [System.Web.Security.Membership]::GeneratePassword(14,4)
$txtGeneratPwd.Text = $Psswd
})
$btSetPwd.add_Click({
$GetPsswd = $txtGeneratPwd.Text
$ServerName = Get-PDC
Get-ADUser $form.txtUserName.Text -Server $ServerName |Set-ADAccountPassword -NewPassword (ConvertTo-SecureString $GetPsswd -AsPlainText -Force) -Reset
$txtGeneratePassword.Text = Write-output New Password Set for $form.txtUserName.Text
$samAccountName = $form.txtUserName.Text
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Password Management
New Password set for user $samAccountName
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 0 -EntryType information
})
$PwdResetWindow.SHowDialog()
$PwdResetWindow.Close()
})
$form.btUserUnlock.add_Click({
[XML]$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Width="1530" Height="600">
<Grid Background="#3f52c2">
<TabControl Margin="10,6,16,23"><TabItem Header="Generate New Password "><Grid Background="#e5efff">
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Enter UserName to Unlock :" Margin="15,100,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtUserUnlock}"/>
<TextBox Name="txtUserUnlock" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="500" TextWrapping="Wrap" Margin="220,100,0,0" FontSize="14"/>
<Button Name="btUnlock" Content="Click to Unlock" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="900,95,0,0" FontSize="12" FontWeight="Bold"/>
<TextBox Name="txtUnlock" HorizontalAlignment="Left" VerticalAlignment="Top" Width="1460" Height="284" Margin="10,200,0,0" FontWeight="Bold" FontSize="14" TextWrapping="Wrap" />
</Grid></TabItem>
</TabControl>
</Grid>
</Window>
"@
$Reader = (New-Object System.Xml.XmlNodeReader $xaml)
$UnlockUser = [Windows.Markup.XamlReader]::Load($Reader)
$UnlockUser.FindName
$xaml.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | %{Set-Variable -Name ($_.Name) -Value $UnlockUser.FindName($_.Name)}
$btUnlock.add_Click({
$DCObj = Get-ADDomainController -Filter *
$DCObj.Hostname
If ($txtUserUnlock.Text -eq "") { $txtUnlock.Text = Write-Output User name should not be blank}else{
foreach ($Server in $DCObj.Hostname) {
$online = Test-Connection -ComputerName $Server -Count 1 -Quiet
If ($online){
#$txtUnlock.Text = Write-Output $Server is reachable. Unlocking user $txtUserUnlock.Text
try{
Unlock-ADAccount -identity $txtUserUnlock.Text -Server $Server
$txtUnlock.Text = Write-Output User $txtUserUnlock.Text is Unlocked.
#$txtUnlock.Text = Write-Output $Server is reachable. Unlocking user $txtUserUnlock.Text
$samAccountNameUnlock = $txtUserUnlock.Text
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
User account $samAccountNameUnlock unlocked
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 0 -EntryType information
}catch{
if ($_.Exception.Message -eq "insufficient access rights to perform the operation"){
$txtUnlock.Text = Write-Host "User Unlock failed: insufficient access rights to perform the operation"}
}}
}
}
})
$UnlockUser.SHowDialog()
$UnlockUser.Close()
})
$form.btUserEnable.add_Click({
[XML]$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Width="1530" Height="600">
<Grid Background="#3f52c2">
<TabControl Margin="10,6,16,23"><TabItem Header="Enable User Account"><Grid Background="#e5efff">
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="UserName to Enable :" Margin="15,100,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtUserUnlock}"/>
<TextBox Name="txtUserEnable" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="500" TextWrapping="Wrap" Margin="220,100,0,0" FontSize="14"/>
<Button Name="btUnlock" Content="Click to Unlock" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="900,95,0,0" FontSize="12" FontWeight="Bold"/>
<TextBox Name="txtEnable" HorizontalAlignment="Left" VerticalAlignment="Top" Width="1460" Height="284" Margin="10,200,0,0" FontWeight="Bold" FontSize="14" TextWrapping="Wrap" />
</Grid></TabItem>
</TabControl>
</Grid>
</Window>
"@
$Reader = (New-Object System.Xml.XmlNodeReader $xaml)
$UserEnable = [Windows.Markup.XamlReader]::Load($Reader)
$UserEnable.FindName
$xaml.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | %{Set-Variable -Name ($_.Name) -Value $UserEnable.FindName($_.Name)}
$btUnlock.add_Click({
try{
Enable-ADAccount -identity $txtUserEnable.Text
$txtEnable.Text = Write-Output User $txtUserEnable.Text is Enabled.
$samAccountNameEnabled = $txtUserEnable.Text
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
User account $samAccountNameEnabled Enabled
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 0 -EntryType information
}catch{
if ($_.Exception.Message -eq "insufficient access rights to perform the operation"){
$txtEnable.Text = Write-Host "User Unlock failed: insufficient access rights to perform the operation"}}
})
$UserEnable.SHowDialog()
$UserEnable.Close()
})
$form.btUserDisable.add_Click({
[XML]$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Width="1530" Height="600">
<Grid Background="#3f52c2">
<TabControl Margin="10,6,16,23"><TabItem Header="Disable User Account "><Grid Background="#e5efff">
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="UserName to Disable :" Margin="15,100,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtUserDisable}"/>
<TextBox Name="txtUserDisable" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="500" TextWrapping="Wrap" Margin="220,100,0,0" FontSize="14"/>
<Button Name="btDisable" Content="Click to Disable" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="900,95,0,0" FontSize="12" FontWeight="Bold"/>
<TextBox Name="txtDisable" HorizontalAlignment="Left" VerticalAlignment="Top" Width="1460" Height="284" Margin="10,200,0,0" FontWeight="Bold" FontSize="14" TextWrapping="Wrap" />
</Grid></TabItem>
</TabControl>
</Grid>
</Window>
"@
$Reader = (New-Object System.Xml.XmlNodeReader $xaml)
$UserDisable = [Windows.Markup.XamlReader]::Load($Reader)
$UserDisable.FindName
$xaml.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | %{Set-Variable -Name ($_.Name) -Value $UserDisable.FindName($_.Name)}
$btDisable.add_Click({
try{
Disable-ADAccount -identity $txtUserDisable.Text
$txtDisable.Text = Write-Output User $txtUserDisable.Text is Disabled.
$samAccountNameDisabled = $txtUserDisable.Text
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
User account $samAccountNameDisabled Disabled
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 0 -EntryType information
}catch{
if ($_.Exception.Message -eq "insufficient access rights to perform the operation"){
$txtDisable.Text = Write-Host "User account Disable failed: insufficient access rights to perform the operation"}}
})
$UserDisable.SHowDialog()
$UserDisable.Close()
})
$form.btUpdateUser.add_Click({
[XML]$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Width="1530" Height="600">
<Grid Background="#3f52c2">
<TabControl Margin="10,6,16,23"><TabItem Header="General "><Grid Background="#e5efff">
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="First Name:" Margin="15,24,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtFirstName}"/>
<TextBox Name="txtFirstName" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="111,25,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Initials:" Margin="500,24,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtInitials}"/>
<TextBox Name="txtInitials" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="100" TextWrapping="Wrap" Margin="600,25,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Last Name:" Margin="940,24,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtLastName}"/>
<TextBox Name="txtLastName" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="1020,25,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Display Name:" Margin="15,80,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtDisplayName}"/>
<TextBox Name="txtDisplayName" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="111,80,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Description:" Margin="500,80,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtDescription}"/>
<TextBox Name="txtDescription" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="600,80,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Office:" Margin="940,80,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtOffice}"/>
<TextBox Name="txtOffice" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="1020,80,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Email:" Margin="15,135,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtEmail}"/>
<TextBox Name="txtEmail" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="111,135,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Telephones:" Margin="500,135,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtTelephones}"/>
<TextBox Name="txtTelephones" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="600,135,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="WebPage:" Margin="940,135,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtWebPage}"/>
<TextBox Name="txtWebPage" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="1020,135,0,0" FontSize="14"/>
<Button Name="btGeneral" Content="Update" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1320,400,0,0" FontSize="12" FontWeight="Bold"/>
<!-- <TextBox Name="txtGeneratePassword" HorizontalAlignment="Left" VerticalAlignment="Top" Width="1460" Height="284" Margin="10,200,0,0" FontSize="14" /> -->
</Grid></TabItem>
<TabItem Header="Address"><Grid Background="#e5efff">
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Street:" Margin="15,24,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtStreet}"/>
<TextBox Name="txtStreet" HorizontalAlignment="Left" VerticalAlignment="Top" Height="100" Width="300" TextWrapping="Wrap" Margin="300,25,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="P.O.Box:" Margin="15,150,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtPOBox}"/>
<TextBox Name="txtPOBox" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="300,150,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="City:" Margin="15,215,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtPOBox}"/>
<TextBox Name="txtCity" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="300,215,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="State/Province:" Margin="15,280,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtState}"/>
<TextBox Name="txtState" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="300,280,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Zip/Postal Code:" Margin="15,340,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtZip}"/>
<TextBox Name="txtZip" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="300,340,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Country/Region:" Margin="15,400,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtCountry}"/>
<TextBox Name="txtCountry" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="300,400,0,0" FontSize="14"/>
<Button Name="btAddress" Content="Update" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1320,400,0,0" FontSize="12" FontWeight="Bold"/>
</Grid></TabItem>
<TabItem Header="Telephones"><Grid Background="#e5efff">
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Home:" Margin="15,24,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtHome}"/>
<TextBox Name="txtHome" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="300,25,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Pager:" Margin="15,90,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtPager}"/>
<TextBox Name="txtPager" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="300,90,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Mobile:" Margin="15,155,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtMobile}"/>
<TextBox Name="txtMobile" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="300,155,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Fax:" Margin="15,220,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtFax}"/>
<TextBox Name="txtFax" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="300,220,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="IP Phone:" Margin="15,285,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtIPPhone}"/>
<TextBox Name="txtIPPhone" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="300,285,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Notes:" Margin="15,350,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtCountry}"/>
<TextBox Name="txtNotes" HorizontalAlignment="Left" VerticalAlignment="Top" Height="100" Width="300" TextWrapping="Wrap" Margin="300,350,0,0" FontSize="14"/>
<Button Name="btTelephones" Content="Update" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1320,400,0,0" FontSize="12" FontWeight="Bold"/>
</Grid></TabItem>
<TabItem Header="Orginization"><Grid Background="#e5efff">
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Job Title:" Margin="15,24,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtJobTitle}"/>
<TextBox Name="txtJobTitle" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="300,25,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Department:" Margin="15,90,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtDepartment}"/>
<TextBox Name="txtDepartment" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="300,90,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Company:" Margin="15,155,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtCompany}"/>
<TextBox Name="txtCompany" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="300,155,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Manager Name:" Margin="15,220,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtManagerName}"/>
<TextBox Name="txtManagerName" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="300,220,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Direct Reports:" Margin="15,285,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtDirectReports}" />
<TextBox Name="txtDirectReports" HorizontalAlignment="Left" VerticalAlignment="Top" Height="100" Width="300" TextWrapping="Wrap" Margin="300,285,0,0" FontSize="14" IsReadOnly="True" />
<Button Name="btOrginization" Content="Update" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1320,400,0,0" FontSize="12" FontWeight="Bold"/>
</Grid></TabItem>
<TabItem Header="Attributes"><Grid Background="#e5efff">
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Proxy Address:" Margin="15,24,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtProxyAddress}"/>
<TextBox Name="txtProxyAddress" HorizontalAlignment="Left" VerticalAlignment="Top" Height="100" Width="300" TextWrapping="Wrap" Margin="300,25,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Employee ID:" Margin="15,155,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtEmployeeID}"/>
<TextBox Name="txtEmployeeID" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="300,150,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Employee Number:" Margin="15,218,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtEmployeeNumber}"/>
<TextBox Name="txtEmployeeNumber" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="300,215,0,0" FontSize="14"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Employee Type:" Margin="15,275,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtEmployeeType}"/>
<TextBox Name="txtEmployeeType" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="300" TextWrapping="Wrap" Margin="300,280,0,0" FontSize="14"/>
<Button Name="btAttributes" Content="Update" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1320,400,0,0" FontSize="12" FontWeight="Bold"/>
</Grid></TabItem>
</TabControl>
</Grid>
</Window>
"@
$Reader = (New-Object System.Xml.XmlNodeReader $xaml)
$UpdateUserWindow = [Windows.Markup.XamlReader]::Load($Reader)
$UpdateUserWindow.FindName
$xaml.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | %{Set-Variable -Name ($_.Name) -Value $UpdateUserWindow.FindName($_.Name)}
$txtFirstName.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty GivenName
$txtInitials.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty Initials
$txtLastName.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty Surname
$txtDisplayName.Text= Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty DisplayName
$txtDescription.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty Description
$txtOffice.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty Office
$txtTelephones.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty OfficePhone
$Email = $txtEmail.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty EmailAddress
$Web = $txtWebPage.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty HomePage
$txtStreet.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty StreetAddress
$txtPOBox.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty POBox
$txtCity.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty City
$txtState.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty State
$txtZip.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty Postalcode
$txtCountry.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty Country
$txtHome.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty HomePhone
$txtPager.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty Pager
$txtMobile.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty Mobilephone
$txtFax.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty Fax
$txtIPPhone.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty IPPhone
$txtNotes.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty Info
$txtJobTitle.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty Title
$txtDepartment.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty Department
$txtCompany.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty Company
$ManagerName = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty Manager
$ManagerName2 = @($ManagerName.Split(",").Replace("CN=" , "" ))
$ManagerName3 = $ManagerName2[0]
$txtManagerName.Text = $ManagerName3
$txtProxyAddress.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty ProxyAddresses
$txtCompany2.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty Company
$txtEmployeeID.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty EmployeeID
$txtEmployeeNumber.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty EmployeeNumber
$txtEmployeeType.Text = Get-ADUser $form.txtUserName.Text -Properties * |select -ExpandProperty EmployeeType
$btGeneral.add_Click({
$name = $txtFirstName.Text
$Initials = $txtInitials.Text
$lastName = $txtLastName.Text
$DisplayName = $txtDisplayName.Text
$Description = $txtDescription.Text
$Office = $txtOffice.Text
$Tel = $txtTelephones.Text
$Email = $txtEmail.Text
$Web = $txtWebPage.Text
$ServerName = Get-PDC
If($name -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -GivenName $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -GivenName $name
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Name: $name
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($Initials -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -Initials $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -Initials $Initials
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Initials: $Initials
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($lastName -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -Surname $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -Surname $lastName
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Last name: $lastName
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($DisplayName -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -DisplayName $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -DisplayName $DisplayName
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Dispaly Name: $DisplayName
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($Description -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -Description $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -Description $Description
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Description: $Description
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($Office -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -Office $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -Office $Office
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Office Address: $Office
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($Tel -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -OfficePhone $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -OfficePhone $Tel
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Office Phone: $Tel
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($Email -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -EmailAddress $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -EmailAddress $Email
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Email Address: $Email
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($Web -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -HomePage $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -HomePage $Web
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Web Page: $Web
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
})
$btAddress.add_Click({
$Street = $txtStreet.Text
$POBox = $txtPOBox.Text
$City = $txtCity.Text
$State = $txtState.Text
$Zip = $txtZip.Text
$Country = $txtCountry.Text
$ServerName = Get-PDC
If($Street -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -StreetAddress $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -StreetAddress $Street
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Street Info: $Street
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($POBox -eq ""){Set-Aduser $$form.txtUserName.Text -Server $ServerName -POBox $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -POBox $POBox
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated POBox: $POBox
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($City -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -City $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -City $City
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated City: $City
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($State -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -State $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -State $State
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated State: $State
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($Zip -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -Postalcode $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -Postalcode $Zip
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Zip Code: $Zip
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($Country -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -Country $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -Country $Country
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Country: $Country
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
})
$btTelephones.add_Click({
$HomePhone = $txtHome.Text
$Pager = $txtPager.Text
$Mobilephone = $txtMobile.Text
$Fax = $txtFax.Text
$IPPhone= $txtIPPhone.Text
$Notes = $txtNotes.Text
$ServerName = Get-PDC
If($HomePhone -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -HomePhone $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -HomePhone $HomePhone
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Home Phone: $HomePhone
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($Pager -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -clear Pager}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -Replace @{Pager = $Pager}
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Pager: $Pager
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($Mobilephone -eq ""){Set-Aduser $textbox1.Text -Server $ServerName -Mobilephone $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -Mobilephone $Mobilephone
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Mobile Number: $Mobilephone
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($Fax -eq ""){Set-Aduser $form.txtUserName.Text -Server $Fax -Fax $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -Fax $Fax
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Fax: $Fax
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($IPPhone -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -clear IPPhone }Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -Replace @{IPPhone =$IPPhone}
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated IP Phone: $IPPhone
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($Notes -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -clear Info }Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -Replace @{Info = $Notes}
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Notes: $Notes
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
})
$btOrginization.add_Click({
$Job = $txtJobTitle.Text
$Department = $txtDepartment.Text
$Company = $txtCompany.Text
$Manager = $ManagerName3
$ServerName = Get-PDC
If($Job -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -Title $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -Title $Job
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Job: $Job
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($Department -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -Department Pager}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -Department $Department
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Department: $Department
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($Company -eq ""){Set-Aduser $textbox1.Text -Server $ServerName -Company $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -Company $Company
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Company: $Company
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($Manager -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -Manager $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -Manager $txtManagerName.Text
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Manager: $Manager
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
})
$btAttributes.add_Click({
$Proxy = $txtProxyAddress.Text
$EmployeeID = $txtEmployeeID.Text
$EmployeeNumber = $txtEmployeeNumber.Text
$EmployeeType = $txtEmployeeType.Text
$ServerName = Get-PDC
If($Proxy -eq ""){ Set-Aduser $form.txtUserName.Text -Server $ServerName -Replace @{proxyAddresses=$Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -Replace @{proxyAddresses=$Proxy}
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Proxy Address: $Proxy
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($EmployeeID -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -EmployeeID $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -EmployeeID $EmployeeID
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated EmployeeID: $EmployeeID
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($EmployeeNumber -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -EmployeeNumber $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -EmployeeNumber $EmployeeNumber
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated EmployeeNumber: $EmployeeNumber
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}
If($EmployeeType -eq ""){Set-Aduser $form.txtUserName.Text -Server $ServerName -EmployeeType $Null}Else{
Set-Aduser $form.txtUserName.Text -Server $ServerName -Replace @{employeeType = $EmployeeType}
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Updated Employee Type: $EmployeeType
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
}}
})
$UpdateUserWindow.SHowDialog()
$UpdateUserWindow.Close()
})
$form.btExport.add_Click({
$FilePath = Get-folder
$SaveFile = "Export.csv"
$form.dgFindUsers.Items | Export-Csv $FilePath\$SaveFile -NoTypeInformation
})
####################### TAB 2 Code Below ########################
$form.txtUserName2.Add_TextChanged({
$form.txtFullName.Text = $form.txtUserName2.Text
$form.txtUserLogonName.Text = $form.txtUserName2.Text
})
$form.txtLastName.Add_TextChanged({
$form.txtFullName.Text = $form.txtUserName2.Text + " " + $form.txtLastName.Text
$form.txtUserLogonName.Text = $form.txtUserName2.Text + '.'+ $form.txtLastName.Text
})
#$UPN = @((get-adforest).UPNSuffixes)
#$UPN = $UPN | ForEach-Object {"@$_"}
$form.txtPreLogonName.Text = "VT\" # Change User Logonname as per AD domain.
$UPN = @("@vtechie.co.in","@vt.co.in") # Change UPN as per need
$form.cbUserLogonName.ItemsSource = $UPN
$form.btGeneratePwd.Add_Click({
$Psswd = [System.Web.Security.Membership]::GeneratePassword(14,4) # Set Password length(14) as per AD domain policy
$form.txtGeneratePwd.Text = $Psswd
})
# Change OU names as per Organization AD structure
$OuArray2 = @(Get-ADOrganizationalUnit -LDAPFilter '(name=*)' -SearchBase 'OU=Users,DC=vtechie,DC=co,DC=in' -SearchScope Subtree -Properties Name |select -ExpandProperty DistinguishedName -Unique |Sort-Object)
$OuArray3 = @(Get-ADOrganizationalUnit -LDAPFilter '(name=*)' -SearchBase 'OU=Security Groups,DC=vtechie,DC=co,DC=in' -SearchScope Subtree -Properties Name |select -ExpandProperty DistinguishedName -Unique |Sort-Object)
$OuArray4 = @(Get-ADOrganizationalUnit -LDAPFilter '(name=*)' -SearchBase 'OU=Privilege_Users,DC=vtechie,DC=co,DC=in' -SearchScope Subtree -Properties Name |select -ExpandProperty DistinguishedName -Unique |Sort-Object)
$OuArray += $OuArray2
$OuArray += $OuArray3
$OuArray += $OuArray4
$OuArray |Sort-Object
$form.cbOU.ItemsSource = $OuArray
$form.btCreate.Add_Click({
$form.txtUserCreation.Clear()
Create-User
$samAccountNameCreate =$form.txtPreLogonName2.Text
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
New account $samAccountNameCreate created
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
})
######################### TAB 3 Code Below ###############################
$form.btFindGroup.Add_Click({
$server = Get-PDC
$ADGroupObjName =$form.txtFindGroup.Text
$GroupObj = Get-ADGroup -Server $server -Filter * -Properties samAccountName, GroupScope, GroupCategory, DistinguishedName | Where-Object { ($_.samAccountName -eq $ADGroupObjName) -or ($_.Name -match $ADGroupObjName)} |Select samAccountName, GroupScope, GroupCategory, DistinguishedName
$GroupObjName = New-Object System.collections.ArrayList
$GroupObjName.AddRange(@($GroupObj))
$form.dgFindGroupName.Visibility = "Visible"
$form.txtDataOutBox.Visibility = "Hidden"
$form.dgFindGroupName.ItemsSource = $GroupObjName
})
$form.btUpdateGroup.Add_Click({
[XML]$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Width="1200" Height="600"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" >
<Grid Background="#3f52c2">
<TabControl Margin="10,6,16,23"><TabItem Header="Group Members Add"><Grid Background="#e5efff">
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Enter GroupName :" Margin="15,24,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtGroupName}"/>
<TextBox Name="txtGroupName" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="500" TextWrapping="Wrap" Margin="220,24,0,0" FontSize="14"/>
<Button Name="btShowMembers" Content="Show Members" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="800,20,0,0" FontSize="12" FontWeight="Bold"/>
<Button Name="btAddMembers" Content="Add Members" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1000,20,0,0" FontSize="12" FontWeight="Bold"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Enter Member Names :" Margin="15,80,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtAddMembers}" />
<TextBox Name="txtAddMembers" HorizontalAlignment="Left" VerticalAlignment="Top" Width="500" Height="200" Margin="220,80,0,0" FontWeight="Normal" FontSize="14" TextWrapping="Wrap" AcceptsReturn="True"/>
<DataGrid Name="dgShowGroupMembers" HorizontalAlignment="Left" VerticalAlignment="Top" Width="1120" Height="200" Margin="10,300,0,0" AutoGenerateColumns="True" ColumnWidth="*" IsReadOnly="True" >
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontWeight" Value="Bold"/>
</Style>
</DataGrid.ColumnHeaderStyle>
</DataGrid>
<TextBox Name="txtDataOutBox2" HorizontalAlignment="Left" VerticalAlignment="Top" Width="1120" Height="200" Margin="10,300,0,0" FontWeight="Bold" FontSize="14" TextWrapping="Wrap" Visibility="Collapsed" />
</Grid></TabItem>
<TabItem Header="Group Members Remove"><Grid Background="#e5efff">
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Enter GroupName :" Margin="15,24,0,0" FontWeight="Bold" FontSize="12" Target="{Binding ElementName=txtGroupNameRemove}"/>
<TextBox Name="txtGroupNameRemove" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="500" TextWrapping="Wrap" Margin="220,24,0,0" FontSize="14"/>
<Button Name="btViewMembers" Content="View" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="800,440,0,0" FontSize="12" FontWeight="Bold"/>
<Button Name="btRemoveMembers" Content="Remove" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="100" Margin="1020,440,0,0" FontSize="12" FontWeight="Bold"/>
<TextBox Name="txtDataOutBox3" HorizontalAlignment="Left" VerticalAlignment="Top" Width="500" Height="350" Margin="220,80,0,0" FontWeight="Bold" FontSize="14" TextWrapping="Wrap" Visibility="Collapsed" />
<DataGrid Name="dgShowGroupMembers2" HorizontalAlignment="Left" VerticalAlignment="Top" Width="500" Height="350" Margin="220,80,0,0" AutoGenerateColumns="True" ColumnWidth="*" IsReadOnly="True" >
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontWeight" Value="Bold"/>
</Style>
</DataGrid.ColumnHeaderStyle>
</DataGrid>
</Grid></TabItem>
</TabControl>
</Grid>
</Window>
"@
$Reader = (New-Object System.Xml.XmlNodeReader $xaml)
$UpdateGroupMembers = [Windows.Markup.XamlReader]::Load($Reader)
$UpdateGroupMembers.FindName
$xaml.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | %{Set-Variable -Name ($_.Name) -Value $UpdateGroupMembers.FindName($_.Name)}
$btShowMembers.Add_Click({
$dgShowGroupMembers.Visibility = "Visible"
$txtDataOutBox2.Visibility = "Hidden"
$GrpName = $txtGroupName.text
try{
$GrpMembers = Get-ADGroupMember $GrpName |select Name,samAccountName,ObjectClass
$dgShowGroupMembers.ItemsSource = @($GrpMembers)
}Catch{
$dgShowGroupMembers.Visibility = "Hidden"
$txtDataOutBox2.Visibility = "Visible"
$txtDataOutBox2.Clear()
$txtDataOutBox2.text= Write-Output Cannot find an object with identity: $txtGroupName.text }
})
$btAddMembers.Add_Click({
$dgShowGroupMembers.Visibility = "Hidden"
$txtDataOutBox2.Visibility = "Visible"
$GrpName2 = $txtGroupName.text
$Members = @($txtAddMembers.Text)
$Member = $Members.Split("`r`n", [StringSplitOptions]::RemoveEmptyEntries)
try{
foreach($grpMember in $Member){
Add-ADGroupMember $GrpName2 -Members $grpMember
$txtDataOutBox2.text = Write-Output $grpMember added to group $GrpName2 `r`n
$samAccountNameAddMember = $grpMember
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
New member $samAccountNameAddMember added to $GrpName2
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 2 -EntryType information
}
}Catch{
$txtDataOutBox2.text= Write-Output Cannot find an object with identity: $txtAddMembers.Text
}
})
$btViewMembers.Add_Click({
$dgShowGroupMembers2.Visibility = "Visible"
$txtDataOutBox3.Visibility = "Hidden"
try{
$GrpName = $txtGroupNameRemove.text
$GrpMembers = Get-ADGroupMember $GrpName |select Name,samAccountName
$dgShowGroupMembers2.ItemsSource = @($GrpMembers)
}Catch{
$dgShowGroupMembers2.Visibility = "Hidden"
$txtDataOutBox3.Visibility = "Visible"
$txtDataOutBox3.Text = Write-Output Cannot find an object with identity: $GrpName
}
})
$btRemoveMembers.Add_Click({
$Array = @($dgShowGroupMembers2.SelectedItems.samAccountName)
try{
foreach($user in $Array){
Remove-ADGroupMember $txtGroupNameRemove.text -Members $user -Confirm:$false}
$GrpName = $txtGroupNameRemove.text
$GrpMembers = Get-ADGroupMember $GrpName |select Name,samAccountName
$dgShowGroupMembers2.ItemsSource = @($GrpMembers)
$samAccountNameRemoveMember = $user
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
Member $samAccountNameRemoveMember removed from group $GrpName
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 3 -EntryType information
}catch{
$dgShowGroupMembers2.Visibility = "Hidden"
$txtDataOutBox3.Visibility = "Visible"
$txtDataOutBox3.Text = Write-Output Members not selected in group $txtGroupNameRemove.text}
})
$UpdateGroupMembers.ShowDialog()
$UpdateGroupMembers.Close()
})
$form.cbOUPath.ItemsSource = $OuArray
$form.btCreateGroup.Add_Click({
$gpName = $form.txtGroupName.Text
$samName = $form.txtGroupNamePre2000.Text
$displayName = $form.txtGroupName.Text
$OU = $form.cbOUPath.Text
$rdbDomainLocal = $form.rdbDomainLocal.IsChecked
$rdbGlobal = $form.rdbGlobal.IsChecked
$rdbUniversal = $form.rdbUniversal.IsChecked
$rdbSecurity = $form.rdbSecurity.IsChecked
$rdbDistribution = $form.rdbDistribution.IsChecked
$form.dgFindGroupName.Visibility = "Hidden"
$form.txtDataOutBox.Visibility = "Visible"
$ServerName = Get-PDC
#New-ADGroup -Name $gpName -SamAccountName $samName -GroupScope DomainLocal -GroupCategory Security -DisplayName $displayName -Path $form.cbOUPath.Text
$AdGroupName = (Get-ADGroup $samName -Server $ServerName |Select SamAccountName -ErrorAction SilentlyContinue)
try{
If ($AdGroupName){$form.txtDataOutBox.Text = Write-Output The Specified Group $samName already exists. Try using another Group Name}Else{
If (($rdbDomainLocal) -and ($rdbSecurity) -and ($OU -eq "")){$form.txtDataOutBox.Text = Write-Output Error: OU path cannot be blank}
If (($rdbDomainLocal) -and ($rdbSecurity) -and ($OU -ne "")){New-ADGroup -Server $ServerName -Name $gpName -SamAccountName $samName -GroupScope DomainLocal -GroupCategory Security -DisplayName $displayName -Path $OU
$form.txtDataOutBox.Text = Write-Output Created Group $samName in OU $OU }
If (($rdbDomainLocal) -and ($rdbDistribution) -and ($OU -eq "")){$form.txtDataOutBox.Text = Write-Output Error: OU path cannot be blank}
If (($rdbDomainLocal) -and ($rdbDistribution) -and ($OU -ne "")){New-ADGroup -Server $ServerName -Name $gpName -SamAccountName $samName -GroupScope DomainLocal -GroupCategory Distribution -DisplayName $displayName -Path $OU
$form.txtDataOutBox.Text = Write-Output Created Group $samName in OU $OU }
If (($rdbGlobal) -and ($rdbSecurity) -and ($OU -eq "")){$form.txtDataOutBox.Text = Write-Output Error: OU path cannot be blank}
If (($rdbGlobal) -and ($rdbSecurity) -and ($OU -ne "")){New-ADGroup -Server $ServerName -Name $gpName -SamAccountName $samName -GroupScope Global -GroupCategory Security -DisplayName $displayName -Path $OU
$form.txtDataOutBox.Text = Write-Output Created Group $samName in OU $OU }
If (($rdbGlobal) -and ($rdbDistribution) -and ($OU -eq "")){$form.txtDataOutBox.Text = Write-Output Error: OU path cannot be blank}
If (($rdbGlobal) -and ($rdbDistribution) -and ($OU -ne "")){New-ADGroup -Server $ServerName -Name $gpName -SamAccountName $samName -GroupScope Global -GroupCategory Distribution -DisplayName $displayName -Path $OU
$form.txtDataOutBox.Text = Write-Output Created Group $samName in OU $OU }
If (($rdbUniversal) -and ($rdbSecurity) -and ($OU -eq "")){$form.txtDataOutBox.Text = Write-Output Error: OU path cannot be blank}
If (($rdbUniversal) -and ($rdbSecurity) -and ($OU -ne "")){New-ADGroup -Server $ServerName -Name $gpName -SamAccountName $samName -GroupScope Universal -GroupCategory Security -DisplayName $displayName -Path $OU
$form.txtDataOutBox.Text = Write-Output Created Group $samName in OU $OU }
If (($rdbUniversal) -and ($rdbDistribution) -and ($OU -eq "")){$form.txtDataOutBox.Text = Write-Output Error: OU path cannot be blank}
If (($rdbUniversal) -and ($rdbDistribution) -and ($OU -ne "")){New-ADGroup -Server $ServerName -Name $gpName -SamAccountName $samName -GroupScope Universal -GroupCategory Distribution -DisplayName $displayName -Path $OU
$form.txtDataOutBox.Text = Write-Output Created Group $samName in OU $OU }}
}Catch{$form.txtDataOutBox.Text = $_.Exception.Message}
$samAccountNameGrpCreate = $form.txtGroupNamePre2000.Text
$Who = whoami
$Message = "
Account Name: $who
Category: User Management
Subcategory: Account Management
New group $samAccountNameGrpCreate is created
"
Write-EventLog -LogName UserManagment -Source script -Message $Message -EventId 1 -EntryType information
#>
})
##########################################
$EventLog = Get-EventLog -LogName UserManagment
If ($EventLog){ Write-host UserManagment eventlog exists
}Else{
New-EventLog -LogName UserManagment -Source Script }
$Window.ShowDialog()
$Window.Close()
```
Explanation of PowerShell code
Finding users and computers: This tab is used to find existing uses and computers in Activity directory. You can also use this tab to Update user information, Reset user password, Unlock user account, Enable / Disable user account.

Finding using and computer in Active directory Creating a User: You can use User Creation tab to create new users in Active directory.

Creating new users Creating a Group and Adding new members to Groups: The Group Modification tab is used to create new Groups in Activity directory and adding / removing members from existing groups.

Group creation and Modification
Additional User Management Features
To enhance functionality, you can add more option like Attribute Editor.
Finally step
Use an third part tool to convert the XAML and PowerShell script into a single executable file which can be provided to L1 engineers.
Testing the Tool
Once you have completed coding your GUI and backend functionality, it's time for testing:
Enter a username in the TextBox.
Click the "Create User" button and check if the user is added to the Active Directory.
Test the modifications and deactivation functions similarly to ensure they work as intended.
Always use real usernames while adhering to your organization’s security policies during this phase.
Considerations for Production Deployment
Before you roll out the tool to your L1 engineers, keep these points in mind:
User Role Restrictions: Make sure the accounts running this application have limited permissions to prevent unauthorized changes.
Testing: Rigorously test different scenarios to guarantee reliability.
Documentation: Prepare clear usage instructions for L1 engineers, covering common troubleshooting tips.
Wrapping Up
Creating a fully functional Active Directory user management tool using PowerShell and XAML provides a practical solution for organizations that want to empower L1 engineers without overwhelming them with the complexities of AD management. By combining a graphical user interface with PowerShell's capabilities, organizations can minimize accidental changes, ensuring user roles are managed securely.
This guide offers a detailed view of building the tool from scratch, enabling you to create custom features tailored to your needs. Thorough testing and user training remain critical before introducing any new tool.
By following this process, you're not just building a tool; you are enhancing operational efficiency and securing your Active Directory management practices.

Comments