Explorar o código

add Disable-ADAccountGui.ps1

Tobias Simetsreiter %!s(int64=2) %!d(string=hai) anos
pai
achega
f1428b1899
Modificáronse 1 ficheiros con 36 adicións e 0 borrados
  1. 36 0
      bin/Disable-ADAccountGui.ps1

+ 36 - 0
bin/Disable-ADAccountGui.ps1

@@ -0,0 +1,36 @@
+param(
+    [hashtable]$GetADUserArgs=@{},
+    $Where={$true}
+)
+
+
+if (-not $GetADUserArgs.Properties) {
+    $GetADUserArgs["Properties"] = @(
+        "mail",
+        "lastLogon",
+        "lastLogonTimestamp",
+        "distinguishedName",
+        "UserPrincipalName"
+    )
+}
+if (-not $GetADUserArgs.Filter) {
+    $GetADUserArgs["Filter"] = {Enabled -eq $true}
+}
+$GetADUserArgs | Format-Table | Out-Host
+
+
+$users = Get-ADUser @GetADUserArgs | Where-Object $Where | Sort-Object lastLogonTimestamp | Foreach-Object {
+    [PSCustomObject]@{
+        dn=$_.distinguishedName
+        UserPrincipalName=$_.UserPrincipalName
+        mail=$_.mail
+        lastLogon=$_.lastLogon
+        lastLogonTimestamp=$_.lastLogonTimestamp
+        lastLogonTimestampStr=[datetime]::FromFileTimeUtc($_.lastLogonTimestamp)
+    }
+} | Out-GridView -OutputMode Multiple
+
+$users | Foreach-Object {
+    ([string]$_.dn) | Out-Host
+    Disable-ADAccount -Identity ([string]$_.dn)
+}