SCSM how to change assigned to of an incident from powershell.
I want to change Incident assignee from powershell.
Technology Tips and News
SCSM how to change assigned to of an incident from powershell.
I want to change Incident assignee from powershell.
This assumes you have SMLets installed.
$incident = "IR3406" $username = "Lopez" $domain = "LAB" Import-Module SMLets $i = Get-SCSMObject (Get-SCSMClass System.WorkItem.Incident$) -Filter "Id -eq $incident" $u = Get-SCSMObject (Get-SCSMClass System.Domain.User$) | ?{$_.Domain -eq $domain -and $_.Username -eq $username} $r = Get-SCSMRelationshipClass System.WorkItemAssignedToUser$ Get-SCSMRelationshipObject -Relationship $r | ?{$_.SourceObject -eq $i} | Remove-SCSMRelationshipObject $n = New-SCSMRelationshipObject -Relationship $r -Source $i -Target $u -NoCommit $n.Commit() Remove-Module SMLets
This assumes you have SMLets installed.
$incident = "IR3406" $username = "Lopez" $domain = "LAB" Import-Module SMLets $i = Get-SCSMObject (Get-SCSMClass System.WorkItem.Incident$) -Filter "Id -eq $incident" $u = Get-SCSMObject (Get-SCSMClass System.Domain.User$) | ?{$_.Domain -eq $domain -and $_.Username -eq $username} $r = Get-SCSMRelationshipClass System.WorkItemAssignedToUser$ Get-SCSMRelationshipObject -Relationship $r | ?{$_.SourceObject -eq $i} | Remove-SCSMRelationshipObject $n = New-SCSMRelationshipObject -Relationship $r -Source $i -Target $u -NoCommit $n.Commit() Remove-Module SMLets
This assumes you have SMLets installed.
$incident = "IR3406" $username = "Lopez" $domain = "LAB" Import-Module SMLets $i = Get-SCSMObject (Get-SCSMClass System.WorkItem.Incident$) -Filter "Id -eq $incident" $u = Get-SCSMObject (Get-SCSMClass System.Domain.User$) | ?{$_.Domain -eq $domain -and $_.Username -eq $username} $r = Get-SCSMRelationshipClass System.WorkItemAssignedToUser$ Get-SCSMRelationshipObject -Relationship $r | ?{$_.SourceObject -eq $i} | Remove-SCSMRelationshipObject $n = New-SCSMRelationshipObject -Relationship $r -Source $i -Target $u -NoCommit $n.Commit() Remove-Module SMLets
Thanks for the reply what i am doing is. I want to set Resolved by user as Assigned to User. I am using following script to get resolved by user display name now let me know how to set it as Assignedto user.
$ID='IR424'Hi Shumail,
I've modified your script to set the "resolved by user" to the same user as the "assigned user".
$ID='IR2185' Import-module smlets -Force #Retrieve the target workitem class (Incident in this case) and assign to a variable $IRClass = get-scsmclass -name System.WorkItem.Incident$ #Retrieve the relationship that connects the assigned user to the work item and assign to a variable $AssignedToRel = get-scsmrelationshipclass -name System.WorkItemAssignedToUser$ #retrieve the incident for which you want to retrieve the assigned user and assign to a variable $IR = get-SCSMObject -class $IRClass -Filter "ID -eq $ID" #Retrieve the AssignedTo User for the incident and assign to a variable $AssignedToUser = Get-SCSMRelatedObject -SMObject $IR -Relationship $AssignedToRel #Get ResolvedBy relationship $resolvedByRel = Get-SCSMRelationshipClass -name System.WorkItem.TroubleTicketResolvedByUser$ #Set resolved by New-SCSMRelationshipObject -Relationship $resolvedByRel -Source $IR -Target $AssignedToUser -Bulk
It worked with name -eq $ID:
$I = Get-SCSMObject -Class $IncidentClass -Filter "name -eq $ID"
ID -eq $ID bring to error:
Get-SCSMObject : Id='32' -- Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). At C:\Users\VorchukovM\Desktop\Implementation\DeleteAssignToUser.ps1:16 char:13 + $Incident = Get-SCSMObject -Class $IncidentClass -Filter "ID -eq $ID" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-SCSMObject], UnknownDatabaseException + FullyQualifiedErrorId : Microsoft.EnterpriseManagement.Common.UnknownDatabaseException,SMLets.GetSMObjectCommand
It worked with name -eq $ID:
$I = Get-SCSMObject -Class $IncidentClass -Filter "name -eq $ID"
ID -eq $ID bring to error:
Get-SCSMObject : Id='32' -- Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). At C:\Users\VorchukovM\Desktop\Implementation\DeleteAssignToUser.ps1:16 char:13 + $Incident = Get-SCSMObject -Class $IncidentClass -Filter "ID -eq $ID" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-SCSMObject], UnknownDatabaseException + FullyQualifiedErrorId : Microsoft.EnterpriseManagement.Common.UnknownDatabaseException,SMLets.GetSMObjectCommand
It worked with name -eq $ID:
$I = Get-SCSMObject -Class $IncidentClass -Filter "name -eq $ID"
ID -eq $ID bring to error:
Get-SCSMObject : Id='32' -- Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). At C:\Users\VorchukovM\Desktop\Implementation\DeleteAssignToUser.ps1:16 char:13 + $Incident = Get-SCSMObject -Class $IncidentClass -Filter "ID -eq $ID" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-SCSMObject], UnknownDatabaseException + FullyQualifiedErrorId : Microsoft.EnterpriseManagement.Common.UnknownDatabaseException,SMLets.GetSMObjectCommand
It worked with name -eq $ID:
$I = Get-SCSMObject -Class $IncidentClass -Filter "name -eq $ID"
ID -eq $ID bring to error:
Get-SCSMObject : Id='32' -- Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). At C:\Users\VorchukovM\Desktop\Implementation\DeleteAssignToUser.ps1:16 char:13 + $Incident = Get-SCSMObject -Class $IncidentClass -Filter "ID -eq $ID" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-SCSMObject], UnknownDatabaseException + FullyQualifiedErrorId : Microsoft.EnterpriseManagement.Common.UnknownDatabaseException,SMLets.GetSMObjectCommand