Please Read: Significant Update Planned, Migrating Forum Software This Month

See more
See less

Quey user partial name & unlock account

  • Filter
  • Time
  • Show
Clear All
new posts

  • Quey user partial name & unlock account

    Hi all
    Im looking to quickly unlock AD accounts. I want to enter in the partial name e.g. donald d
    have it return e.g.

    donald duck dduck locked
    donald donovan ddonovan disabled
    donald davids ddavids enabled

    Then choose e.g. donald duck to be unlocked

    So I need to list the relevant accounts including lockled accounts and quickly select the locked one.
    So far I have below. It dosent display locked accounts and I cant act upon the output.

    $name = read-host 'Whats the name'
    Get-Aduser -Filter "name -like '$name*'" | select name,enabled | Format-List

    I have researched that Search-AdAccoount -lockedout can be used to look for unlocked accounts

    Need to bring it all together.

    The trick will be acting on the output. e.g. Select an account to be unlocked and the user would select 1 or 2

    1) donald duck dduck locked

    2) donald donovan ddonovan disabled

    If anyone has any pointers id be grateful



  • #2
    It think something like this should get you what you're looking for.

    $name = read-host 'Whats the name'
    $users = Get-Aduser -Filter "name -like '$name*'" -Properties enabled,lockedout | ForEach-Object { $_ | select @{name='Number';Expression={$i}},name,enabled,lockedout;$i++}
    $users | ft -AutoSize
    $exei = Read-Host 'Select the number to take action on'
    #Insert code to take action on here using "$users[$exei]":
    Write-Host "You took action on this user:"
    Last edited by JeremyW; 7th June 2015, 12:33.

    Network Consultant/Engineer
    Baltimore - Washington area and beyond