Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Trouble deleting a computer from SCCM 2012

Posted on 2013-06-11
10
Medium Priority
?
3,269 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
  • 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
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

While Plesk offers many potential benefits to website administrators, including compatibility with Windows Server and other leading technologies, the company has also been working to differentiate it from other control panels for content management…
The Internet has made sending and receiving information online a breeze. But there is also the threat of unauthorized viewing, data tampering, and phoney messages. Surprisingly, a lot of business owners do not fully understand how to use security t…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
Suggested Courses

877 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