Archiving Computers in MEMCM

Posted on May 21, 2022

I work with some serious and talented people. Working with serious and talented (and seriously talented) people is, essentially, my mission in life. The take is that I’m just learning this constantly. The give is that I’m frequently challenged in many ways that include time, talent, energy, and flexibility among others. I got a message about our SCCM (MEMCM) server sending out a significant amount of DNS queries to hostnames which, as far as anyone can tell, have no business being queried. It’s a bit of a mystery to me, so let’s get digging.

First Things First

I got a list of hostnames. They aren’t FQDN and that can complicate things as we have several domains on our network however that’s some legacy thinking. I had already made a script to somewhat comprehensively get information from SCCM, AD, and other resources on our network but it was, at this point, years old and had partially been corrupted by one of my computers at some point so there was precious little reason to carry it forward. Additionally, it was doing much more than I wanted or needed. So throw that away and let’s start very simple.

$computers = Get-Content 'c:\users\mark\Downloads\sccm.txt'
$output = @() #dangerously generic variable naming

This is just the housekeeping stuff. Now, there’s another crucial thing here and that is to connect to SCCM via PowerShell session. The SCCM console (MEMCM console–I don’t think I’ll ever live that down) has that set up for you if you click on the blue arrow menu on the top left (the approximation of The Ribbon). You can start a PowerShell session through ISE and that should give you the code that you need to include to get that going. I copy it from here because it has changed over the years and has become a bit more accepting and flexible.

You’ll note that you can enable verbosity as you load the PS module and, well, I’m pretty into it so I did. It will also let you know that the script is advancing without needing to have any print to screen commands, if you’re lazy like I am. PowerShell has the concept of PowerShell Drives, and I know this is maybe more recent than the 5.x we are mostly running on our Windows systems but it holds true, and the MEMCM Site (a concept with which you should be familiar with at this point) is a PSDrive just like the Registry can be.

cd CCM: #assuming that your site code is CCM

Excellent. Now, if you did enable the verbosity when loading the MEMCM PS modules you would have noticed that it imports a whole slew of commandlets. We’re primarily concerned with one easy one at this moment in time.

Get-CMDevice -Name computername

That’s it. That’s all you’ll need as far as CCM commandlets but, again, there’s a lot of them and some are incredibly useful.

Analysis

What you want to do is have a variable like $output = @() which is a nifty array. Then you’ll iterate over all of the hostnames and add the CM device to the array. From here you can examine them by selecting some of the more useful fields like Name, Domain, LastActiveTime, LastClientTime, LastHardwareScan, LastLogonUser, MACAddress, SerialNumber to view as they’ll give you some idea of how active this device is.

If you have a really strong asset management process, then it’s cruise control but for some organizations you do need to go back and check out what’s up with some machines. In my case, the site server was popping off a bunch of requests for the devices but they weren’t in service anymore and were marked off in other systems or just stuffed in a drawer. Having that connectivity to all your systems in terms of asset management is several posts for another day but, needless to say, it is important.

From here, use the Swiss army knife of IT that is Excel (or not, I’m not your supervisor) to select what you want to get rid of. Export that csv and then we’re off to the races.

Execution

Use Import-CSV to import that CSV into a neat array of objects. Then there’s just one more cmdlet you need, and that is Remove-CMDevice. You can definitely use the Name attribute with that cmdlet and, if you don’t want to confirm each one, use the force flag.

$csv = Import-CSV '.\selections.csv\'
foreach ($record in $csv) {
	Remove-CMDevice -DeviceName $record.Name -Force #don't ask for confirmation
}

So that’s really it. As always, test. I happened to have many computers that did not have a LastActiveTime so those got purged. They were correlated through several sources to no longer be active so I had no real negative implications but that may be different where you are.

Be nice.

