?
Solved

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

Posted on 2012-03-18
5
Medium Priority
?
570 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
  • 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 2000 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Here's a look at newsworthy articles and community happenings during the last month.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

830 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