Solved

Trouble deleting a computer from SCCM 2012

Posted on 2013-06-11
10
2,790 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Are your corporate email signatures appalling?

Is it scary how unprofessional your email signatures look? Do users create their own terrible designs and give themselves stupid job titles? You can make this a lot easier for yourself by choosing an email signature management solution from Exclaimer today.

Join & Write a Comment

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
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 tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

746 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

13 Experts available now in Live!

Get 1:1 Help Now