Solved

Powershell - details output file .

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

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.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now