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)
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)