SCSM SMLets Assinged to Field

Jul 21, 2011 at 11:35 AM

Hi all,

I was trying to use use the NEW-SCSMincident to fill up the Assigend to Field with no Luck, does anyone done that before ?

 

Kind Regards,

Moe.

 

 

Developer
Jul 26, 2011 at 12:16 AM

New-SCSMIncident doesn't allow you to set the AssignedTo field, you need to use Set-IncidentUser to do that

 

jim

Aug 1, 2011 at 9:24 PM

Hi,

I am getting the following error when i use hte Set-IncidentUser :

 

Multiple ambiguous overloads found for "Add" and the argument count: "2".
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\smlets\Scripts\Set-IncidentUser.ps1:64 char:26
+             $Incident.Add <<<< (($AssignedToUser -as $EMOT) ,$ASSIGNEDTORELATIONSHIP.Target)
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

 

any advice please ???

Developer
Aug 1, 2011 at 9:37 PM

i'm sorry, but there's not enough information in this error to help you.

Could you please include the command line or script that you are using.

Aug 1, 2011 at 9:39 PM

hi,

this is the command

 

get-scsmincident -title "13%" | set-incidentuser -assignedto "jab\administrator"

 

jab is the domain

administrator is the user.

 

any advice please ... thanks a lot .

Moe.

Developer
Aug 1, 2011 at 9:58 PM

This can occur if the user is not found or some other trouble. You can remove the comment from line 52 in the Set-IncidentUser script which will allow you to see what the Get-User function found for the user. If you don't see any output, it means that no user was found which could cause this problem.

Aug 1, 2011 at 10:39 PM

Hi - I still have the same problem.

the user is there i have already used it with the New-SCSMIncident Command .. with the -affecteduser switch and it works great ... just the set-incidentuser is causing this problem ... do you think i might be the pipe feed in to the command.

 

i have tired to use the get-SCSMincident command then pipe it into set-SCSMincident to attached a file and it worked great as well..

 

 

Thanks for the help, your advice is highly appreciated.

 

Kind Regards,

Moe,

Aug 1, 2011 at 10:40 PM

Hi - I still have the same problem.

the user is there i have already used it with the New-SCSMIncident Command .. with the -affecteduser switch and it works great ... just the set-incidentuser is causing this problem ... do you think i might be the pipe feed in to the command.

 

i have tried to use the get-SCSMincident command then pipe it into set-SCSMincident to attached a file and it worked great as well..

 

 

Thanks for the help, your advice is highly appreciated.

 

Kind Regards,

Moe,

Aug 1, 2011 at 10:41 PM

Hi - I still have the same problem.

the user is there i have already used it with the New-SCSMIncident Command .. with the -affecteduser switch and it works great ... just the set-incidentuser is causing this problem ... do you think i might be the pipe feed in to the command.

 

i have tried to use the get-SCSMincident command then pipe it into set-SCSMincident to attached a file and it worked great as well..

 

 

Thanks for the help, your advice is highly appreciated.

 

Kind Regards,

Moe,

Aug 1, 2011 at 10:46 PM

Hi - I still have the same problem.

the user is there i have already used it with the New-SCSMIncident Command .. with the -affecteduser switch and it works great ... just the set-incidentuser is causing this problem ... do you think i might be the pipe feed in to the command.

 

i have tried to use the get-SCSMincident command then pipe it into set-SCSMincident to attached a file and it worked great as well..

 

 

Thanks for the help, your advice is highly appreciated.

 

Kind Regards,

Developer
Aug 1, 2011 at 10:49 PM

i'm sorry, I have no idea what's going wrong and can't duplicate the problem that you are seeing the script works fine for me. You should follow standard script debugging methods such as tracing and determine whether the the $AssignedToUser (line 63 in the script) is being set correctly, then determine whether the incident object is correct by inspecting it in line 64

Aug 1, 2011 at 11:01 PM

Thanks for the help,

then can you past the Script for me here I will use it on my machine , if this is okay.

 

Kind Regards,

Moe.

Developer
Aug 1, 2011 at 11:02 PM

I expect that this is the same script that you have, so this probably won't help, but here you go:

 

