Powershell Creation of SR from Template - Setting Request Offering
I've scripted the automatic creation of an SR based on a template using powershell with the help of:
- https://gallery.technet.microsoft.com/Submit-SCSM-Request-22b0488c
- http://blog.coretech.dk/mme/set-scsmtemplatewithactivities-powershell-script/
Any ideas?
Best Answer
-
john_doyle Cireson Support Ninja IT Monkey ✭✭✭✭Hi David,
After committing the changes to the properties, you can add this code:
# commit them
$TemplateObjects | % {$_ | Set-SCSMObject -PropertyHashtable $PropertyCollection[$_.get_id().Guid] -ComputerName $ComputerName}
#new code to add Request Offering relationship
$relClass = Get-SCSMRelationshipClass -Id 2730587f-3d88-a4e4-42d8-08cf94535a6e
$proj = Get-SCSMTypeProjection System.WorkItem.ServiceRequestPortalProjection
$SRID = $RequestObject.Id
$SRRequest = Get-SCSMObjectProjection -Projection $proj -filter "Id -eq $SRID"
$SRRequest.__base.Add($RequestOffering.Object,$relClass.Target)
$SRRequest.__base.Commit()
3
Answers
https://social.technet.microsoft.com/Forums/systemcenter/en-US/8245b062-8636-4228-b1a1-9300683fffb7/using-newscsmrelationshipobject-to-create-systemworkitemrelatestorequestoffering?forum=customization
After committing the changes to the properties, you can add this code:
# commit them
$TemplateObjects | % {$_ | Set-SCSMObject -PropertyHashtable $PropertyCollection[$_.get_id().Guid] -ComputerName $ComputerName}
#new code to add Request Offering relationship
$relClass = Get-SCSMRelationshipClass -Id 2730587f-3d88-a4e4-42d8-08cf94535a6e
$proj = Get-SCSMTypeProjection System.WorkItem.ServiceRequestPortalProjection
$SRID = $RequestObject.Id
$SRRequest = Get-SCSMObjectProjection -Projection $proj -filter "Id -eq $SRID"
$SRRequest.__base.Add($RequestOffering.Object,$relClass.Target)
$SRRequest.__base.Commit()
We are now looking to create a template using powershell as a precursor to creating a request off this template (as per above).
You can create a shell for the template using SMLets: New-SCSMObjectTemplate but I've been unable to find any way of setting / adding the properties and objects within the template given these templates are management pack objects, other than by editing the XML. Actually you can set them by getting the objects property / object collection and setting the properties but how do you save these updates back into the template itself (as opposed to applying the template to another object / projection via Set-SCSMObjectTemplate).
Has anyone achieved this?