speclou Posted May 29, 2015 Report post Posted May 29, 2015 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") Quote Share this post Link to post Share on other sites More sharing options...
Peter van der Woude Posted May 29, 2015 Report post Posted May 29, 2015 See: https://social.technet.microsoft.com/Forums/en-US/65142308-4b35-4ebf-b01b-1a8f5c8f5694/how-to-remove-a-computer-from-sccm-during-a-task-sequence?forum=configmanagergeneral Quote Share this post Link to post Share on other sites More sharing options...
Bharti C Posted October 31, 2022 Report post Posted October 31, 2022 @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. Quote Share this post Link to post Share on other sites More sharing options...