Computer Object Owner is enable or Disable RRS feed

  • Question

  • Hi Expert,

    I need to verify is the Computer Object Owner is still enable with the script below. not sure where goes wrong but the result always go to "User $userName who Manage this machine is DISABLE" even the user is enable.

    $ManageBy = Get-ADComputer computer -Properties ManagedBy |select -ExpandProperty ManagedBy
    $userName = Get-ADUser "$ManageBy" -Properties name| select -ExpandProperty Name
    $user = Get-ADUser "$ManageBy" -Properties enabled,name,managedObjects,manager | select ManagedObjects,Name,Enabled,Manager
    $ValidateUser = $user
    try{$ValidateUser = Get-ADUser "$ManageBy" -Properties enabled|select Enable  -ErrorAction SilentlyContinue } Catch {}
    if ($ValidateUser -eq $user)
    Write-Host "User $userName who Manage this machine is Enable" -ForegroundColor yellow 
    $user| fl
    if ($ValidateUser -ne $user)
    Write-Host "User $userName who Manage this machine is DISABLE" -ForegroundColor Red

    • Moved by Bill_Stewart Thursday, December 13, 2018 3:32 PM This is not "debug/fix/rewrite my script for me" forum
    Tuesday, September 25, 2018 9:27 AM

All replies

  • I think you should take time to learn the basics of PowerShell.  The code you have posted is mostly nonsense.

    Please be aware that the word is "Enabled" and not "Enable".  If you bet the property names wrong then they will always be false, empty or missing.

    You cannot use Try/Catch with "SilentlyContinue".

    To get the user enabled status:

    (Get-AdUser $userid).Enabled


    1. Learn PowerShell  
    2. PowerShell Documentation
    3. PowerShell Style Guidelines


    Tuesday, September 25, 2018 10:07 AM