Advertisement
Guest User

Untitled

a guest
May 25th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. function Remove-AdminCount
  2. {
  3. [CmdletBinding()]
  4.     param ($Samaccountname)
  5.     if (!$(Get-Module activedirectory)){import-module activedirectory}
  6. try
  7.     {
  8.         $User = Get-ADUser $Samaccountname -Properties Admincount
  9.         if ($User.Admincount -eq 1)
  10.         {
  11.             Write-Verbose "Admin Count found on $Samaccountname"
  12.             set-aduser $Samaccountname -Replace @{admincount=0}
  13.             $command = 'dsacls "' + $user.distinguishedName + '" /P:N'
  14.             iex $command > $null
  15.             Write-Verbose "Admin Count removed from $Samaccountname"
  16.         }
  17.         else {Write-Verbose "Admincount not set on $Samaccountname"}
  18.     }
  19.     catch {Write-Warning "$Samaccountname does not exist in AD"}
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement