Problem with powershell activity
I had to Change our PowerShell activity for Service Request Quick and Close. With the following command the Assignment went wrong for our Group Team Netzwerk. We have a Team "Team Netzwerk" and "Team Netzwerk physikalisch". If I choose Business Service "VPN" the Support Group Setting is set to "Team Netzwerk physikalisch" and not "Team Netzwerk" what it should be.
Get-SCSMObject -ID $id | Set-SCSMObject -Property SupportGroup -Value $Zuweisung.DisplayName
Now I Change the command to the following
Get-SCSMObject -class $SRClass -filter 'ID -eq $SR.ID' | Set-SCSMObject -Property SupportGroup -value $SupportgroupEnum.name
This works in PowerShell ise but not in Service Manager PowerShell Activity and I am not able to debug it. I tried to use the serveral commands to write the variables to Output but it did not work. Could anyone help with my script? Here is the script Code:
Param([GUID]$id)
#
# Autor: mjussen
#
# Hole SR
#
$SR = Get-SCSMObject -Id $id
#
# Parameter Service Request ID
#
# Definitionen
#
write-output ('Hallo')
# Service Request Klasse
#
$SRClass = Get-SCSMClass -Name System.WorkItem.ServiceRequest$
#
# Klasse des Benutzers, dem der Request zugewiesen wird
#
$AssToUserClass = Get-SCSMRelationshipClass -Name System.WorkItemAssignedToUser$
#
# Ersteller
#
$CreatedByUser = Get-SCSMRelatedObject -SMObject $SR -Relationship $CreatedByUserClass
#
# Weise Request dem Ersteller zu
#
New-SCSMRelationshipObject -Relationship $AssToUserClass -Source $SR -Target $CreatedByUser –Bulk
#
# Wurde ein Dienst zugeordnet?
#
$RelatedServiceClass = Get-SCSMRelationshipClass -Name System.WorkItemABoutConfigItem
$AssignedToService = Get-SCSMRelatedObject -SMObject $SR -Relationship $RelatedServiceClass
if ($AssignedTOService -eq $null) {return}
$ServiceUser = get-SCSMRelatedObject -SMObject $AssignedToService -Relationship (Get-SCSMRelationshipClass -Name IT_AdminGroup)
if ($ServiceUser –eq $null) {return}
echo $ServiceUser
$SupportGroupEnum = Get-SCSMEnumeration |?{$_.DisplayName -eq 'Service Request Support Group'} | Get-SCSMChildEnumeration |?{$_.DisplayName -eq $ServiceUser.DisplayName)}
write-output ($SupportGroupEnum)
write-output ($SRClass)
write-output ($SR.ID)
Get-SCSMObject -class $SRClass -filter 'ID -eq $SR.ID' | Set-SCSMObject -Property SupportGroup -value $SupportgroupEnum.name
return
Regards Margret
Answers
My PowerShell script runs fine in ISE. I'm finding PSA does not like working with the Run as User or when the credentials are stored in the script. It just sits there running with nothing for me to look at to see what it is doing it just throws the 1 Error in the event viewer. If I remove the Run as User and the credentials in the script it runs, but I get Access Denied errors in the PowerShell Output and the activity fails...