Jump to content


speclou

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

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

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.

Guest
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.

Loading...


×
×
  • Create New...