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

Published Feb 15 2019 05:57 AM 1,032 Views
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:

%3CLINGO-SUB%20id%3D%22lingo-sub-342952%22%20slang%3D%22en-US%22%3EUsing%20SMLets%20Beta%203%20Post%20%233%E2%80%93Using%20Set-SCSMObject%20to%20Bulk%20Update%20Properties%20on%20Objects%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-342952%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20TECHNET%20on%20Apr%2022%2C%202011%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EThis%20is%20a%20continuation%20in%20a%20series%20of%20blog%20posts%20on%20using%20SMLets%20Beta%203.%20Previous%20blog%20posts%20in%20this%20series%3A%3C%2FP%3E%0A%20%20%3CUL%3E%0A%20%20%20%3CLI%3E%3CA%20href%3D%22http%3A%2F%2Fblogs.technet.com%2Fb%2Fservicemanager%2Farchive%2F2011%2F04%2F21%2Fusing-smlets-beta-3-post-1-using-get-scsmobject-get-scsmclass-to-dump-data-from-scsm.aspx%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20Using%20SMLets%20Beta%203%20Post%20%231%20%E2%80%93%20Using%20Get-SCSMObject%2C%20Get-SCSMClass%20to%20Dump%20Data%20from%20SCSM%20%3C%2FA%3E%3C%2FLI%3E%0A%20%20%20%3CLI%3E%3CA%20href%3D%22http%3A%2F%2Fblogs.technet.com%2Fb%2Fservicemanager%2Farchive%2F2011%2F04%2F21%2Fusing-smlets-beta-3-post-2-using-get-scsmenumeration-get-scsmrelationshipobject-get-scsmrelationshipclass-to-automatically-resolve-incidents-when-all-child-activities-are-completed.aspx%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20Using%20SMLets%20Beta%203%20Post%20%232%E2%80%93Using%20Get-SCSMEnumeration%2C%20Get-SCSMRelationshipObject%2C%20Get-SCSMRelationshipClass%20to%20Automatically%20Resolve%20Incidents%20When%20All%20Child%20Activities%20Are%20Completed%20%3C%2FA%3E%3C%2FLI%3E%0A%20%20%3C%2FUL%3E%0A%20%20%3CP%3ERemember%20how%20I%20was%20saying%20the%20Set-SCSMObject%20cmdlet%20was%20really%20powerful%3F%26nbsp%3B%20Let%E2%80%99s%20see%20an%20example%20of%20using%20Set-SCSMObject%20to%20set%20multiple%20property%20values%20on%20multiple%20objects%20at%20the%20same%20time.%26nbsp%3B%20Here%E2%80%99s%20the%20scenario..%26nbsp%3B%20We%20have%20decided%20to%20move%20our%20internal%20line%20of%20business%20application%20%E2%80%9CHRWeb%E2%80%9D%20to%20the%20cloud.%26nbsp%3B%20As%20a%20result%20we%20are%20retiring%20all%20of%20the%20dusty%20HRWeb%20IIS%20servers%20since%20the%20front%20end%20will%20now%20be%20run%20out%20of%20Azure.%26nbsp%3B%20To%20retire%20these%20computers%20we%20need%20to%20change%20the%20asset%20status%20on%20them%20to%20%E2%80%98Retired%E2%80%99%20and%20add%20a%20note%20to%20the%20computer%20record.%26nbsp%3B%20Let%E2%80%99s%20say%20there%20were%2015%20of%20these%20servers.%26nbsp%3B%20That%20could%20take%20awhile%20doing%20it%20by%20hand%20in%20the%20UI.%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F76961iAA3BD16222EBD760%22%20%2F%3EBut%20not%20to%20fear%20because%20we%20have%20SMLets!%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F76962i8A7A4CD9C7EE2D9A%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3ETo%20start%20off%20with%20here%20is%20what%20the%20computer%20record%20looks%20like%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F76963i6E38E69E71BE945C%22%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F76964i91038F02F0F2F411%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3EFirst%2C%20as%20always%20we%20import%20the%20SMLets%20module%3A%3C%2FP%3E%0A%20%20%3CP%3EImport-Module%20SMLets%3C%2FP%3E%0A%20%20%3CP%3EThen%2C%20we%20need%20to%20get%20the%20objects%20we%20want%20to%20update%20using%20Get-SCSMObject%20and%20its%20buddy%20cmdlet%20Get-SCSMClass%20as%20we%20have%20seen%20in%20the%20previous%20two%20posts%3A%3C%2FP%3E%0A%20%20%3CP%3E%24HRWebServers%20%3D%20Get-SCSMObject%20-Class%20(Get-SCSMClass%20-Name%20Microsoft.Windows.Computer%24)%20-Filter%20%22PrincipalName%20-like%20HRWEBIIS*%22%3C%2FP%3E%0A%20%20%3CP%3EThen%20we%20need%20to%20get%20the%20%E2%80%98Retired%E2%80%99%20asset%20status%20enumeration%3A%3C%2FP%3E%0A%20%20%3CP%3E%24RetiredEnum%20%3D%20Get-SCSMEnumeration%20-Name%20System.ConfigItem.AssetStatusEnum.Retired%24%3C%2FP%3E%0A%20%20%3CP%3EThen%20we%20create%20a%20hashtable%20of%20the%20properties%20and%20the%20values%20we%20want%20to%20update%3A%3C%2FP%3E%0A%20%20%3CP%3E%24PropertyHash%20%3D%20%40%7B%22AssetStatus%22%20%3D%20%24RetiredEnum%3B%20%22Notes%22%20%3D%20%22The%20HRWeb%20servers%20have%20been%20retired%20as%20part%20of%20the%20move%20to%20the%20cloud%22%7D%3C%2FP%3E%0A%20%20%3CP%3ELastly%2C%20we%20pipe%20our%20objects%20we%20want%20to%20update%20to%20Set-SCSMObject%20and%20pass%20the%20hashtable%20as%20a%20parameter%20value%20to%20the%20%E2%80%93PropertyHashtable%3A%3C%2FP%3E%0A%20%20%3CP%3E%24HRWebServers%20%7C%20Set-SCSMObject%20-PropertyHashtable%20%24PropertyHash%3C%2FP%3E%0A%20%20%3CP%3EBam!%26nbsp%3B%20We%20just%20updated%2015%20records%20with%20two%20property%20values%20in%20less%20than%20a%20minute.%26nbsp%3B%20It%20could%20just%20as%20easily%20have%20been%20tens%20of%20thousands%20of%20records.%26nbsp%3B%20That%E2%80%99s%20the%20power%20of%20PowerShell%20and%20SMLets!%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F76965i35FC8F6EA493056F%22%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F76966i46AAD7E0D891DB3E%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3EHere%E2%80%99s%20the%20whole%20script%3A%3C%2FP%3E%0A%20%20%3CP%3EImport-Module%20SMLets%20%3CBR%20%2F%3E%20%24HRWebServers%20%3D%20Get-SCSMObject%20-Class%20(Get-SCSMClass%20-Name%20Microsoft.Windows.Computer%24)%20-Filter%20%22PrincipalName%20-like%20HRWEBIIS*%22%20%3CBR%20%2F%3E%20%24RetiredEnum%20%3D%20Get-SCSMEnumeration%20-Name%20System.ConfigItem.AssetStatusEnum.Retired%24%20%3CBR%20%2F%3E%20%24PropertyHash%20%3D%20%40%7B%22AssetStatus%22%20%3D%20%24RetiredEnum%3B%20%22Notes%22%20%3D%20%22The%20HRWeb%20servers%20have%20been%20retired%20as%20part%20of%20the%20move%20to%20the%20cloud%22%7D%20%3CBR%20%2F%3E%20%24HRWebServers%20%7C%20Set-SCSMObject%20-PropertyHashtable%20%24PropertyHash%3C%2FP%3E%0A%20%20%3CP%3EAnd%20a%20screenshot%20of%20the%20script%20for%20easier%20reading%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F76967iE07126E1EEB01607%22%20%2F%3E%3C%2FP%3E%0A%20%0A%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-342952%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20TECHNET%20on%20Apr%2022%2C%202011%20This%20is%20a%20continuation%20in%20a%20series%20of%20blog%20posts%20on%20using%20SMLets%20Beta%203.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-342952%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESystem%20Center%20Service%20Manager%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Mar 11 2019 08:43 AM
Updated by: