Last active
May 21, 2018 17:15
-
-
Save kyleericson/a92c7be0192fca415c99d014915e37e7 to your computer and use it in GitHub Desktop.
AD Creation Tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$WPFsearchad.Add_Click({Get-ADUser -Filter * -Properties Name, department, SamAccountName, mail, distinguishedname, description, memberof | Where {$_.enabled } | select -Property Name, department, SamAccountName, mail, distinguishedname, description, memberof | Out-GridView -passthru}) | |
function Get-FormFields(){ | |
$User = Get-AdUser $WPFsearchad.SamAccountName | |
$new_password = 'acemfg1' | |
$User = Get-AdUser $WPFsearchad | |
$DN = $User.distinguishedName | |
$OldUser = [ADSI]"LDAP://$DN" | |
$Parent = $OldUser.Parent | |
$OU = [ADSI]$Parent | |
$OUDN = $OU.distinguishedName | |
$HashArguments = | |
@{ Name = $WPFnewuname.Text; | |
GivenName=$WPFnewfname.Text; | |
SurName = $WPFnewlname.Text; | |
DisplayName = "$WPFnewfname.Text $WPFnewlname.Text"; | |
AccountPassword= $new_password; | |
Company = "Ace Manufacturing"; | |
Department = $WPFsearchad.department; | |
Description = $WPFsearchad.Description; | |
SamAccountName = $WPFsearchad.SamAccountName; | |
Distinguishedname = $WPFsearchad.distinguishedname; | |
memberof = $WPFsearchad.memberof; | |
Path = "$OUDN" | |
Enabled = $True | |
} | |
} | |
$HashArguments | |
#Get-ADUser $NewUser -Properties userPrincipalName | foreach { Set-ADUser $_ -UserPrincipalName "$($_.samaccountname)@truemfg.com"} | |
#Get-ADPrincipalGroupMembership $User | foreach { Add-ADPrincipalGroupMembership -identity $NewUser -MemberOf $_.samaccountname } -ErrorAction Ignore | |
$WPFcreateuser.Add_Click({ | |
#Resolve Form Settings | |
$hash = Get-FormFields | |
New-ADUser @hash -PassThru | |
$Form.Close()}) | |
write-host "To show the form, run the following" -ForegroundColor Cyan | |
$Form.ShowDialog() | out-null | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment