Applying SR template using Powershell

Steve_O'ConnorSteve_O'Connor Customer IT Monkey ✭
edited July 2016 in Service Manager
Rather than putting every bit of software in as a Request Offering, I'm trying to leverarge the ConfigMgr Application Catalogue instead. So the scenario link to software catalogue, customer request application from there, ticket logged in SCSM for analyst to approve. Orchestrator does the work behind the scenes. Its all working fine until I realised there is no easy way to apply a SR template within orchestrator.

So with a bit of looking around, I have found various parts of scripts and ideas and come up with the below to apply a template as a run.net script action.

Import-Module SMlets

#Variable / Class Setup
$srClass = Get-SCSMClass -name System.WorkItem.ServiceRequest$
$srprior = Get-SCSMEnumeration -Name ServiceRequestPriorityEnum.Medium
$srurg = Get-SCSMEnumeration -Name ServiceRequestUrgencyEnum.Medium
$ararea = get-SCSMEnumeration -Name ServiceRequestAreaEnum.Software.Installation
$title = "Application Template Test 3"

#Service Request Arguements
$srargs = @{
Title = $title;
Urgency = $srurg;
Priority = $srprior;
ID = "SR{0}";
Area = $ararea;
Description = "Remove Test"
}


#Create Service Request
$newserviceRequest = New-SCSMOBject -Class $srClass -PropertyHashtable $srargs
$serviceRequestId = $newServiceRequest.ID

#Pause
Start-Sleep -s 40

#Get Projection & Object for Created Service Request
$srTypeProjection = Get-SCSMTypeProjection -name System.WorkItem.ServiceRequestProjection$
$SRProj = Get-scsmobjectprojection -ProjectionName $srTypeProjection.Name -filter “title -eq $title”

#Get Template
$template = Get-SCSMObjectTemplate -DisplayName "SC REQUEST: Software Request"
#Set Template
Set-SCSMObjectTemplate -Projection $SRProj -Template $template
}

It all works fine until we have to get the SR to apply template, its returning a null value:

Get-SCSMObjectProjection : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ProjectionName'. Specified method is not supported.
At line:33 char:52
+ $SRProj = Get-scsmobjectprojection -ProjectionName $srTypeProjection.Name -filte ...
+                                                    ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-SCSMObjectProjection], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,SMLets.GetSMObjectProjectionCommand
 
Set-SCSMObjectTemplate : Cannot bind argument to parameter 'Projection' because it is null.
At line:38 char:36
+ Set-SCSMObjectTemplate -Projection $SRProj -Template $template
+                                    ~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Set-SCSMObjectTemplate], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,SMLets.SetSCSMObjectTemplateCommand


I've tried several variations of the script and it always returns null at the get SR stage.

Really appreciate if anyone has any ideas?

Comments

Sign In or Register to comment.