Аналог dsa.msc на PowerShell (версия 2)
Обновленная версия скрипта, ранее было здесь.
В новой версии можно задавать свой пароль + требовать смены от пользователя. Так же появилась кнопка «разблокировать» учетную запись.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
Import-Module ActiveDirectory Add-Type -AssemblyName System.Windows.Forms $Form = New-Object system.Windows.Forms.Form $Form.Text = "Проверка пользователя" $Form.TopMost = $true $Form.StartPosition = "CenterScreen" $Form.MaximizeBox = $false $Form.MinimizeBox = $True $Form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog $Icon = [System.Drawing.Icon]::ExtractAssociatedIcon("C:\Windows\System32\EhStorAuthn.exe") $Form.Icon = $Icon #прозрачность #$Form.Opacity = 0.9 $Form.Width = 400 $Form.Height = 300 $Picture = New-Object system.windows.Forms.PictureBox $Picture.ImageLocation = "C:\flammlin.gif" $Picture.location = new-object system.drawing.point(270,20) $Form.controls.Add($Picture) $textBox1 = New-Object system.windows.Forms.TextBox $textBox1.Width = 100 $textBox1.Height = 20 $textBox1.Text = "" $textBox1.location = new-object system.drawing.point(10,20) $textBox1.Font = "Microsoft Sans Serif,10" $Form.controls.Add($textBox1) $textBox1.add_KeyDown({if ($_.KeyCode -eq "Enter"){FFADU}}) $textBox2 = New-Object system.windows.Forms.TextBox $textBox2.Width = 150 $textBox2.Height = 20 $textBox2.Text = "" $textBox2.location = new-object system.drawing.point(139,164) $textBox2.Font = "Microsoft Sans Serif,10" $Form.controls.Add($textBox2) $button1 = New-Object system.windows.Forms.Button $button1.Text = "Поиск" $button1.Width = 60 $button1.Height = 30 $button1.location = new-object system.drawing.point(137,20) $button1.Font = "Microsoft Sans Serif,10" $Form.controls.Add($button1) $button1.add_Enter({FFADU}) $button2 = New-Object system.windows.Forms.Button $button2.Text = "Смена" $button2.Width = 60 $button2.Height = 30 $button2.Add_Click({ $loginname = $listView1.Text $newpwd = ConvertTo-SecureString -String $textBox2.Text -AsPlainText –Force if($checkBox.Checked) { Set-ADAccountPassword $loginname -NewPassword $newpwd -Reset -PassThru | Set-ADuser -ChangePasswordAtLogon $True msgBox("Пароль сменен со сменой при первом входе") } else { Set-ADAccountPassword $loginname -NewPassword $newpwd -Reset -PassThru msgBox("Пароль сменен") } }) $button2.location = new-object system.drawing.point(137, 225) $button2.Font = "Microsoft Sans Serif,10" $Form.controls.Add($button2) $button3 = New-Object system.windows.Forms.Button $button3.Text = "Разблокировать" $button3.Width = 140 $button3.Height = 30 $button3.Add_Click({ $loginname = $listView1.Text Get-ADUser -Identity $loginname | Unlock-ADAccount msgBox("Учетная запись разблокирована") }) $button3.location = new-object system.drawing.point(215, 225) $button3.Font = "Microsoft Sans Serif,10" $Form.controls.Add($button3) $listView1 = New-Object System.Windows.Forms.ListBox $listView1.MultiColumn=$false $listView1.Width=100 $listView1.Height=170 $listView1.location = new-object system.drawing.point(9,53) $Form.controls.Add($listView1) $listView1.add_click({SelADU}) $label1 = New-Object system.windows.Forms.Label $label1.Text = "Последний раз пароль менялся:" $label1.AutoSize = $true $label1.Width = 25 $label1.Height = 10 $label1.location = new-object system.drawing.point(139,64) $label1.Font = "Microsoft Sans Serif,10" $Form.controls.Add($label1) $label3 = New-Object system.windows.Forms.Label $label3.Text = "Просрочен пароль? (FALSE - норм):" $label3.AutoSize = $true $label3.Width = 25 $label3.Height = 10 $label3.location = new-object system.drawing.point(139,104) $label3.Font = "Microsoft Sans Serif,10" $Form.controls.Add($label3) $label5 = New-Object system.windows.Forms.Label $label5.Text = "Новый пароль:" $label5.AutoSize = $true $label5.Width = 25 $label5.Height = 10 $label5.location = new-object system.drawing.point(139,144) $label5.Font = "Microsoft Sans Serif,10" $Form.controls.Add($label5) $button3 = New-Object system.windows.Forms.Button $button3.Text = "Выход" $button3.Width = 60 $button3.Height = 30 $button3.Add_Click({ $form.Close() }) $button3.location = new-object system.drawing.point(10,225) $button3.Font = "Microsoft Sans Serif,10" $Form.controls.Add($button3) #PasswordLastSet $label2 = New-Object system.windows.Forms.Label $label2.AutoSize = $true $label2.Width = 25 $label2.Height = 40 $label2.location = new-object system.drawing.point(139,84) $label2.Font = "Microsoft Sans Serif,10" $Form.controls.Add($label2) #PasswordExpired $label4 = New-Object system.windows.Forms.Label $label4.AutoSize = $true $label4.Width = 25 $label4.Height = 10 $label4.location = new-object system.drawing.point(139,124) $label4.Font = "Microsoft Sans Serif,10" $Form.controls.Add($label4) $checkBox = New-Object system.windows.Forms.CheckBox $checkBox.Text = "Требовать смены пароля" $checkBox.AutoSize = $true $checkBox.Width = 95 $checkBox.Height = 20 $checkBox.location = new-object system.drawing.point(139,194) $checkBox.Font = "Microsoft Sans Serif,10" $Form.controls.Add($checkBox) function FFADU{ $listView1.Items.Clear() $ldapfilte = [string]"(|(userPrincipalName=*"+ $textBox1.Text + "*)(Name=*"+ $textBox1.Text + "*))" $UsersAD = Get-ADUser -ldapfilter $ldapfilte -Properties SamAccountName | Sort SamAccountName foreach ($itemAD in $UsersAD) { $listView1.Items.Add($itemAD.SamAccountName) } $listView1.SelectedIndex=0 } function SelADU { $label2.Text = "" $label4.Text = "" $Global:UserAD = Get-ADUser -Identity $listView1.Text -Properties PasswordExpired, PasswordLastSet $label2.Text =if ($Global:UserAD.PasswordLastSet) {$Global:UserAD.PasswordLastSet} $label4.Text = $Global:UserAD.PasswordExpired } function msgBox($x){ [System.Windows.Forms.MessageBox]::Show($x, 'Информация', [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information, [Windows.Forms.MessageBoxDefaultButton]::Button1, [Windows.Forms.MessageBoxOptions]::ServiceNotification ) } [void]$Form.ShowDialog() $Form.Dispose() |
Это вторая версия скрипта.