Cleanup in AD deleted devices via Powershell in ConfigMgr 2012 SP1

April 26, 2013 § Leave a comment

This script checks every device that is available in the All Systems c

Verified on the following platforms / OS

Windows Server 2012 =Yes

Windows Server 2008 R2 = Yes

Windows Server 2008 = Yes

Windows Server 2003 =No

Windows 8 = Yes

Windows 7 = Yes

Windows Vista = No

Windows XP = Yes

Windows 2000  = No

ollection if it is still available in Active Directory and it will clean up devices that comply to the certain rules. (read more for the rules)

RemoveDeletedDevicesFromConfigMgr2012SP1_v0_2.ps1

Current version: v0.2, release date 04/25/2013

The script checks every device that is available in the All Systems collection if it is still available in Active Directory and it will delete devices that comply to the following rules:

  • The device is available in ConfigMgr but not in Active Directory
  • The device is not a member of a Workgroup
  • The device is not a mobile device
  • The device is not manually imported for Operating System Deployment

Before you are able to use the script you need to configure some variables, you can find these just beneath the comments in the header of the script;

  • $sitecode = “<sitecode>:”
  • $sitecode = “PS1:”
  • $installdrive = “<ConfigMgr Admin Console installation>
  • $installdrive = “C:
  • $loglocation = “<loglocation>
  • $loglocation = “D:\Logfiles\
  • $localdomain = “<domainname>
  • $localdomain = “ConfigMgrLab
  • $maxdevices = <maximum number of devices in your ConfigMgr environment>
  • $maxdevices = 2000

Prerequisites to use this script are:

  • Powershell 3.0 (x86)
  • System Center 2012 Configuration Manager 2012 SP1
  • Active Directory Module for Windows PowerShell

The script RemoveDeletedDevicesFromConfigMgr2012SP1.ps1 uses the cmdlet Get-CMDevices to retrieve the information about the devices from Configuration Manager. After checking if the device is available in Active Directory, part of a workgroup, part of an other domain or mobile device the Remove-CMDevices cmdlet will be used to remove the device from Configuration Manager. Together with the log function of fellow Configuration Manager MVP Kaido Järvemets (http://www.cm12sdk.net) this script will log also if a devices is deleted or why a device is preserved. The script will check the device in Configuration Manager and report back which device does not have an account in the Active Directory you configured.

New in v0.2:

  • Ability to set the Maximum Query Result Size of ConfigMgr 2012 SP1, by default this is 1000 items

  • Fixed little bug while searching in AD for objects give back a number higher than 1. (more AD objects with the same name)

THANKS TO the Master –>Peter Daalmans

Do some Spring Cleaning to your SCCM All Systems Collection from AD.

PowerShell – One Key to the Automation of the Data Center

 

Isvet Laclaustra

Leave a comment

What’s this?

You are currently reading Cleanup in AD deleted devices via Powershell in ConfigMgr 2012 SP1 at Isvet_JR.

meta