Hi, this post was checked with vale which is a content-aware linter. It was checked using the Microsoft style as well as some rules that I made. A summary of those results is below. More details as to how this was put together check out this post. This post had: 8 errors, 34 warnings and 0 suggestions For details on the linting of this post
 ./content/posts/archiving-computers-sccm.md
 9:1     warning  Use first person (such as 'I    Microsoft.FirstPerson  
                  ') sparingly.                                          
 9:86    warning  Consider removing 'seriously'.  Microsoft.Adverbs      
 9:130   warning  Use first person (such as       Microsoft.FirstPerson  
                  'my') sparingly.                                       
 9:167   warning  Use first person (such as       Microsoft.FirstPerson  
                  'I'm') sparingly.                                      
 9:219   warning  Use first person (such as       Microsoft.FirstPerson  
                  'I'm') sparingly.                                      
 9:322   warning  Use first person (such as ' I   Microsoft.FirstPerson  
                  ') sparingly.                                          
 9:345   warning  Try to avoid using              Microsoft.We           
                  first-person plural like                               
                  'our'.                                                 
 9:523   warning  Use first person (such as       Microsoft.FirstPerson  
                  'me') sparingly.                                       
 9:530   warning  Try to avoid using              Microsoft.We           
                  first-person plural like                               
                  'let's'.                                               
 12:1    warning  Use first person (such as 'I    Microsoft.FirstPerson  
                  ') sparingly.                                          
 12:79   warning  Try to avoid using              Microsoft.We           
                  first-person plural like 'we'.                         
 12:79   error    Use 'we've' instead of 'we      Microsoft.Contractions 
                  have'.                                                 
 12:106  warning  Try to avoid using              Microsoft.We           
                  first-person plural like                               
                  'our'.                                                 
 12:236  error    More than 3 commas!             marktoso.TresComas     
 12:265  warning  Try to avoid using              Microsoft.We           
                  first-person plural like                               
                  'our'.                                                 
 12:322  warning  Consider removing 'partially'.  Microsoft.Adverbs      
 12:357  warning  Use first person (such as       Microsoft.FirstPerson  
                  'my') sparingly.                                       
 12:482  warning  Use first person (such as ' I   Microsoft.FirstPerson  
                  ') sparingly.                                          
 12:526  warning  Try to avoid using              Microsoft.We           
                  first-person plural like                               
                  'let's'.                                               
 12:538  warning  Consider removing 'very'.       Microsoft.Adverbs      
 17:82   error    Use 'that's' instead of 'that   Microsoft.Contractions 
                  is'.                                                   
 17:441  warning  Use first person (such as ' I   Microsoft.FirstPerson  
                  ') sparingly.                                          
 19:80   warning  Use first person (such as       Microsoft.FirstPerson  
                  'I'm') sparingly.                                      
 19:101  warning  Use first person (such as ' I   Microsoft.FirstPerson  
                  ') sparingly.                                          
 19:237  warning  Use first person (such as ' I   Microsoft.FirstPerson  
                  ') sparingly.                                          
 19:416  warning  Use first person (such as ' I   Microsoft.FirstPerson  
                  ') sparingly.                                          
 19:463  warning  Try to avoid using              Microsoft.We           
                  first-person plural like 'we'.                         
 19:463  error    Use 'we're' instead of 'we      Microsoft.Contractions 
                  are'.                                                  
 19:488  warning  Try to avoid using              Microsoft.We           
                  first-person plural like                               
                  'our'.                                                 
 23:151  warning  Try to avoid using              Microsoft.We           
                  first-person plural like 'We'.                         
 30:110  warning  Consider using 'all' instead    Microsoft.Wordiness    
                  of 'all of'.                                           
 30:211  warning  Consider using 'some' instead   Microsoft.Wordiness    
                  of 'some of the'.                                      
 32:15   warning  Consider removing 'really'.     Microsoft.Adverbs      
 32:177  warning  Use first person (such as       Microsoft.FirstPerson  
                  'my') sparingly.                                       
 32:485  error    Use 'it's' instead of 'it is'.  Microsoft.Contractions 
 34:43   error    Use 'that's' instead of 'that   Microsoft.Contractions 
                  is'.                                                   
 34:66   warning  Use first person (such as       Microsoft.FirstPerson  
                  'I'm') sparingly.                                      
 34:155  warning  Try to avoid using              Microsoft.We           
                  first-person plural like 'we'.                         
 37:115  error    Use 'that's' instead of 'that   Microsoft.Contractions 
                  is'.                                                   
 45:11   warning  Consider removing 'really'.     Microsoft.Adverbs      
 45:78   error    Use 'didn't' instead of 'did    Microsoft.Contractions 
                  not'.                                                  
 45:201  warning  Use first person (such as ' I   Microsoft.FirstPerson  
                  ') sparingly.                                          
 49:210  warning  Use first person (such as ' I   Microsoft.FirstPerson  
                  ') sparingly.                                          

8 errors, 35 warnings and 0 suggestions in 1 file.