Solved

Trouble deleting a computer from SCCM 2012

Posted on 2013-06-11
10
2,833 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
 
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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is this Task? 4 86
How to upgrade SCCM 2012 r2 to SCCM 2016 4 71
Undo a Print Server Setup 5 74
adding more drive space to the server 5 28
One of the most frustrating experiences a help desk technician will ever encounter is when a customer comes to them with a solution of their own invention and expects the tech to implement it. This often happens when people with a little bit of tech…
You may have a outside contractor who comes in once a week or seasonal to do some work in your office but you only want to give him access to the programs and files he needs and keep privet all other documents and programs, can you do this on a loca…
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now