Solved

Powershell - details output file .

Posted on 2014-01-07
5
255 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
  • 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
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…

776 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