Solved

Trouble deleting a computer from SCCM 2012

Posted on 2013-06-11
10
2,926 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
Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

 
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

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

Suggested Solutions

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This article was originally published on Monitis Blog, you can check it  here .   Some years back, I worked as the CTO.  During my tenure, I had a head of IT support reporting to me.  He did his job quite well and had a commendable sense of duty…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

726 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