Solved

Power Shell - Active Directory -  Pulling local groups from multiple servers

Posted on 2012-03-18
5
556 Views
Last Modified: 2012-06-27
Hi EE

Anyone have a way with Power Shell to pull the members of the Administrators group ?

Get-Content Servers.txt | ???? or some other way ?

I want to put the server names in the text file and have power shell pull all the members of the Administrators group .
0
Comment
Question by:MilesLogan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

by:prashanthd
ID: 37736027
Copy following code to .ps1 file and execute.
This will take input from servers.txt and write to output.txt

$list=get-content servers.txt
foreach ($strcomputer in $list){
$computer = [ADSI]("WinNT://" + $strComputer + ",computer")
$strcomputer
$Group = $computer.psbase.children.find("Administrators")
$members= $Group.psbase.invoke("Members") | %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}

	ForEach($user in $members)
	{
	$a = $strComputer + "," + $user.ToString()
	$a | Out-File output.txt -Append
	}
}

Open in new window

0
 
LVL 12

Expert Comment

by:Navdeep
ID: 37736031
Hi,

This is what you are looking for. These are powershell scripts.

http://poshcode.org/544
http://powershell.com/cs/media/p/3215.aspx

You would need to modify the code a bit to suit your needs.

Regards,
Navdeep [v-2nas]
0
 
LVL 2

Author Comment

by:MilesLogan
ID: 37743071
prashanthd

Thank you for the help .. this does output what I am looking for ...but
Is there a way for the output file to show if the accounts are local to that machine or domain accounts ?
0
 
LVL 12

Accepted Solution

by:
prashanthd earned 500 total points
ID: 37752321
Try the following

$list=get-content servers.txt
foreach ($strcomputer in $list){
$computer = [ADSI]("WinNT://" + $strComputer + ",computer")
$strcomputer
$Group = $computer.psbase.children.find("Administrators")
$members= $Group.psbase.invoke("Members") | %{$_.GetType().InvokeMember("adspath", 'GetProperty', $null, $_, $null)}

	ForEach($user in $members)
	{
	$username=$user.ToString()
	$username=$username.replace("WinNT://","")
	if ($username.contains("$strcomputer/")){
		$a = $strComputer + "," + $username +",Local User"
	}
	else{
	$a = $strComputer + "," + $username +",Domain User"
	}

	$a | Out-File output.txt -Append
	}
}
         

Open in new window

0
 
LVL 2

Author Closing Comment

by:MilesLogan
ID: 37761340
This worked perfect .. thanks !
0

Featured Post

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question