Home Service Manager
Options

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<br><br>#Variable / Class Setup<br>$srClass = Get-SCSMClass -name System.WorkItem.ServiceRequest$<br>$srprior = Get-SCSMEnumeration -Name ServiceRequestPriorityEnum.Medium<br>$srurg = Get-SCSMEnumeration -Name ServiceRequestUrgencyEnum.Medium<br>$ararea = get-SCSMEnumeration -Name ServiceRequestAreaEnum.Software.Installation<br>$title = "Application Template Test 3"<br><br>#Service Request Arguements<br>$srargs = @{<br>Title = $title;<br>Urgency = $srurg;<br>Priority = $srprior;<br>ID = "SR{0}";<br>Area = $ararea;<br>Description = "Remove Test"<br>}<br><br><br>#Create Service Request<br>$newserviceRequest = New-SCSMOBject -Class $srClass -PropertyHashtable $srargs<br>$serviceRequestId = $newServiceRequest.ID<br><br>#Pause<br>Start-Sleep -s 40<br><br>#Get Projection & Object for Created Service Request<br>$srTypeProjection = Get-SCSMTypeProjection -name System.WorkItem.ServiceRequestProjection$<br>$SRProj = Get-scsmobjectprojection -ProjectionName $srTypeProjection.Name -filter “title -eq $title”<br><br>#Get Template<br>$template = Get-SCSMObjectTemplate -DisplayName "SC REQUEST: Software Request"<br>#Set Template<br>Set-SCSMObjectTemplate -Projection $SRProj -Template $template<br>}

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.<br>At line:33 char:52<br>+ $SRProj = Get-scsmobjectprojection -ProjectionName $srTypeProjection.Name -filte ...<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp;&nbsp;&nbsp; + CategoryInfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : InvalidArgument: (:) [Get-SCSMObjectProjection], ParameterBindingException<br>&nbsp;&nbsp;&nbsp; + FullyQualifiedErrorId : CannotConvertArgument,SMLets.GetSMObjectProjectionCommand<br>&nbsp;<br>Set-SCSMObjectTemplate : Cannot bind argument to parameter 'Projection' because it is null.<br>At line:38 char:36<br>+ Set-SCSMObjectTemplate -Projection $SRProj -Template $template<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ~~~~~~~<br>&nbsp;&nbsp;&nbsp; + CategoryInfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : InvalidData: (:) [Set-SCSMObjectTemplate], ParameterBindingValidationException<br>&nbsp;&nbsp;&nbsp; + 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.