This script could be used to remove computers from a group.
Sometimes, AD admin need to remove some computers from a group.
This script contains one advanced function, Remove-OSCComputer. You can use this script in following ways:
Method 1:
Method 2:
Example 1: Remove computer "test1","test2" form group GPO
Command: Remove-OSCComputer -ComputerName "test1","test2" -GroupName GPO
Screenshot:

Example 2: Remove computers form group GPO according to a text file
Command: Remove-OSCComputer -FilePath "C:\ComputerList.txt" -GroupName GPO
Screenshot:

Note The file format should be like this:
test1
test2
test3
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
If($ComputerName)
{
#Remove specified computer from specified group
Foreach($Item in $ComputerName)
{
RemoveCompter $Item $GroupName
}
}
Else
{
#Get the content of the specified file
$ComputerName = Get-Content -Path $FilePath
Foreach($Item in $ComputerName )
{
#Remove one by one
RemoveCompter $Item $GroupName
}
}
If($ComputerName) { #Remove specified computer from specified group Foreach($Item in $ComputerName) { RemoveCompter $Item $GroupName }} Else { #Get the content of the specified file $ComputerName = Get-Content -Path $FilePath Foreach($Item in $ComputerName ) { #Remove one by one RemoveCompter $Item $GroupName }}
PowerShell
Windows Server 2008R2 or later version