#requires -version 2.0
[CmdletBinding(SupportsShouldProcess=$true)]
param (
    [Parameter()][string]$AssignedTo,
    [Parameter()][string]$Affected,
    [Parameter(ValueFromPipeline=$true)]$TheIncident
)
BEGIN
{
    $NS = "Microsoft.EnterpriseManagement"
    $EMGType = "${NS}.EnterpriseManagementGroup"
    $EMG = new-object ${EMGType} localhost
 
    $ASSIGNEDTORELATIONSHIP = $EMG.EntityTypes.GetRelationshipClasses()|?{$_.name -eq "System.WorkItemAssignedToUser"}
    $AFFECTEDRELATIONSHIP = $EMG.EntityTypes.GetRelationshipClasses()|?{$_.name -eq "System.WorkItemAffectedUser" }
    $DEFAULT = ("${NS}.Common.ObjectQueryOptions" -as "type")::Default
    $EMOT    = "${NS}.Common.EnterpriseManagementObject" -as "type"
    $EMOP = "EnterpriseManagementObjectProjection"
    $IPT = "System.WorkItem.Incident.ProjectionType"
    $CEMO = "${NS}.Common.CreatableEnterpriseManagementObject"
    $INCIDENTC = $EMG.EntityTypes.GetClasses() |?{$_.name -eq "System.WorkItem.Incident" }
    $COMMENTC = $EMG.EntityTypes.GetClasses()|?{$_.name -eq "System.WorkItem.TroubleTicket.AnalystCommentLog"}
    $USERC    = $EMG.EntityTypes.GetClasses()|?{$_.name -eq "System.User"}
    $PROJECTION = $EMG.EntityTypes.GetTypeProjections()| ?{$_.name -eq $IPT}
    $MPCLASSTYPE = "${NS}.Configuration.ManagementPackClass"
    $SYSTEMMP = $EMG.ManagementPacks.GetManagementPacks()|?{$_.name -eq "System.Library"}

    function Get-User
    {
 
        param ( 
            [parameter(Mandatory=$true,Position=0)][string]$displayname
            )
            $criteriaString = '
     <Criteria xmlns="http://Microsoft.EnterpriseManagement.Core.Criteria/">
      <Reference Id="System.Library" Version="{0}" PublicKeyToken="{1}" Alias="System" />
      <Expression>
        <SimpleExpression>
          <ValueExpressionLeft><Property>$Target/Property[Type=''System!System.Domain.User'']/DisplayName$</Property></ValueExpressionLeft>
          <Operator>Equal</Operator>
          <ValueExpressionRight><Value>{2}</Value></ValueExpressionRight>
        </SimpleExpression>
      </Expression>
    </Criteria>
    ' -f $SYSTEMMP.Version, $SYSTEMMP.KeyToken, $displayname
        $userclass = get-scsmclass System.Domain.User
        $CriteriaType = "Microsoft.EnterpriseManagement.Common.EnterpriseManagementObjectCriteria"
        $global:criteria = new-object $CriteriaType $criteriastring,$userclass,$EMG
        # write-host -for cyan $criteria
        $r = Get-SCSMObject -criteria $criteria 
#        $r = Get-SCSMObject System.Domain.User -filter "DisplayName -eq '$displayName'"
        write-host -for cyan $r
        $r

    }
    }
    PROCESS
    {
        $incident = $TheIncident.__base

        if ( $AssignedTo )
        {
            $AssignedToUser = Get-User $AssignedTo
            $Incident.Add(($AssignedToUser -as $EMOT) ,$ASSIGNEDTORELATIONSHIP.Target)
            if ( $Incident.Item("AssignedWorkItem").Count -gt 1 )
            {
                $Incident.Item("AssignedWorkItem")[0].Remove()
            }
        }

        if ( $Affected )
        {
            $AffectedUser = Get-User $Affected
            $Incident.Add(($AffectedUser -as $EMOT) ,$AFFECTEDRELATIONSHIP.Target)
            if ( $Incident.Item("CreatedWorkItem").Count -gt 1 )
            {
                $Incident.Item("CreatedWorkItem")[0].Remove()
            }
        }

        if ( $PSCmdlet.ShouldProcess($TheIncident.DisplayName))
        {
            $Incident.Commit()
        }

    }

Aug 16, 2011 at 6:21 PM

I also received the same error msg using domain\username.  I changed the name to the display name (Last, First) and all is worked as expected.

Mar 21, 2013 at 4:21 PM
I wrestled with this for a while too, managed in the end and have finally come back to the discussion hoping this helps someone

i believe the big difference of it working or not working is where you run the powershell, the "set-incidentuser" script above works fine if running from the SCSM server but won't work for me from a client machine, I think its down to this line $EMG = new-object ${EMGType} localhost

I stole bits of the script above between begin and function and changed this line

$EMG = new-object ${EMGType} $ourSCSMServer

this code then worked a treat (in my case its just using the logged in user $env:username as the assigned to user as this is a small part of a quick incident logging tool)

$AssignedToUser = Get-SCSMObject $UserClass -computer $ourSCSMServer -Filter "UserName -eq $env:username"

$incident = $TheIncident.__base

$Incident.Add(($AssignedToUser -as $EMOT) ,$ASSIGNEDTORELATIONSHIP.Target)