SCSM how to change assigned to of an incident from powershell

SCSM how to change assigned to of an incident from powershell.

I want to change Incident assignee from powershell.

March 25th, 2013 6:51am

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

Free Windows Admin Tool Kit Click here and download it now
March 25th, 2013 10:05pm

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

March 25th, 2013 10:05pm

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

Free Windows Admin Tool Kit Click here and download it now
March 25th, 2013 10:05pm

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'
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.WorkItem.TroubleTicketResolvedByUser$

#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

#Retrieve AssignedTo User property you want (I was looking for DisplayName

$AssignedToUserDisplayName = $AssignedToUser.DisplayName

#Echo Assigned User DisplayName to the screen (for purposes of this example)

$AssignedToUserDisplayName

$AssignedUserObjectRelClass = Get-SCSMRelationshipClass -name System.WorkItemAssignedToUser
$AssignedUser = Get-SCSMRelatedObject -SMObject $IR -Relationship $AssignedUserObjectRelClass

#$PropertyHash = @{"AssignedTo" = $AssignedtoUser}
$IR | Set-SCSMObject -PropertyHashTable @{"AssignedTo" = $AssignedTo.DisplayName}

 
March 28th, 2013 8:09am

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

Free Windows Admin Tool Kit Click here and download it now
April 4th, 2013 9:48pm

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




  • Edited by fapw 16 hours 31 minutes ago
  • Proposed as answer by fapw 16 hours 30 minutes ago
March 16th, 2015 10:42am

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




  • Edited by fapw Monday, March 16, 2015 2:40 PM
  • Proposed as answer by fapw Monday, March 16, 2015 2:42 PM
Free Windows Admin Tool Kit Click here and download it now
March 16th, 2015 2:40pm

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




  • Edited by fapw Monday, March 16, 2015 2:40 PM
  • Proposed as answer by fapw Monday, March 16, 2015 2:42 PM
March 16th, 2015 2:40pm

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




  • Edited by fapw Monday, March 16, 2015 2:40 PM
  • Proposed as answer by fapw Monday, March 16, 2015 2:42 PM
Free Windows Admin Tool Kit Click here and download it now
March 16th, 2015 2:40pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics