Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Local Admins report - please help

$
0
0

Hey All

I found a script on here that should help me, but I am stuck a little bit.

I need to only need local accounts, how can I exclude domain accounts? I also need to gather whether the account is set to expire or not or if it's disabled.

Can anyone kindly help me?  This also has to read a list of servers from a text file

 

$computername='yourcomputer'
$group= [ADSI]("WinNT://$computername/Administrators,group")
$group.Members() | ForEach-Object {
$AdsPath=$_.GetType().InvokeMember('Adspath', 'GetProperty', $null, $_, $null)
$a=$AdsPath.split('/',[StringSplitOptions]::RemoveEmptyEntries)
$name=$a[-1]
$domain=$a[-2]
$Sid=$_.GetType().InvokeMember('objectsid', 'GetProperty', $null, $_, $null)
New-Object-TypeName PSObject -Property ([ordered]@{
Name =$name
Computer =$computerName
PasswordAge =$(try {[int]((([ADSI]"WinNT://$($computerName)/$name").passwordage[0])/86400)} catch {$null})
objectSid = (New-ObjectSystem.Security.Principal.SecurityIdentifier($Sid, 0)).Value
LastLogin =$(([ADSI]"WinNT://$($computername)/$($name)").lastlogin)
FullName =$_.GetType().InvokeMember('fullname', 'GetProperty', $null, $_, $null)
})
}


Viewing all articles
Browse latest Browse all 6937

Trending Articles