Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $t = '[DllImport("user32.dll")] public static extern bool ShowWindow(int handle, int state);'
- add-type -name win -member $t -namespace native
- [native.win]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0)
- Add-Type -AssemblyName System.Windows.Forms
- $dir = "c:\ADUserCreator\"
- If(!(test-path $dir))
- {
- New-Item -ItemType Directory -Force -Path $dir
- }
- #VZHLED FORMULARE
- $Form = New-Object system.Windows.Forms.Form
- $Form.Text = "AD User Creator"
- $Form.TopMost = $true
- $Form.Width = 312
- $Form.Height = 330
- $Form.KeyPreview = $True
- $Form.StartPosition = "CenterScreen"
- $Maker = New-Object system.windows.Forms.Label
- $Maker.Text = "@Prihoda 2017"
- $Maker.AutoSize = $true
- $Maker.ForeColor = "#fffcfc"
- $Maker.Width = 25
- $Maker.Height = 10
- $Maker.Add_MouseHover({
- $Maker.ForeColor = "#000000"
- $Maker.Font = "Microsoft Sans Serif,10,style=Bold"
- })
- $Maker.location = new-object system.drawing.point(137,-25)
- $Maker.Font = "Microsoft Sans Serif,10"
- $Form.controls.Add($Maker)
- $GivenName = New-Object system.windows.Forms.TextBox
- $GivenName.Width = 140
- $GivenName.Height = 20
- $GivenName.location = new-object system.drawing.point(145,10)
- $GivenName.Font = "Microsoft Sans Serif,10"
- $Form.controls.Add($GivenName)
- $firstname = New-Object system.windows.Forms.Label
- $firstname.Text = "Křestní jméno"
- $firstname.AutoSize = $true
- $firstname.Width = 25
- $firstname.Height = 10
- $firstname.location = new-object system.drawing.point(13,10)
- $firstname.Font = "Microsoft Sans Serif,10"
- $Form.controls.Add($firstname)
- $Surname = New-Object system.windows.Forms.TextBox
- $Surname.Width = 140
- $Surname.Height = 20
- $Surname.location = new-object system.drawing.point(145,35)
- $Surname.Font = "Microsoft Sans Serif,10"
- $Form.controls.Add($Surname)
- $prijmeni = New-Object system.windows.Forms.Label
- $prijmeni.Text = "Příjmení"
- $prijmeni.AutoSize = $true
- $prijmeni.Width = 25
- $prijmeni.Height = 10
- $prijmeni.location = new-object system.drawing.point(13,35)
- $prijmeni.Font = "Microsoft Sans Serif,10"
- $Form.controls.Add($prijmeni)
- $Name = New-Object system.windows.Forms.TextBox
- $Name.Width = 140
- $Name.Height = 20
- $Name.location = new-object system.drawing.point(145,60)
- $Name.Font = "Microsoft Sans Serif,10"
- $Form.controls.Add($Name)
- $username = New-Object system.windows.Forms.Label
- $username.Text = "Uživatelské jméno"
- $username.AutoSize = $true
- $username.Width = 25
- $username.Height = 10
- $username.location = new-object system.drawing.point(13,60)
- $username.Font = "Microsoft Sans Serif,10"
- $Form.controls.Add($username)
- $DisplayName = New-Object system.windows.Forms.TextBox
- $DisplayName.Text = "`"PRIJMENI Jmeno`""
- $DisplayName.Width = 140
- $DisplayName.Height = 20
- $DisplayName.location = new-object system.drawing.point(145,85)
- $DisplayName.Font = "Microsoft Sans Serif,10"
- $Form.controls.Add($DisplayName)
- $displayedname = New-Object system.windows.Forms.Label
- $displayedname.Text = "Zobrazované jméno"
- $displayedname.AutoSize = $true
- $displayedname.Width = 25
- $displayedname.Height = 10
- $displayedname.location = new-object system.drawing.point(13,85)
- $displayedname.Font = "Microsoft Sans Serif,10"
- $Form.controls.Add($displayedname)
- $OU = New-Object system.windows.Forms.TextBox
- $OU.Width = 140
- $OU.Height = 20
- $OU.location = new-object system.drawing.point(145,110)
- $OU.Font = "Microsoft Sans Serif,10"
- $Form.controls.Add($OU)
- $department = New-Object system.windows.Forms.Label
- $department.Text = "Oddělení"
- $department.AutoSize = $true
- $department.Width = 25
- $department.Height = 10
- $department.location = new-object system.drawing.point(13,110)
- $department.Font = "Microsoft Sans Serif,10"
- $Form.controls.Add($department)
- $Title = New-Object system.windows.Forms.TextBox
- $Title.Width = 140
- $Title.Height = 20
- $Title.location = new-object system.drawing.point(145,135)
- $Title.Font = "Microsoft Sans Serif,10"
- $Form.controls.Add($Title)
- $funkce = New-Object system.windows.Forms.Label
- $funkce.Text = "Funkce"
- $funkce.AutoSize = $true
- $funkce.Width = 25
- $funkce.Height = 10
- $funkce.location = new-object system.drawing.point(13,135)
- $funkce.Font = "Microsoft Sans Serif,10"
- $Form.controls.Add($funkce)
- $MailNickname = New-Object system.windows.Forms.TextBox
- $MailNickname.Text = "bez @daidometal.com"
- $MailNickname.Width = 140
- $MailNickname.Height = 20
- $MailNickname.location = new-object system.drawing.point(145,185)
- $MailNickname.Font = "Microsoft Sans Serif,9"
- $Form.controls.Add($MailNickname)
- $Mailenabled1 = New-Object system.windows.Forms.Label
- $Mailenabled1.Text = "Povolit email"
- $Mailenabled1.AutoSize = $true
- $Mailenabled1.Width = 95
- $Mailenabled1.Height = 20
- $Mailenabled1.location = new-object system.drawing.point(13,160)
- $Mailenabled1.Font = "Microsoft Sans Serif,10"
- $Form.controls.Add($Mailenabled1)
- $Mailenabled2 = New-Object system.windows.Forms.Checkbox
- $Mailenabled2.location = new-object system.drawing.point(145,160)
- $Form.controls.Add($Mailenabled2)
- $mailname = New-Object system.windows.Forms.Label
- $mailname.Text = "Jméno emailu"
- $mailname.AutoSize = $true
- $mailname.Width = 25
- $mailname.Height = 10
- $mailname.location = new-object system.drawing.point(13,185)
- $mailname.Font = "Microsoft Sans Serif,10"
- $Form.controls.Add($mailname)
- $enabled = New-Object system.windows.Forms.CheckBox
- $enabled.Text = "enable account"
- $enabled.Checked = $true
- $enabled.AutoSize = $true
- $enabled.Width = 95
- $enabled.Height = 20
- $enabled.location = new-object system.drawing.point(145,230)
- $enabled.Font = "Microsoft Sans Serif,10"
- $Form.controls.Add($enabled)
- $label18 = New-Object system.windows.Forms.Label
- $label18.Text = "Heslo"
- $label18.AutoSize = $true
- $label18.Width = 25
- $label18.Height = 10
- $label18.location = new-object system.drawing.point(13,210)
- $label18.Font = "Microsoft Sans Serif,10"
- $Form.controls.Add($label18)
- $Password = New-Object system.windows.Forms.TextBox
- $Password.Text = "Daidometal1"
- $Password.Width = 140
- $Password.Height = 20
- $Password.location = new-object system.drawing.point(145,210)
- $Password.Font = "Microsoft Sans Serif,8"
- $Form.controls.Add($Password)
- "GivenName,Surname,Name,DisplayName,OU,Title,Password" | OUT-FILE c:\ADUserCreator\info.txt -force
- "MailNickname" | OUT-FILE c:\ADUserCreator\mail.txt -force
- $button3 = New-Object system.windows.Forms.Button
- $button3.BackColor = "#8ef2aa"
- $button3.Text = "Přidat"
- $button3.ForeColor = "#000000"
- $button3.Width = 90
- $button3.Height = 30
- $button3.location = new-object system.drawing.point(8,250)
- $button3.Font = "Microsoft Sans Serif,10,style=Bold"
- $Form.controls.Add($button3)
- #PO STISKNUTI TLACITKA ZKONTROLOVAT SE OTEVRE TXT SOUBOR S UDAJI, BUDE NAHRAZENO TLACITKEM "PRIDAT DALSI"
- $button3.Add_Click(
- {$GivenName.Text+","+$Surname.Text+","+$Name.Text+","+$DisplayName.Text+","+$OU.Text+","+$Title.Text+","+$Password.text| Out-File c:\ADUserCreator\info.txt -append
- $MailNickname.Text | OUT-FILE c:\ADUserCreator\mail.txt -append
- })
- $button2 = New-Object system.windows.Forms.Button
- $button2.Text = "Check user name"
- $button2.ForeColor = "#000000"
- $button2.Width = 90
- $button2.Height = 30
- $button2.location = new-object system.drawing.point(103,250)
- $button2.Font = "Microsoft Sans Serif,6,style=Bold"
- $Form.controls.Add($button2)
- $button2.Add_Click({
- if (dsquery user -samid $Name.text){
- $button2.BackColor = "#ff0000"
- }
- else{
- $button2.BackColor = "#04ff00"};
- })
- $button4 = New-Object system.windows.Forms.Button
- $button4.BackColor = "#ffbfbf"
- $button4.Text = "Vyčistit"
- $button4.Width = 90
- $button4.Height = 30
- $button4.location = new-object system.drawing.point(198,250)
- $button4.Font = "Microsoft Sans Serif,10,style=Bold"
- $Form.controls.Add($button4)
- $button4.Add_Click(
- {$GivenName.Clear();$Surname.Clear();$Name.Clear();$DisplayName.text ="`"PRIJMENI Jmeno`"";$OU.Clear();$Title.Clear();$MailNickname.text = "bez @daidometal.com";$Mailenabled2.Checked = $false;$enabled.Checked = $true; $Password.text = "Daidometal1"})
- #ZMACKNUTI ESC ZAVRE FORMULAR
- $Form.Add_KeyDown({
- if($_.KeyCode -eq "Escape") {
- $form.Close()
- Stop-Process -name ADUserCreator.exe
- }
- #ZMACKNUTI ENTERU ULOZI UDAJE Z FORMULARE DO TXT SOUBORU
- if($_.KeyCode -eq "Return"){
- $GivenName.Text+","+$Surname.Text+","+$Name.Text+","+$DisplayName.Text+","+$OU.Text+","+$Title.Text+","+$Password.text| Out-File c:\ADUserCreator\info.txt -append -NoNewline
- }
- })
- $button3.Add_Click({
- $path = import-csv "C:\ADUserCreator\info.txt"
- ForEach ($line in $path)
- {
- $GName = $line.GivenName
- $SName = $line.Surname
- $Nname = $line.Name
- $Dname = $line.DisplayName
- $OUnit = $line.OU
- $TTitle = $line.Title
- $Pass = ConvertTo-SecureString -AsPlainText $line.Password -force
- }
- $cesta="OU="+$OUnit+",OU=GeneralUsers,OU=DMC,OU=EU,DC=global,DC=ad,DC=local"
- New-ADUser -name $Nname -SamAccountName $Nname -GivenName $Gname -Surname $Sname -DisplayName $Dname -AccountPassword $Pass -Path $Cesta -UserPrincipalName $Nname"@daidometal.com" -OtherAttributes @{'countryCode'="203";'postalCode'="60200";'l'="Brno";'c'="CZ";'company'="DMC";'st'="GLOBAL";'department'=$OUnit;'title'=$TTitle;'co'="Česká Republika";'streetAddress'="Švédské valy 6";} -PassThru | % {Add-ADGroupMember -Identity "DMCZ" -Members $_;Add-ADGroupMember -Identity "GISA006" -Members $_};
- If ($enabled.Checked -eq $true)
- {
- Enable-ADAccount -Identity $Nname
- }
- $path2 = import-csv "C:\ADUserCreator\mail.txt"
- ForEach ($line1 in $path2)
- {$MNickname = $line1.MailNickname}
- $Mmail=$MNickname+"@daidomatel.com"
- If ($Mailenabled2.Checked -eq $true)
- {Set-ADUser -Identity $Nname -add @{'mail'=$Mmail;'mailNickname'=$MNickname;'proxyAddresses'="SMTP:"+$Mmail;}}
- })
- [void]$Form.ShowDialog()
- $Form.Dispose()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement