Solved

Trouble deleting a computer from SCCM 2012

Posted on 2013-06-11
10
3,018 Views
Last Modified: 2013-07-03
Hi there,

A rookie question: I need to delete a PC from SCCM 2012 device list, however there is no delete button when I right-click on it. Any advice?

Thanks!
0
Comment
Question by:rookie_b
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 22

Expert Comment

by:Haresh Nikumbh
ID: 39237343
0
 

Author Comment

by:rookie_b
ID: 39237366
OK, thanks for that, looks like I will try to make use of it in the future. Is there a one liner that I can use to just manually remove a specific record, based on computer name or id?

Thanks!
0
 

Author Comment

by:rookie_b
ID: 39237766
Anyone?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:Haresh Nikumbh
ID: 39237829
its just simple script which will ask some question like domain name.. SSCM server name and site

have you tried to running ?
0
 
LVL 22

Expert Comment

by:Haresh Nikumbh
ID: 39237839
Remove-ADComputer [-Identity] <ADComputer> [-AuthType {<Negotiate> | <Basic>}] [-Credential <PSCredential>] [-Partition <string>] [-Server <string>] [-Confirm] [-WhatIf] [<CommonParameters>]

Open in new window


Above is powershell script which remove active directory computer

http://technet.microsoft.com/en-us/library/ee617250.aspx
0
 

Author Comment

by:rookie_b
ID: 39238169
The script is for aged PCs. This is not an aged PC. I literaly just need to delete it from sccm, not even from AD.
0
 

Author Comment

by:rookie_b
ID: 39238376
Here is a script I found

<#
.SYNOPSIS
    Deletes computer from SCCM and AD
.DESCRIPTION
    Queries AD & SCCM, deletes the computer account from AD, and removes the computer object from SCCM
.NOTES
    Author: Jonathan - jon@elderec.org
.LINK
 
http://elderec.org
 
.PARAMETER computerName
    Name of computer to delete from AD/SCCM
.PARAMETER sccmServer
    Name of the SCCM server to use
.PARAMETER sccmSite
    Name of the SCCM site to use
.EXAMPLE
    .\delcomp-adsccm.ps1 -computerName CON-01337
    .\delcomp-adsccm.ps1 -computerName CON-01337 -sccmServer sccm.contoso.com
    .\delcomp-adsccm.ps1 -computerName CON-01337 -sccmServer sccm.contoso.comm -sccmSite YOURSITE
#>
 
param (
    [parameter(Mandatory=$true, HelpMessage="Enter a computer name")][string]$computerName,
    [parameter(Mandatory=$false, HelpMessage="Enter SCCM server")][string]$sccmServer='sccm-server.contoso.com',
    [parameter(Mandatory=$false, HelpMessage="Enter SCCM server")][string]$sccmSite='YOURSITE'
)
 
# find and delete the computer from AD
$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$root = $dom.GetDirectoryEntry()
$search = [System.DirectoryServices.DirectorySearcher]$root
$search.filter = "(&(objectclass=computer)(name=$computerName))"
$search.findall() | %{$_.GetDirectoryEntry() } | %{$_.DeleteObject(0)}
 
# find and delete from SCCM
$comp = get-wmiobject -query "select * from SMS_R_SYSTEM WHERE Name='$computerName'" -computername $sccmServer -namespace "ROOT\SMS\site_$sccmSite"
$comp.psbase.delete()
 
# spit out results
Write-Host "Deleted $computerName from AD. Removed $computerName from SCCM server $sccmServer, site $sccmSite"




I pastye it in powershell but all it does is prompt me for a computername and nothing happens. Is there anything I need to change? I don't care about prompts,. I'd be perfectly happy to just manually set the PC, Site and Server, but I don't know how. Also, regarding the AD bit, do I need to import-module activedirectory?
0
 

Author Comment

by:rookie_b
ID: 39238458
I get


             Exception calling "Delete" with "0" argument(s): "Generic failure"
 


on the

          $comp.psbase.delete()


line
0
 

Author Comment

by:rookie_b
ID: 39238478
Now I am getting this:

Method invocation failed because [System.Management.Automation.PSInternalMemberSet] doesn't contain a method named 'delete'.
At line:39 char:1
+ $comp.psbase.delete()
+ ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (delete:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
0
 
LVL 22

Accepted Solution

by:
Haresh Nikumbh earned 500 total points
ID: 39238505
check it out this


#// required parameters

$SCCMServer = "SCCMServerName"

$sitename = "SCCMSiteName"

$computername = “PCName”

 

#// get resourceID of $computername

$resID = Get-WmiObject -computername $SCCMServer -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

{

    #// get the specified computerobject based on found ID

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

 

    #// delete it

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

Featured Post

Webinar: MongoDB® Index Types

Join Percona’s Senior Technical Services Engineer, Adamo Tonete as he presents “MongoDB Index Types, How, When and Where Should They be Used?” on Wednesday, July 12, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7).

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Popular third-party chat platforms like Slack, Discord, and Telegram are just a few of the many new productivity applications that are being hijacked by cybercriminals to create command-and-control (C&C) communications infrastructures for their malw…
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question