Skip to content

How to remove a computer from sccm during a task sequence

Featured Replies

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

$computername=$Tsenv.value("OSDComputerName")

$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"}

else

{

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

$comp.psbase.delete()

#// deletion successfull?

if($?)

{$msgboxValue = "Successfully deleted $computername"}

else

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

}

 

[void][system.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')

 

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

  • 7 years later...

@Peter van der Woude i am not sure why you posted the link above. Above link doesnt provide any solution to what the the guy has asked. i am actully looking for same thing to be address. 

Join the conversation

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

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.