Created
August 29, 2016 09:17
-
-
Save Albus/ea023d7b9c548e77288f4aa057bb3929 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #Generated Form Function | |
| function GenerateForm { | |
| ######################################################################## | |
| # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0 | |
| # Generated On: 2014-02-17 09:30 | |
| # Generated By: Jean-Sebastien Elie | |
| Import-Module ActiveDirectory | |
| ######################################################################## | |
| #region Import the Assemblies | |
| [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null | |
| [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null | |
| #endregion | |
| #region Generated Form Objects | |
| $form1 = New-Object System.Windows.Forms.Form | |
| $val2 = New-Object System.Windows.Forms.Label | |
| $val1 = New-Object System.Windows.Forms.Label | |
| $bclear = New-Object System.Windows.Forms.Button | |
| $membership = New-Object System.Windows.Forms.CheckedListBox | |
| $bvalidate = New-Object System.Windows.Forms.Button | |
| $bcopy = New-Object System.Windows.Forms.Button | |
| $label3 = New-Object System.Windows.Forms.Label | |
| $label2 = New-Object System.Windows.Forms.Label | |
| $label1 = New-Object System.Windows.Forms.Label | |
| $cmbtransfer = New-Object System.Windows.Forms.ComboBox | |
| $cmbcopy = New-Object System.Windows.Forms.ComboBox | |
| $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState | |
| #endregion Generated Form Objects | |
| #---------------------------------------------- | |
| #Generated Event Script Blocks | |
| #---------------------------------------------- | |
| #Provide Custom Code for events specified in PrimalForms. | |
| #Ad array for Users + Feeding combobox | |
| $arrac = get-aduser -SearchBase "DC=fc-moron,DC=ru" -Filter * | sort-object | |
| #Feeding cmbcopy | |
| #Feeding cmbtransfer | |
| foreach($user in $arrac) | |
| { | |
| $cmbcopy.items.add($user.Name) | |
| $cmbtransfer.items.add($user.Name) | |
| } | |
| $bcopy_OnClick= | |
| { | |
| #Checking the Checkboxlist for all Checked Items | |
| $arrindexgrp = $membership.checkeditems | |
| $membership.enabled = $False | |
| #Adding User to each Group checked | |
| foreach($group in $arrindexgrp) | |
| { | |
| Try | |
| { | |
| Add-ADGroupMember -Identity "$group" -Members $global:user2 -ErrorAction Stop | |
| } | |
| Catch [Microsoft.ActiveDirectory.Management.ADException] | |
| { | |
| Write-host "Already a member of the Group: $group" | |
| Continue | |
| } | |
| } | |
| #Email report to It | |
| #$smtpServer = "mail.366.ru" | |
| #$smtpFrom = "[email protected]" | |
| #$smtpTo = "[email protected]" | |
| #$messageSubject = "Automated User Group Transfer" | |
| [string]$messagebody = "" | |
| $mailgrp = $arrindexgrp -join “`r`n” | |
| $global:user1 = $iuser1.name | |
| $global:user2 = $iuser2.name | |
| $messagebody = "Copied User: $global:user1 `r`nTransfered User: $global:user2 `r`nGroup Copied: `r`n$mailgrp" | |
| Write-host $messagebody | |
| #Send-MailMessage -To $smtpTo -From $smtpFrom -Subject $messagesubject -Body $messagebody -SmtpServer $smtpServer -Port 25 | |
| $bcopy.visible = $False | |
| $bclear.visible = $True | |
| } | |
| $bvalidate_OnClick= | |
| { | |
| #array index selection | |
| $global:indexcopy = $cmbcopy.SelectedIndex | |
| $global:indexxfer = $cmbtransfer.SelectedIndex | |
| $global:iuser1 = $arrac[$indexcopy] | |
| $global:iuser2 = $arrac[$indexxfer] | |
| $global:user1 = $iuser1 | |
| $global:user2 = $iuser2 | |
| #Combo User Selection Validation | |
| if ($cmbcopy.SelectedIndex -eq -1) {$global:user1 = "" | |
| $val1.Text = "No Selection"} | |
| else {$val1.Text = "OK"} | |
| if ($cmbtransfer.SelectedIndex -eq -1) {$global:user2 = "" | |
| $val2.Text = "No Selection"} | |
| else {$val2.Text = "OK"} | |
| # If both validation are ok then do next step | |
| if ( $val1.Text -eq "OK" -and $val2.Text -eq "OK") { | |
| $cmbcopy.enabled = $False | |
| $cmbtransfer.enabled = $False | |
| $bcopy.visible = $true | |
| $bvalidate.visible = $False | |
| $arrgroups = (Get-ADPrincipalGroupMembership $global:user1) | |
| foreach($group in $arrgroups) | |
| { | |
| $membership.items.add($group.Name) | |
| }} | |
| } | |
| $bclear_OnClick= | |
| { | |
| #Clearing Combobox | |
| $cmbcopy.SelectedIndex = -1 | |
| $cmbtransfer.SelectedIndex = -1 | |
| # Clear CheckedListBox | |
| $i = $membership.Items.Count | |
| while($i -ne -1) {$membership.items.remove($membership.items[$i]) | |
| $i--} | |
| #Enabling Combo, Checklist, Textbox and Button | |
| $val1.Text = "" | |
| $val2.Text = "" | |
| $cmbcopy.enabled = $true | |
| $cmbtransfer.enabled = $true | |
| $membership.enabled = $true | |
| $bvalidate.visible = $true | |
| $bclear.visible = $False | |
| } | |
| $OnLoadForm_StateCorrection= | |
| {#Correct the initial state of the form to prevent the .Net maximized form issue | |
| $form1.WindowState = $InitialFormWindowState | |
| } | |
| #---------------------------------------------- | |
| #region Generated Form Code | |
| $System_Drawing_Size = New-Object System.Drawing.Size | |
| $System_Drawing_Size.Height = 297 | |
| $System_Drawing_Size.Width = 477 | |
| $form1.ClientSize = $System_Drawing_Size | |
| $form1.DataBindings.DefaultDataSourceUpdateMode = 0 | |
| $form1.Name = "form1" | |
| $form1.Text = "Membership Transfer" | |
| $val2.DataBindings.DefaultDataSourceUpdateMode = 0 | |
| $System_Drawing_Point = New-Object System.Drawing.Point | |
| $System_Drawing_Point.X = 183 | |
| $System_Drawing_Point.Y = 116 | |
| $val2.Location = $System_Drawing_Point | |
| $val2.Name = "val2" | |
| $System_Drawing_Size = New-Object System.Drawing.Size | |
| $System_Drawing_Size.Height = 20 | |
| $System_Drawing_Size.Width = 112 | |
| $val2.Size = $System_Drawing_Size | |
| $val2.TabIndex = 11 | |
| $form1.Controls.Add($val2) | |
| $val1.DataBindings.DefaultDataSourceUpdateMode = 0 | |
| $System_Drawing_Point = New-Object System.Drawing.Point | |
| $System_Drawing_Point.X = 183 | |
| $System_Drawing_Point.Y = 52 | |
| $val1.Location = $System_Drawing_Point | |
| $val1.Name = "val1" | |
| $System_Drawing_Size = New-Object System.Drawing.Size | |
| $System_Drawing_Size.Height = 20 | |
| $System_Drawing_Size.Width = 112 | |
| $val1.Size = $System_Drawing_Size | |
| $val1.TabIndex = 10 | |
| $form1.Controls.Add($val1) | |
| $bclear.DataBindings.DefaultDataSourceUpdateMode = 0 | |
| $System_Drawing_Point = New-Object System.Drawing.Point | |
| $System_Drawing_Point.X = 327 | |
| $System_Drawing_Point.Y = 106 | |
| $bclear.Location = $System_Drawing_Point | |
| $bclear.Name = "bclear" | |
| $System_Drawing_Size = New-Object System.Drawing.Size | |
| $System_Drawing_Size.Height = 30 | |
| $System_Drawing_Size.Width = 126 | |
| $bclear.Size = $System_Drawing_Size | |
| $bclear.TabIndex = 9 | |
| $bclear.Text = "Clear" | |
| $bclear.UseVisualStyleBackColor = $True | |
| $bclear.add_Click($bclear_OnClick) | |
| $bclear.Visible = $False | |
| $form1.Controls.Add($bclear) | |
| $membership.DataBindings.DefaultDataSourceUpdateMode = 0 | |
| $membership.FormattingEnabled = $True | |
| $System_Drawing_Point = New-Object System.Drawing.Point | |
| $System_Drawing_Point.X = 30 | |
| $System_Drawing_Point.Y = 191 | |
| $membership.Location = $System_Drawing_Point | |
| $membership.Name = "membership" | |
| $System_Drawing_Size = New-Object System.Drawing.Size | |
| $System_Drawing_Size.Height = 94 | |
| $System_Drawing_Size.Width = 252 | |
| $membership.Size = $System_Drawing_Size | |
| $membership.TabIndex = 8 | |
| $form1.Controls.Add($membership) | |
| $bvalidate.DataBindings.DefaultDataSourceUpdateMode = 0 | |
| $System_Drawing_Point = New-Object System.Drawing.Point | |
| $System_Drawing_Point.X = 327 | |
| $System_Drawing_Point.Y = 25 | |
| $bvalidate.Location = $System_Drawing_Point | |
| $bvalidate.Name = "bvalidate" | |
| $System_Drawing_Size = New-Object System.Drawing.Size | |
| $System_Drawing_Size.Height = 30 | |
| $System_Drawing_Size.Width = 126 | |
| $bvalidate.Size = $System_Drawing_Size | |
| $bvalidate.TabIndex = 7 | |
| $bvalidate.Text = "Validate Group to copy" | |
| $bvalidate.UseVisualStyleBackColor = $True | |
| $bvalidate.add_Click($bvalidate_OnClick) | |
| $form1.Controls.Add($bvalidate) | |
| $bcopy.DataBindings.DefaultDataSourceUpdateMode = 0 | |
| $System_Drawing_Point = New-Object System.Drawing.Point | |
| $System_Drawing_Point.X = 327 | |
| $System_Drawing_Point.Y = 64 | |
| $bcopy.Location = $System_Drawing_Point | |
| $bcopy.Name = "bcopy" | |
| $System_Drawing_Size = New-Object System.Drawing.Size | |
| $System_Drawing_Size.Height = 30 | |
| $System_Drawing_Size.Width = 126 | |
| $bcopy.Size = $System_Drawing_Size | |
| $bcopy.TabIndex = 6 | |
| $bcopy.Text = "Copy" | |
| $bcopy.UseVisualStyleBackColor = $True | |
| $bcopy.Visible = $False | |
| $bcopy.add_Click($bcopy_OnClick) | |
| $form1.Controls.Add($bcopy) | |
| $label3.DataBindings.DefaultDataSourceUpdateMode = 0 | |
| $System_Drawing_Point = New-Object System.Drawing.Point | |
| $System_Drawing_Point.X = 30 | |
| $System_Drawing_Point.Y = 162 | |
| $label3.Location = $System_Drawing_Point | |
| $label3.Name = "label3" | |
| $System_Drawing_Size = New-Object System.Drawing.Size | |
| $System_Drawing_Size.Height = 21 | |
| $System_Drawing_Size.Width = 252 | |
| $label3.Size = $System_Drawing_Size | |
| $label3.TabIndex = 5 | |
| $label3.Text = "Membership " | |
| $form1.Controls.Add($label3) | |
| $label2.DataBindings.DefaultDataSourceUpdateMode = 0 | |
| $System_Drawing_Point = New-Object System.Drawing.Point | |
| $System_Drawing_Point.X = 30 | |
| $System_Drawing_Point.Y = 25 | |
| $label2.Location = $System_Drawing_Point | |
| $label2.Name = "label2" | |
| $System_Drawing_Size = New-Object System.Drawing.Size | |
| $System_Drawing_Size.Height = 21 | |
| $System_Drawing_Size.Width = 139 | |
| $label2.Size = $System_Drawing_Size | |
| $label2.TabIndex = 3 | |
| $label2.Text = "User to copy membership" | |
| $form1.Controls.Add($label2) | |
| $label1.DataBindings.DefaultDataSourceUpdateMode = 0 | |
| $System_Drawing_Point = New-Object System.Drawing.Point | |
| $System_Drawing_Point.X = 30 | |
| $System_Drawing_Point.Y = 88 | |
| $label1.Location = $System_Drawing_Point | |
| $label1.Name = "label1" | |
| $System_Drawing_Size = New-Object System.Drawing.Size | |
| $System_Drawing_Size.Height = 21 | |
| $System_Drawing_Size.Width = 139 | |
| $label1.Size = $System_Drawing_Size | |
| $label1.TabIndex = 2 | |
| $label1.Text = "User to transfer groups" | |
| $form1.Controls.Add($label1) | |
| $cmbtransfer.AutoCompleteMode = 3 | |
| $cmbtransfer.AutoCompleteSource = 256 | |
| $cmbtransfer.DataBindings.DefaultDataSourceUpdateMode = 0 | |
| $cmbtransfer.FormattingEnabled = $True | |
| $System_Drawing_Point = New-Object System.Drawing.Point | |
| $System_Drawing_Point.X = 30 | |
| $System_Drawing_Point.Y = 118 | |
| $cmbtransfer.Location = $System_Drawing_Point | |
| $cmbtransfer.Name = "cmbtransfer" | |
| $System_Drawing_Size = New-Object System.Drawing.Size | |
| $System_Drawing_Size.Height = 21 | |
| $System_Drawing_Size.Width = 139 | |
| $cmbtransfer.Size = $System_Drawing_Size | |
| $cmbtransfer.TabIndex = 1 | |
| $form1.Controls.Add($cmbtransfer) | |
| $cmbcopy.AutoCompleteMode = 3 | |
| $cmbcopy.AutoCompleteSource = 256 | |
| $cmbcopy.DataBindings.DefaultDataSourceUpdateMode = 0 | |
| $cmbcopy.FormattingEnabled = $True | |
| $System_Drawing_Point = New-Object System.Drawing.Point | |
| $System_Drawing_Point.X = 30 | |
| $System_Drawing_Point.Y = 52 | |
| $cmbcopy.Location = $System_Drawing_Point | |
| $cmbcopy.Name = "cmbcopy" | |
| $System_Drawing_Size = New-Object System.Drawing.Size | |
| $System_Drawing_Size.Height = 21 | |
| $System_Drawing_Size.Width = 139 | |
| $cmbcopy.Size = $System_Drawing_Size | |
| $cmbcopy.TabIndex = 0 | |
| $form1.Controls.Add($cmbcopy) | |
| #endregion Generated Form Code | |
| #Save the initial state of the form | |
| $InitialFormWindowState = $form1.WindowState | |
| #Init the OnLoad event to correct the initial state of the form | |
| $form1.add_Load($OnLoadForm_StateCorrection) | |
| #Show the Form | |
| $form1.ShowDialog()| Out-Null | |
| } #End Function | |
| #Call the Function | |
| GenerateForm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment