Jump to content


How to remove a computer from sccm during a task sequence

Recommended Posts

m trying to write a powershell script that will remove the computer running it from sccm during a task sequence. I have the proper server and site name in but it always returns a null resID during the task sequence but when i change it to be used in a normal powershell script in the ise it works just fine. I have the computer name saved as a task sequence variable OSDComputerName earlier in the task sequence. Can anyone help me out?

$SCCMServer = 'SERVER'

$sitename = 'SITE'

$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment


$resID = Get-WmiObject -computername $SCCMServer -credential $credential -query "select resourceID from sms_r_system where Name like `'$computername`'" -Namespace "root\sms\site_$sitename"

if ($resID.ResourceId -eq $null)

{$msgboxValue = "The PC does not exist in SCCM"}



$comp = [wmi]"\\$SCCMServer\root\sms\site_$($sitename):sms_r_system.resourceID=$($resID.ResourceId)"


#// deletion successfull?


{$msgboxValue = "Successfully deleted $computername"}


{$msgboxValue = "Could not delete $computername, error: $($error[0])"}





[Microsoft.VisualBasic.Interaction]::msgbox($msgboxValue, 0, "Delete from SCCM Status")

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...