Today I needed to generate a bunch of test data in a hurry.  How about using SMLets for that!? Smile  No problem!  In fact that is part of why we created SMLets was to do data generation for tests quickly and easily.

Here is an example of how to do it using the New-SCSMObject to create some incidents.

First get the incident class as a variable:

$incidentclass = get-scsmclass -name system.workitem.incident$

Then get the urgency medium and impact medium enumeration values since impact and urgency are required properties and store those as variables:

$impmed = Get-SCSMEnumeration -Name System.WorkItem.TroubleTicket.ImpactEnum.Medium

$urgmed = Get-SCSMEnumeration -Name System.WorkItem.TroubleTicket.UrgencyEnum.Medium

Now we just need to generate as many incidents as we need (in this case I did 1000):

foreach($i in 1..1000){New-SCSMOBject -Class $incidentclass -PropertyHashtable (@{Title = "Test $i"; Urgency = $urgmed; Impact = $impmed})}

The PropertyHashtable takes a Hashtable as a value. In this case I am creating the hashtable right there inline but it could be passed as a variable too.  All you need to do here is use the PropertyName on the left hand side of each hashtable pair and a value on the right hand side.  Separate each pair in the hashtable using a semi colon.  More information on creating hashtables in PowerShell can be found here:http://technet.microsoft.com/en-us/library/ee692803.aspx

This is what it looks like all put together:

image

On my test system it took about 45 seconds to create 1000 incidents this way.  Nice! Smile