[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$Form = New-Object System.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(800,500)
############################################## Start functions
function Return-DropDown {
$DropDown.Text = $DropDown.Text -replace ",",""
$name = ph $DropDown.Text #-return name
$User_account = ph $DropDown.Text -return User_account
$supervisor = ph $DropDown.Text -return supervisor
$type = ph $DropDown.Text -return type
$outputbox.Text = $name
}
function Mail {
$UserName=$InputBox.text
import-module activedirectory
import-module activedirectory
# ADSI Bind with current process credentials
$forestName = ([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Name
$ADsPath = [ADSI]"GC://$forestName"
$Rech = new-object System.DirectoryServices.DirectorySearcher($ADsPath)
$rc = $Rech.filter = "(&(objectCategory=person)(objectCategory=User)(SamAccountName=$UserName))"
$rc = $Rech.SearchScope = "subtree"
$rc = $Rech.PropertiesToLoad.Add("distinguishedName") | out-null
$rc = $Rech.PropertiesToLoad.Add("sAMAccountName");
$rc = $Rech.PropertiesToLoad.Add("CanonicalName");
$rc = $Rech.PropertiesToLoad.Add("mail");
$rc = $Rech.PropertiesToLoad.Add("name");
$rc = $Rech.PropertiesToLoad.Add("employeenumber");
$rc = $Rech.PropertiesToLoad.Add("displayname");
$rc = $Rech.PropertiesToLoad.Add("l");
$rc = $Rech.PropertiesToLoad.Add("title");
$rc = $Rech.PropertiesToLoad.Add("department");
$rc = $Rech.PropertiesToLoad.Add("distinguishedname");
$rc = $Rech.PropertiesToLoad.Add("company");
$rc = $Rech.PropertiesToLoad.Add("objectpath");
$rc = $Rech.PropertiesToLoad.Add("Manager");
$rc = $Rech.PropertiesToLoad.Add("physicalDeliveryOfficeName"); # Your attribute
$liste = $Rech.findall()
$distinguishedname = $liste.Properties.item("distinguishedname")
$CanonicalName = $liste.Properties.item("CanonicalName")
$mail = $liste.Properties.item("mail")
$name = $liste.Properties.item("name")
$Manager = $liste.Properties.item("Manager")
$employeenumber = $liste.Properties.item("employeenumber")
$displayname = $liste.Properties.item("displayname")
$UserId = $liste.Properties.item("samaccountname")
$location = $liste.Properties.item("l")
$title = $liste.Properties.item("title")
$department = $liste.Properties.item("department")
$Company = $liste.Properties.item("company")
$objectpath = $liste.Properties.item("objectpath")
$manager
$search = new-object System.DirectoryServices.DirectorySearcher($ADsPath)
$RCManager = $search.filter = "(&(objectCategory=person)(objectCategory=User)(distinguishedname=$manager))"
$RCM = $search.PropertiesToLoad.Add("givenname");
$RCM = $search.PropertiesToLoad.Add("Displayname");
$RCM = $search.PropertiesToLoad.Add("mail");
$Manliste = $search.findall()
$Mangivennamee = $Manliste.Properties.item("givenname")
$ManDisplaynamer = $Manliste.Properties.item("Displayname")
$ManMail = $Manliste.Properties.item("mail")
#End Manager Data, GiveName
$content = "Hi $Mangivennamee , `n
YOU ARE RECEIVING THIS MESSAGE BECAUSE: `n
Computer account access was provisioned as requested for the new hire listed below: `n
Email = $mail `n
Windows = $CanonicalName `n
UNIX `n
WHAT YOU NEED TO KNOW: `n
• Your Info Here !!
WHAT YOU NEED TO DO:
• Your Info Here!!
New Joiner Details :
========================
Employee ID : $employeenumber
Name : $Displayname
Mail : $mail
User ID : $UserID
Location : $location
Title : $title
Department : $Department
Supervisor : $ManDisplaynamer
Affiliation : $company
"
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = $ManMail
$body = $CanonicalName
$body = $subject + $mail
$Mail.Subject = "New Hire Account Details $Displayname"
$Mail.Body = $content
$mail.display()
}
function Refresh {
$InputBox.Clear()
$Form.Refresh()
$outputBox.Clear()
}
function ADInfo {
$UserName=$InputBox.text
import-module activedirectory
# ADSI Bind with current process credentials
#$dn = [adsi] "LDAP://192.168.30.200:389/dc=dom,dc=fr"
$forestName = ([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Name
$ADsPath = [ADSI]"GC://$forestName"
$Rech = new-object System.DirectoryServices.DirectorySearcher($ADsPath)
$rc = $Rech.filter = "(&(objectCategory=person)(objectCategory=User)(SamAccountName=$UserName))"
$rc = $Rech.SearchScope = "subtree"
$rc = $Rech.PropertiesToLoad.Add("distinguishedName") | out-null
$rc = $Rech.PropertiesToLoad.Add("sAMAccountName");
$rc = $Rech.PropertiesToLoad.Add("CanonicalName");
$rc = $Rech.PropertiesToLoad.Add("mail");
$rc = $Rech.PropertiesToLoad.Add("name");
$rc = $Rech.PropertiesToLoad.Add("employeenumber");
$rc = $Rech.PropertiesToLoad.Add("l");
$rc = $Rech.PropertiesToLoad.Add("title");
$rc = $Rech.PropertiesToLoad.Add("department");
$rc = $Rech.PropertiesToLoad.Add("distinguishedname");
$rc = $Rech.PropertiesToLoad.Add("company");
$rc = $Rech.PropertiesToLoad.Add("objectpath");
$rc = $Rech.PropertiesToLoad.Add("Manager");
$rc = $Rech.PropertiesToLoad.Add("physicalDeliveryOfficeName"); # Your attribute
$liste = $Rech.findall()
$distinguishedname = $liste.Properties.item("distinguishedname")
$CanonicalName = $liste.Properties.item("CanonicalName")
$mail = $liste.Properties.item("mail")
$name = $liste.Properties.item("name")
$Manager = $liste.Properties.item("Manager")
$employeenumber = $liste.Properties.item("employeenumber")
$displayname = $liste.Properties.item("displayname")
$UserId = $liste.Properties.item("samaccountname")
$location = $liste.Properties.item("l")
$title = $liste.Properties.item("title")
$department = $liste.Properties.item("department")
$Company = $liste.Properties.item("company")
$objectpath = $liste.Properties.item("objectpath")
$manager
$search = new-object System.DirectoryServices.DirectorySearcher($ADsPath)
$RCManager = $search.filter = "(&(objectCategory=person)(objectCategory=User)(distinguishedname=$manager))"
$RCM = $search.PropertiesToLoad.Add("givenname");
$RCM = $search.PropertiesToLoad.Add("Displayname");
$Manliste = $search.findall()
$Mangivennamee = $Manliste.Properties.item("givenname")
$ManDisplaynamer = $Manliste.Properties.item("Displayname")
$ManDisplaynamer
$Mangivennamee
$outputBox.text = $CanonicalName
} #end ADINFO
############################################## end functions
############################################## Start text fields
$InputBox = New-Object System.Windows.Forms.TextBox
$InputBox.Location = New-Object System.Drawing.Size(20,50)
$InputBox.Size = New-Object System.Drawing.Size(150,20)
$Form.Controls.Add($InputBox)
$outputBox = New-Object System.Windows.Forms.TextBox
$outputBox.Location = New-Object System.Drawing.Size(10,150)
$outputBox.Size = New-Object System.Drawing.Size(200,200)
$outputBox.MultiLine = $True
$outputBox.ScrollBars = "Vertical"
$Form.Controls.Add($outputBox)
############################################## end text fields
############################################## Start buttons
$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Size(200,50)
$Button.Size = New-Object System.Drawing.Size(90,20)
$Button.Text = "Get AD Info"
$Button.Add_Click({ADInfo})
$Form.Controls.Add($Button)
############################################## end buttons
$Button2 = New-Object System.Windows.Forms.Button
$Button2.Location = New-Object System.Drawing.Size(500,50)
$Button2.Size = New-Object System.Drawing.Size(90,20)
$Button2.Text = "Refresh"
$Button2.Add_Click({Refresh})
$Form.Controls.Add($Button2)
$Button3 = New-Object System.Windows.Forms.Button
$Button3.Location = New-Object System.Drawing.Size(225,375)
$Button3.Size = New-Object System.Drawing.Size(90,20)
$Button3.Text = "Launch Mail"
$Button3.Add_Click({Mail})
$Form.Controls.Add($Button3)
############################################## Start DropDown
$DropDown = new-object System.Windows.Forms.ComboBox
$DropDown.Location = new-object System.Drawing.Size(20,100)
$DropDown.Size = new-object System.Drawing.Size(130,30)
ForEach ($Item in $DropDownArray) {
$DropDown.Items.Add($Item)
}
$Form.Controls.Add($DropDown)
$DropDownLabel = new-object System.Windows.Forms.Label
$DropDownLabel.Location = new-object System.Drawing.Size(10,10)
$DropDownLabel.size = new-object System.Drawing.Size(100,20)
$DropDownLabel.Text = "Items"
$Form.Controls.Add($DropDownLabel)
$Button = new-object System.Windows.Forms.Button
$Button.Location = new-object System.Drawing.Size(200,100)
$Button.Size = new-object System.Drawing.Size(100,20)
$Button.Text = "Select an UID"
$Button.Add_Click({Return-DropDown})
$form.Controls.Add($Button)
$Form.Add_Shown({$Form.Activate()})
$Form.ShowDialog()
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$Form = New-Object System.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(800,500)
############################################## Start functions
function Return-DropDown {
$DropDown.Text = $DropDown.Text -replace ",",""
$name = ph $DropDown.Text #-return name
$User_account = ph $DropDown.Text -return User_account
$supervisor = ph $DropDown.Text -return supervisor
$type = ph $DropDown.Text -return type
$outputbox.Text = $name
}
function Mail {
$UserName=$InputBox.text
import-module activedirectory
import-module activedirectory
# ADSI Bind with current process credentials
$forestName = ([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Name
$ADsPath = [ADSI]"GC://$forestName"
$Rech = new-object System.DirectoryServices.DirectorySearcher($ADsPath)
$rc = $Rech.filter = "(&(objectCategory=person)(objectCategory=User)(SamAccountName=$UserName))"
$rc = $Rech.SearchScope = "subtree"
$rc = $Rech.PropertiesToLoad.Add("distinguishedName") | out-null
$rc = $Rech.PropertiesToLoad.Add("sAMAccountName");
$rc = $Rech.PropertiesToLoad.Add("CanonicalName");
$rc = $Rech.PropertiesToLoad.Add("mail");
$rc = $Rech.PropertiesToLoad.Add("name");
$rc = $Rech.PropertiesToLoad.Add("employeenumber");
$rc = $Rech.PropertiesToLoad.Add("displayname");
$rc = $Rech.PropertiesToLoad.Add("l");
$rc = $Rech.PropertiesToLoad.Add("title");
$rc = $Rech.PropertiesToLoad.Add("department");
$rc = $Rech.PropertiesToLoad.Add("distinguishedname");
$rc = $Rech.PropertiesToLoad.Add("company");
$rc = $Rech.PropertiesToLoad.Add("objectpath");
$rc = $Rech.PropertiesToLoad.Add("Manager");
$rc = $Rech.PropertiesToLoad.Add("physicalDeliveryOfficeName"); # Your attribute
$liste = $Rech.findall()
$distinguishedname = $liste.Properties.item("distinguishedname")
$CanonicalName = $liste.Properties.item("CanonicalName")
$mail = $liste.Properties.item("mail")
$name = $liste.Properties.item("name")
$Manager = $liste.Properties.item("Manager")
$employeenumber = $liste.Properties.item("employeenumber")
$displayname = $liste.Properties.item("displayname")
$UserId = $liste.Properties.item("samaccountname")
$location = $liste.Properties.item("l")
$title = $liste.Properties.item("title")
$department = $liste.Properties.item("department")
$Company = $liste.Properties.item("company")
$objectpath = $liste.Properties.item("objectpath")
$manager
$search = new-object System.DirectoryServices.DirectorySearcher($ADsPath)
$RCManager = $search.filter = "(&(objectCategory=person)(objectCategory=User)(distinguishedname=$manager))"
$RCM = $search.PropertiesToLoad.Add("givenname");
$RCM = $search.PropertiesToLoad.Add("Displayname");
$RCM = $search.PropertiesToLoad.Add("mail");
$Manliste = $search.findall()
$Mangivennamee = $Manliste.Properties.item("givenname")
$ManDisplaynamer = $Manliste.Properties.item("Displayname")
$ManMail = $Manliste.Properties.item("mail")
#End Manager Data, GiveName
$content = "Hi $Mangivennamee , `n
YOU ARE RECEIVING THIS MESSAGE BECAUSE: `n
Computer account access was provisioned as requested for the new hire listed below: `n
Email = $mail `n
Windows = $CanonicalName `n
UNIX `n
WHAT YOU NEED TO KNOW: `n
• Your Info Here !!
WHAT YOU NEED TO DO:
• Your Info Here!!
New Joiner Details :
========================
Employee ID : $employeenumber
Name : $Displayname
Mail : $mail
User ID : $UserID
Location : $location
Title : $title
Department : $Department
Supervisor : $ManDisplaynamer
Affiliation : $company
"
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = $ManMail
$body = $CanonicalName
$body = $subject + $mail
$Mail.Subject = "New Hire Account Details $Displayname"
$Mail.Body = $content
$mail.display()
}
function Refresh {
$InputBox.Clear()
$Form.Refresh()
$outputBox.Clear()
}
function ADInfo {
$UserName=$InputBox.text
import-module activedirectory
# ADSI Bind with current process credentials
#$dn = [adsi] "LDAP://192.168.30.200:389/dc=dom,dc=fr"
$forestName = ([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Name
$ADsPath = [ADSI]"GC://$forestName"
$Rech = new-object System.DirectoryServices.DirectorySearcher($ADsPath)
$rc = $Rech.filter = "(&(objectCategory=person)(objectCategory=User)(SamAccountName=$UserName))"
$rc = $Rech.SearchScope = "subtree"
$rc = $Rech.PropertiesToLoad.Add("distinguishedName") | out-null
$rc = $Rech.PropertiesToLoad.Add("sAMAccountName");
$rc = $Rech.PropertiesToLoad.Add("CanonicalName");
$rc = $Rech.PropertiesToLoad.Add("mail");
$rc = $Rech.PropertiesToLoad.Add("name");
$rc = $Rech.PropertiesToLoad.Add("employeenumber");
$rc = $Rech.PropertiesToLoad.Add("l");
$rc = $Rech.PropertiesToLoad.Add("title");
$rc = $Rech.PropertiesToLoad.Add("department");
$rc = $Rech.PropertiesToLoad.Add("distinguishedname");
$rc = $Rech.PropertiesToLoad.Add("company");
$rc = $Rech.PropertiesToLoad.Add("objectpath");
$rc = $Rech.PropertiesToLoad.Add("Manager");
$rc = $Rech.PropertiesToLoad.Add("physicalDeliveryOfficeName"); # Your attribute
$liste = $Rech.findall()
$distinguishedname = $liste.Properties.item("distinguishedname")
$CanonicalName = $liste.Properties.item("CanonicalName")
$mail = $liste.Properties.item("mail")
$name = $liste.Properties.item("name")
$Manager = $liste.Properties.item("Manager")
$employeenumber = $liste.Properties.item("employeenumber")
$displayname = $liste.Properties.item("displayname")
$UserId = $liste.Properties.item("samaccountname")
$location = $liste.Properties.item("l")
$title = $liste.Properties.item("title")
$department = $liste.Properties.item("department")
$Company = $liste.Properties.item("company")
$objectpath = $liste.Properties.item("objectpath")
$manager
$search = new-object System.DirectoryServices.DirectorySearcher($ADsPath)
$RCManager = $search.filter = "(&(objectCategory=person)(objectCategory=User)(distinguishedname=$manager))"
$RCM = $search.PropertiesToLoad.Add("givenname");
$RCM = $search.PropertiesToLoad.Add("Displayname");
$Manliste = $search.findall()
$Mangivennamee = $Manliste.Properties.item("givenname")
$ManDisplaynamer = $Manliste.Properties.item("Displayname")
$ManDisplaynamer
$Mangivennamee
$outputBox.text = $CanonicalName
} #end ADINFO
############################################## end functions
############################################## Start text fields
$InputBox = New-Object System.Windows.Forms.TextBox
$InputBox.Location = New-Object System.Drawing.Size(20,50)
$InputBox.Size = New-Object System.Drawing.Size(150,20)
$Form.Controls.Add($InputBox)
$outputBox = New-Object System.Windows.Forms.TextBox
$outputBox.Location = New-Object System.Drawing.Size(10,150)
$outputBox.Size = New-Object System.Drawing.Size(200,200)
$outputBox.MultiLine = $True
$outputBox.ScrollBars = "Vertical"
$Form.Controls.Add($outputBox)
############################################## end text fields
############################################## Start buttons
$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Size(200,50)
$Button.Size = New-Object System.Drawing.Size(90,20)
$Button.Text = "Get AD Info"
$Button.Add_Click({ADInfo})
$Form.Controls.Add($Button)
############################################## end buttons
$Button2 = New-Object System.Windows.Forms.Button
$Button2.Location = New-Object System.Drawing.Size(500,50)
$Button2.Size = New-Object System.Drawing.Size(90,20)
$Button2.Text = "Refresh"
$Button2.Add_Click({Refresh})
$Form.Controls.Add($Button2)
$Button3 = New-Object System.Windows.Forms.Button
$Button3.Location = New-Object System.Drawing.Size(225,375)
$Button3.Size = New-Object System.Drawing.Size(90,20)
$Button3.Text = "Launch Mail"
$Button3.Add_Click({Mail})
$Form.Controls.Add($Button3)
############################################## Start DropDown
$DropDown = new-object System.Windows.Forms.ComboBox
$DropDown.Location = new-object System.Drawing.Size(20,100)
$DropDown.Size = new-object System.Drawing.Size(130,30)
ForEach ($Item in $DropDownArray) {
$DropDown.Items.Add($Item)
}
$Form.Controls.Add($DropDown)
$DropDownLabel = new-object System.Windows.Forms.Label
$DropDownLabel.Location = new-object System.Drawing.Size(10,10)
$DropDownLabel.size = new-object System.Drawing.Size(100,20)
$DropDownLabel.Text = "Items"
$Form.Controls.Add($DropDownLabel)
$Button = new-object System.Windows.Forms.Button
$Button.Location = new-object System.Drawing.Size(200,100)
$Button.Size = new-object System.Drawing.Size(100,20)
$Button.Text = "Select an UID"
$Button.Add_Click({Return-DropDown})
$form.Controls.Add($Button)
$Form.Add_Shown({$Form.Activate()})
$Form.ShowDialog()