Forums on Intune, SCCM, and Windows 11

Welcome to the forums. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your topics and posts, as well as connect with other members through your own private inbox!

SOLVED DELETING COMPUTER RECORDS IN FROM SCCM CONSOLE USING POWERSHELL

Status
Not open for further replies.

Gokul

Well-Known Member
Staff member
Messages
321
Solutions
4
Reaction score
58
Points
28
Good Day All

Working in Big infra , its very hectic to delete the computer records one by one from console . It will ruin your day itself . So here i am showing bulk deleting of sccm clients using PS . Scripts will check the client availability in console , if its present it will remove the clients from console . This we can monitor by clientremoval.log , which will by create by script
1.Copy paste the below scripts and save as .ps in drive
2.Open a notepad and put the client hostname and save as clients.txt
SS 1.JPG

Log

SS 1.JPG
 
<#
This script will read notepad file for client computers,check if they exist and remove from SCCM .

#>
# Determine script location and create log file to store the results
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
#log
$log = "$ScriptDir\clientremoval.log"
$date = Get-Date -Format "dd-MM-yyyy hh:mm:ss"

"--------------------- Script executed on $date (dd-MM-yyyy hh:mm:ss) ---------------------" + "`r`n" | Out-File $log -append
#try import SCCM Module ,if error catch it.
Try
{
Import-Module (Join-Path $(Split-Path $env:SMS_ADMIN_UI_PATH) ConfigurationManager.psd1)
$SiteCode = Get-PSDrive -PSProvider CMSITE
$SMSProvider=$sitecode.SiteServer
Set-Location "$($SiteCode.Name):\"
}
Catch
{
"[ERROR]`t SCCM Module couldn't be loaded. Script will exit!" | Out-File $log -append
Exit 1
}
# Read the notepad file for client records
ForEach ($client in Get-Content $ScriptDir"\clients.txt")
{
$CN=Get-CMDevice -Name $client
$name=$CN.Name
if ($name)
{
try {
"$date [INFO]`t $name found in SCCM " | Out-File $log -append
Remove-CMDevice -name $client -force
"$date [INFO]`t $name removed from SCCM " | Out-File $log -append
}
catch
{"$date [INFO]`t $name found in SCCM but unable to delete record.Check further " | Out-File $log -append
}
}
else
{ "$date [INFO]`t $client not found in SCCM " | Out-File $log -append}
}
 
Last edited:
Status
Not open for further replies.

Forum statistics

Threads
7,174
Messages
27,997
Members
18,300
Latest member
rpetrov

Trending content

Back
Top