Powershell Account Aktiflestirme Ve Kapama
-
simdi elimde bir kod var bununla account'un enable veya disable oldugunu gorebiliyorum, fakat benim istedigim bir buton yapip oradan account'u acip kapamak, kullanici adi programpw, bu kodla gosterebiliyorum;
$UserName = “programpw”
$searcher = new-object DirectoryServices.DirectorySearcher([ADSI]“”)
$searcher.filter = “(&(objectClass=user)(sAMAccountName= $UserName))”
$founduser = $searcher.findOne()
$founduser.Properties.useraccountcontrol
$value = $founduser.Properties.useraccountcontrol
if ($Value -eq 514)
{
Write-Output “Account is disabled”
}
if ($Value -eq 512)
{
Write-Output “Account is Enabled”
}
yardimci olursaniz sevinirim..
-
zar zor calisan bisey yaptim laheyya..
$objOUuser = [ADSI] "LDAP://cn=programpw,cn=Users,dc=dom6,dc=local"
$objOUuser
$Activer = New-Object System.Windows.Forms.Button
$Desactiver = New-Object System.Windows.Forms.Button
$Desactiver.Text = "Desactiver"
$Desactiver.Location = New-Object System.Drawing.Size(100, 10)
$Desactiver.Size = New-Object System.Drawing.Size(90,30)
$Activer.Text = "Activer"
$Activer.Location = New-Object System.Drawing.Size(10, 10)
$Activer.Size = New-Object System.Drawing.Size(90,30)
$Activer.Add_Click({
$objOUuser.Put('userAccountControl','512')
$objOUuser.SetInfo()
})
$Desactiver.Add_Click({
$objOUuser.Put('userAccountControl','514')
$objOUuser.SetInfo()
})
$Form1 = new-object System.Windows.Forms.form
$Form1.ClientSize = new-object System.Drawing.Size(200, 50)
$Form1.Controls.Add($Activer)
$Form1.Controls.Add($Desactiver)
$Form1.Text = "Activer - Désactiver Les Comptes"
$Form1.ShowDialog()