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

Local admin list with info for account

$
0
0

Howdy

I found a script on here that I think I am close to getting to work for what I need. But I am stuck on the for-each loop for the list of computers I need to run it against and saving the output to a file.

Here is what I have so far:

Hi Jaap,

I've made it this far and I get the results for only 1 computer in the list...Can you help me out please?

 

Get-Content c:\temp\computers.txt | ForEach-Object {

$computername = $_

$localGroupName = "Administrators"

$group = [ADSI]("WinNT://$computerName/$localGroupName,group")

$group.Members() |

    foreach {

        $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)

        # Ignore non-local accounts

       # if ($domain -eq $computerName)

            New-Object -TypeName PSObject -Property ([ordered]@{

                Name = $name;

                Computer = $computerName;

                PasswordAge = [int]((([ADSI]"WinNT://$($computerName)/$($name)").passwordage[0])/86400)

                objectSid = (New-Object System.Security.Principal.SecurityIdentifier($Sid, 0)).Value

            })

        }

    }


Viewing all articles
Browse latest Browse all 6937

Trending Articles