• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1282
  • Last Modified:

Remove Computer Account from Group - Script

I have a scheduled task on every computer that runs a program. After the program is ran, I am wanting to run a script that removes that computer's AD account from a security group.

I have modified the group so that SELF can remove itself. Does anyone have a script that will allow for the computer to remove itself from the security group specified?
0
Joseph Moody
Asked:
Joseph Moody
2 Solutions
 
X_layerCommented:
You mean to remove this computer account from local security group on this computer?
0
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
Nope. An AD security group.
0
 
X_layerCommented:
Then you can try this:
$Computer = Get-Content env:computername
$GroupName = NameOfSecurityGroup

Remove-ADGroupMember -Identity $GroupName -Members $Computer -WhatIf

Open in new window

When you'll finish with testing, just remove WhatIf at the end.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
X_layerCommented:
And you will need AD module. Put this line on the start of the script:
Import-Module ActiveDirectory

Open in new window

0
 
RobSampsonCommented:
The VBScript equivalent of the Powershell would be:
					Set objADSysInfo = CreateObject("ADSystemInfo")
					Set objGroup = GetObject("LDAP://CN=GroupName,OU=GroupOU,DC=Domain,DC=com")
					objGroup.Remove("LDAP://" & objADSysInfo.ComputerName)

Open in new window


Regards,

Rob.
0
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
Thank you both!
0
 
samiam41Commented:
If either expert here can offer their genius on a PowerShell question, I would be incredibly thankful.

http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_27872052.html#a38419147

Thanks in advance.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now