Local accounts on domain-joined computers

Sometimes you just want to know which local accounts are on which domain-joined computer.

Import-Module ActiveDirectory

#Gets all Computers in specified OU in puts them in $servers array#
$servers = Get-ADComputer -SearchBase "OU=Servers,DC=ITDEPT,DC=LOCAL" -SearchScope Subtree -filter *

$servers | % {
#Gets all accounts on server where LocalAccount is True#
$accounts += Get-WmiObject -Namespace "root\cimv2" -Class Win32_UserAccount -ComputerName $_.Name -Filter "LocalAccount='True'"
}

# Removes empty items from the $accounts array #
$accounts = $accounts | ? {$_}

#Exports $accounts array to CSV#
$accounts | Export-Csv -Path 'LocalAccounts.csv'

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s