Blog Post

System Center Blog
2 MIN READ

Using SMLets Beta 3 Post #3–Using Set-SCSMObject to Bulk Update Properties on Objects

System-Center-Team's avatar
Feb 15, 2019
First published on TECHNET on Apr 22, 2011

This is a continuation in a series of blog posts on using SMLets Beta 3. Previous blog posts in this series:

Remember how I was saying the Set-SCSMObject cmdlet was really powerful?  Let’s see an example of using Set-SCSMObject to set multiple property values on multiple objects at the same time.  Here’s the scenario..  We have decided to move our internal line of business application “HRWeb” to the cloud.  As a result we are retiring all of the dusty HRWeb IIS servers since the front end will now be run out of Azure.  To retire these computers we need to change the asset status on them to ‘Retired’ and add a note to the computer record.  Let’s say there were 15 of these servers.  That could take awhile doing it by hand in the UI. But not to fear because we have SMLets!

To start off with here is what the computer record looks like:

First, as always we import the SMLets module:

Import-Module SMLets

Then, we need to get the objects we want to update using Get-SCSMObject and its buddy cmdlet Get-SCSMClass as we have seen in the previous two posts:

$HRWebServers = Get-SCSMObject -Class (Get-SCSMClass -Name Microsoft.Windows.Computer$) -Filter "PrincipalName -like HRWEBIIS*"

Then we need to get the ‘Retired’ asset status enumeration:

$RetiredEnum = Get-SCSMEnumeration -Name System.ConfigItem.AssetStatusEnum.Retired$

Then we create a hashtable of the properties and the values we want to update:

$PropertyHash = @{"AssetStatus" = $RetiredEnum; "Notes" = "The HRWeb servers have been retired as part of the move to the cloud"}

Lastly, we pipe our objects we want to update to Set-SCSMObject and pass the hashtable as a parameter value to the –PropertyHashtable:

$HRWebServers | Set-SCSMObject -PropertyHashtable $PropertyHash

Bam!  We just updated 15 records with two property values in less than a minute.  It could just as easily have been tens of thousands of records.  That’s the power of PowerShell and SMLets!

Here’s the whole script:

Import-Module SMLets
$HRWebServers = Get-SCSMObject -Class (Get-SCSMClass -Name Microsoft.Windows.Computer$) -Filter "PrincipalName -like HRWEBIIS*"
$RetiredEnum = Get-SCSMEnumeration -Name System.ConfigItem.AssetStatusEnum.Retired$
$PropertyHash = @{"AssetStatus" = $RetiredEnum; "Notes" = "The HRWeb servers have been retired as part of the move to the cloud"}
$HRWebServers | Set-SCSMObject -PropertyHashtable $PropertyHash

And a screenshot of the script for easier reading:

Updated Mar 11, 2019
Version 4.0
No CommentsBe the first to comment