Sign in
|
Join PowerShell.com!
|
Help
Home
PowerTips
Ask the Experts
Forums
Webcasts
Blogs
eBookV2
Script Library
Twitter Grid
Modules
QuickClick
Scripts
Snippets
Videos
Library
»
Script Library
»
Local Accounts
»
Slideshow
Local Accounts Slideshow
Share
|
Browse Library
Module Library
QuickClick Library
Script Library
Active Directory
BizTalk
Citrix
Clustering
Desktop
Exchange Server 2003
Exchange Server 2007
File System
Group Policy
Internet Information Server (IIS)
Local Accounts
Logs
Microsoft Office
Microsoft Team Foundation Server
MySQL
Networking
Registry
Remote Desktop Services
Remoting
Security
SharePoint
SQL Server
System Center Virtual Machine Manager
System Center Configuration Manager
System Center Operations Manager
Tutorial
Terminal Server
Using .Net
Virtual Server
VMware
Windows 7
Windows HPC
Windows Server 2000
Windows Server 2003
Windows Server 2008
Windows XP
WMI
Misc
Snippet Library
Video Library
Members Only
Tags
administrator
ADSI
group
local
local. WinNT
member
psbase
users
WinNT
View more
Add or remove AD groups to or from Local groups
<
#
Name:
remove-ad
-
group.ps1
Objective: To read a list of computernames from a file and then
if
the identified
group exists
in
the local administrators group remove it
Date: 01
/
31
/
2011
Email: rburke@
rbconsulting.net
#>
#Name of user or group to be removed
$userName
=
'IS_Tier3'
#Name of local group to remove user or group from
$localGroupName
=
'Administrators'
#Variable that contains the contents of the servername list
$c
=
Get-Content
"c:\Servers.txt"
#read each name and execute below script against each name in the list
foreach
(
$comp
in
$c
)
{
#Variable reassignment
$computerName
=
$comp
#This reads the local domain and prepends it to the USERID
[
string
]
$domainName
=
([
ADSI
]
''
).
name
# We are providing a yes so that we are not prompted for each computer
$confirm
=
"Y"
if
(
$confirm
-eq
"Y"
) {
([
ADSI
]
"WinNT://$computerName/$localGroupName,group"
).
remove
(
"WinNT://$domainName/$userName"
)
#We could output this to a file for future reference
Write-Host
"User $domainName\$userName has been removed from local group $localGroupName on computer $computerName."
}
}
Loading...
Add or remove...
Control logon...
List Local...
Remove Local...
List All Local...
New Local Group
Configure Windows...
Remove a Domain...
Add a Domain...
List All Local...
View all files
Copyright 2011 PowerShell.com. All rights reserved.