Finding age of administrator accounts on multiple machines in AD using powershell?

How would we search through multiple AD objects (machines) to find the password age for the account Administrator? I'd also like limit it to a search group. Here is what I have thus far:

Param
(
       [Parameter(Position=0,Mandatory=$false)]
       [ValidateNotNullorEmpty()]
       [Alias('cn')][String[]]$ComputerName=$Env:COMPUTERNAME,
       [Parameter(Position=1,Mandatory=$false)]
       [Alias('un')][String[]]$AccountName,
       [Parameter(Position=2,Mandatory=$false)]
       [Alias('cred')][System.Management.Automation.PsCredential]$Credential
)
       
$Obj = @()

Foreach($Computer in $ComputerName)
{
       If($Credential)
       {
              $AllLocalAccounts = Get-WmiObject -Class Win32_UserAccount -Namespace "root\cimv2" `
              -Filter "LocalAccount='$True'" -ComputerName $Computer -Credential $Credential -ErrorAction Stop
       }
       else
       {
              $AllLocalAccounts = Get-WmiObject -Class Win32_UserAccount -Namespace "root\cimv2" `
              -Filter "LocalAccount='$True'" -ComputerName $Computer -ErrorAction Stop
       }
       
       Foreach($LocalAccount in $AllLocalAccounts)
       {
              $Object = New-Object -TypeName PSObject
              
              $Object|Add-Member -MemberType NoteProperty -Name "Name" -Value $LocalAccount.Name
              $Object|Add-Member -MemberType NoteProperty -Name "Full Name" -Value $LocalAccount.FullName
              $Object|Add-Member -MemberType NoteProperty -Name "Caption" -Value $LocalAccount.Caption
      $Object|Add-Member -MemberType NoteProperty -Name "Disabled" -Value $LocalAccount.Disabled
      $Object|Add-Member -MemberType NoteProperty -Name "Status" -Value $LocalAccount.Status
      $Object|Add-Member -MemberType NoteProperty -Name "LockOut" -Value $LocalAccount.LockOut
              $Object|Add-Member -MemberType NoteProperty -Name "Password Changeable" -Value $LocalAccount.PasswordChangeable
              $Object|Add-Member -MemberType NoteProperty -Name "Password Expires" -Value $LocalAccount.PasswordExpires
              $Object|Add-Member -MemberType NoteProperty -Name "Password Required" -Value $LocalAccount.PasswordRequired
              $Object|Add-Member -MemberType NoteProperty -Name "SID" -Value $LocalAccount.SID
              $Object|Add-Member -MemberType NoteProperty -Name "SID Type" -Value $LocalAccount.SIDType
              $Object|Add-Member -MemberType NoteProperty -Name "Account Type" -Value $LocalAccount.AccountType
              $Object|Add-Member -MemberType NoteProperty -Name "Domain" -Value $LocalAccount.Domain
              $Object|Add-Member -MemberType NoteProperty -Name "Description" -Value $LocalAccount.Description
           $Object|Add-Member -MemberType NoteProperty -Name "Password Age" -Value $LocalAccount.PasswordAge
        
              
              $Obj+=$Object
       }
       
       If($AccountName)
       {
              Foreach($Account in $AccountName)
              {
                     $Obj|Where-Object{$_.Name -like "$Account"}
              }
       }
       else
       {
              $Obj
       }
} 

Open in new window

LVL 2
meade470Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

McKnifeCommented:
This is not saved to the AD object since the local admin is not in any way even related to AD.
To determine the age, run a domain startup script at the clients:
net user administrator>\\server\share\%computername%.txt

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.