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

Report of Local Administrators with last login

$
0
0

Hey All

I am trying to get this script working that was in another post. I am not sure what's wrong now but I was getting an error related to "members" network path not found and now it's running and doing absolutely nothing :( 

Can anyone assist me in getting this to work against a list of servers in a text file and then as a separate task I have to use the same script but modify it so that it will read a list of servers in a file and also only look for specific IDs that I can put into a csv or text file.

Get-Content P\Powershell\scripts\serverlist.txt | ForEach-Object {

    $computerName = $_

    $localGroupName = "Administrators"

    $group = [ADSI]("WinNT://$computerName/$localGroupName,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

            LastLogin = $(([ADSI]"WinNT://$($computername)/$($name)").lastlogin).tostring()

        })

    }

} | Export-Csv -Path c:\reports\powershell\admins.csv -NoTypeInformation

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles