Solved

Powershell - details output file .

Posted on 2014-01-07
5
271 Views
Last Modified: 2014-01-17
I normally dont need to do this on such a large scale but I need to add a group to about 4,000 servers . The script below works fine with just a couple .. can someome help me modify this so it outputs a file with information if it did add the group or it could not connect to the server ?

GC Servers.txt | %{

$domain="MyDomain"
$group = "MyGroup"

([adsi]"WinNT://$_/Administrators,group").Add("WinNT://$domain/$group,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 53

Expert Comment

by:Will Szymkowski
ID: 39763851
You can accomplish this very easily using Restricted Groups in Group Policy. This is a computer policy but no reboot required. Wait for group policy to refresh and the AD group will be added to all of the servers/workstations you specify for this GPO.

Restricted Groups GPO - http://community.spiceworks.com/how_to/show/2123-add-an-active-directory-group-to-the-local-administrator-group-of-workstation-s

Will.
0
 
LVL 2

Author Comment

by:MilesLogan
ID: 39763856
Hi Spec01 .. right .. I appreciate that information but I cant use a GPO on these .
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39769524
I have done some modification but not tested... :-) . Check and see if it gives you the expected result.
$ErrorActionPreference = "Stop"
GC Servers.txt | %{
$Serv = $_
$domain="MyDomain"
$group = "Guests"
	Try {
	([adsi]"WinNT://$Serv/Administrators,group").Add("WinNT://$domain/$group,group")
	"" | Select @{N="Server";e={$Serv}},@{N="Status";e={"Success"}}
	}
	Catch{
	"" | Select @{N="Server";e={$Serv}},@{N="Status";e={"Failed"}}
	}
}

Open in new window

0
 
LVL 2

Author Closing Comment

by:MilesLogan
ID: 39788937
Hi Subsun .. This worked great ! thanks again !

Sorry for the delay ..
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39789197
No problem.. :-)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
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…
Suggested Courses

630 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