Removing Disabled Computer Accounts from SCCM with PowerShell

7 thoughts on “Removing Disabled Computer Accounts from SCCM with PowerShell

  1. Thanks for the script, I ran this in my environment and it purged a few computers as expected. When I re-ran the script I get an error below…

    Exception calling “AddRange” with “1” argument(s): “Collection cannot be null.
    Parameter name: c”
    At C:\Users\administrator.VAND1\Desktop\PowerShell Scripts\CM-ComputerCleanup.ps1:134 char:28
    + $DeletedRecords.AddRange($($NotEnabledDevices| foreach {
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentNullException

    This is probably happening because there are no entries returned the second time the script is invoked. Is there a way to trap this error and have the execution of the code exit out without errors if there are no hits?

  2. Hi. Very nice work. Would there be a way to specify the domain in the case of multiple trusted / Untrusted forests?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s