Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Remove-AdminCount
- {
- [CmdletBinding()]
- param ($Samaccountname)
- if (!$(Get-Module activedirectory)){import-module activedirectory}
- try
- {
- $User = Get-ADUser $Samaccountname -Properties Admincount
- if ($User.Admincount -eq 1)
- {
- Write-Verbose "Admin Count found on $Samaccountname"
- set-aduser $Samaccountname -Replace @{admincount=0}
- $command = 'dsacls "' + $user.distinguishedName + '" /P:N'
- iex $command > $null
- Write-Verbose "Admin Count removed from $Samaccountname"
- }
- else {Write-Verbose "Admincount not set on $Samaccountname"}
- }
- catch {Write-Warning "$Samaccountname does not exist in AD"}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement