How to create CR and apply template?

Nov 17, 2010 at 11:01 AM
Edited Nov 17, 2010 at 11:59 AM

Hi Jim

I need  create new CR using smlets and apply CR template

I try this way

$class = Get-SCSMClass -name System.WorkItem.ChangeRequest$
$parameters = @{Title="New CR";ID="CR{0}";TemplateId="StandardChangeRequest"}
New-SCSMObject -Class $class -PropertyHashtable $parameters

In created CR I see TemplateId="StandardChangeRequest" but list of activity is empty.It means template not apply.

 I read but it is not clear for me :(
When I try

$SMDIR = "C:\Program Files\Microsoft System Center\Service Manager 2010"
$COREDLL = "${SMDIR}/SDK Binaries/Microsoft.EnterpriseManagement.Core.dll"

$EMG = new-object Microsoft.EnterpriseManagement.EnterpriseManagementGroup localhost
$tmp = $EMG.Templates.GetObjectTemplates()  | ?{$ -match "StandardChangeRequest"}
$classChangeRequest = $emg.EntityTypes.GetClass("E6C9CF6E-D7FE-1B5D-216C-C3F5D2C7670C")
$cemo = new-object Microsoft.EnterpriseManagement.Common.CreatableEnterpriseManagementObject($emg, $classChangeRequest)

I obtain error
Exception calling "ApplyTemplate" with "1" argument(s): "Only a template targeted at a class can be applied to a single object."


Nov 30, 2010 at 7:47 AM

Hi Alex,


I was facing a similar issue so switched to using an EnterpriseManagementObjectProjection instead of just a plain old EnterpiseManagementObject and it resolved the issue.

I'm a little pressed for time at the moment but if you want an example reply back and I'll post it.