Powershell activity log

I have powershell activity and I have run error, where I can see log ? What stage is the error?

Answers

  • Billy_WilsonBilly_Wilson Cireson Solution Architect Advanced IT Monkey ✭✭✭
    Hi Roman,

    You need to set the log path in the scsm console under Administration - Settings - Cireson Powershell Activity Settings.


  • Roman_NepomniashchiiRoman_Nepomniashchii Customer IT Monkey ✭
    Hi Roman,

    You need to set the log path in the scsm console under Administration - Settings - Cireson Powershell Activity Settings.


    Thank you!
  • Roman_NepomniashchiiRoman_Nepomniashchii Customer IT Monkey ✭
    edited March 19
    I have error who are know what it is?
    An error was written to the Error stream!
    Cannot convert 'System.Object[]' to the type 'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by parameter 'Target'. Specified method is not supported.
    An error was written to the Error stream!
    Cannot convert 'System.Object[]' to the type 'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by parameter 'Target'. Specified method is not supported.Cannot convert 'System.Object[]' to the type 'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by parameter 'Target'. Specified method is not supported.
    System.Center.Service.Manager
  • Roman_NepomniashchiiRoman_Nepomniashchii Customer IT Monkey ✭

  • Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭
    @Roman_Nepomniashchii, I don't think we can see the problem with the script from the screenshot you've posted.  But based on the error, it looks like you might be trying to create a relationship to an object(probably a work item/user?) but rather than getting a specific object(like a single work item or user) you're actually passing in a set of objects as the target for the relationship.  You might need to use more narrow criteria and/or use the -Filter flag on your (not shown above, but a speculation)get-scsmobject.
  • Roman_NepomniashchiiRoman_Nepomniashchii Customer IT Monkey ✭

    param([guid]$id,[guid]$PSId)
    $InstallationConfigKey = 'HKLM:\SOFTWARE\Microsoft\System Center\2010\Service Manager\Setup'
    $AdminModule = (Get-ItemProperty -Path $InstallationConfigKey -Name InstallDirectory).InstallDirectory + "Powershell\System.Center.Service.Manager.psd1"
    Import-Module -Name $AdminModule -PassThru
    #security group for approve free software
    $ApproversGroup = "Safety-Audit"
    #getting classes
    $MAClass = Get-SCSMClass -name System.WorkItem.Activity.ManualActivity
    $RAClass = Get-SCSMClass -name System.WorkItem.Activity.ReviewActivity
    $PAClass = Get-SCSMClass -name System.WorkItem.Activity.ParallelActivity
    $clsReviewer = Get-SCSMClass -name "System.Reviewer"
    $clsUser = Get-SCSMClass -name System.User
    $MAPrefix = (Get-SCClassInstance -class (Get-SCClass -Name System.GlobalSetting.ActivitySettings)).SystemWorkItemActivityManualActivityIdPrefix
    $RAPrefix = (Get-SCClassInstance -class (Get-SCClass -Name System.GlobalSetting.ActivitySettings)).SystemWorkItemActivityReviewActivityIdPrefix
    $PAPrefix = (Get-SCClassInstance -class (Get-SCClass -Name System.GlobalSetting.ActivitySettings)).SystemWorkItemActivityParallelActivityIdPrefix
    #getting required relationships
    $relWorkItemContainsActivity = Get-SCRelationship -name "System.WorkItemContainsActivity"
    $relReviewActivityHasReviewer = Get-SCSMrelationship -Name "System.ReviewActivityHasReviewer"
    $relReviewerIsUser = Get-SCSMrelationship -Name "System.ReviewerIsUser"
    $relConfigItemOwnedByUser = Get-SCSMrelationship -Name "System.ConfigItemOwnedByUser"
    $relBUManager = Get-SCSMrelationship -Name "BUManager"

    $AffectedLicenseUsers = @()
    # getting parent SR
    $cliSR = Get-SCSMClassInstance -Id $id
    $cliAC = Get-SCSMClassInstance -Id $PSId
    $userinput = [xml]$cliSR.UserInput
    $userinput.UserInputs.UserInput | ? {$_.Question -eq "Provide information about assigned user(s)"} | %{[xml]$_.Answer} | foreach {
        $AffectedLicenseUsers += $_.Values.Value.DisplayName}
    $Project = $userinput.UserInputs.UserInput | ? {$_.Question -eq "Project"} | %{[xml]$_.Answer} | %{$_.Values.Value.DisplayName}
    $ProjectId = $userinput.UserInputs.UserInput | ? {$_.Question -eq "Project"} | %{[xml]$_.Answer} | %{$_.Values.Value.Id}
    $SoftwareName = $userinput.UserInputs.UserInput | ? {$_.Question -eq "Provide information about Software Name"} | %{$_.Answer} 
    $SoftwareVersion = $userinput.UserInputs.UserInput | ? {$_.Question -eq "Provide information about Software Version"} | %{$_.Answer} 
    $SoftwareEdition = $userinput.UserInputs.UserInput | ? {$_.Question -eq "Provide information about Software Edition"} | %{$_.Answer} 
    $SoftwareLanguage = $userinput.UserInputs.UserInput | ? {$_.Question -eq "Provide information about Software Language"} | %{$_.Answer} 
    $LicensesNumber = [int]($userinput.UserInputs.UserInput | ? {$_.Question -eq "Provide information about number of licenses"} | %{$_.Answer})
    $UsingEnvironment = $userinput.UserInputs.UserInput | ? {$_.Question -eq "This software for Testing or Production needs?"} | %{$_.Answer} 
    $AdditionalInfo = $userinput.UserInputs.UserInput | ? {$_.Question -eq "Provide reason and additional information"} | %{$_.Answer}

    $cliCostCenter = Get-SCSMClassInstance -Id $ProjectId
    $ManagerGUID = $cliCostCenter.GetRelatedObjectsWhereSource($relConfigItemOwnedByUser.Id).EnterpriseManagementObject.id.GUID
    $cliManager = Get-SCSMClassInstance -id $ManagerGUID
    $BUManagerGUID = $cliCostCenter.GetRelatedObjectsWhereSource($relBUManager.Id).EnterpriseManagementObject.id.GUID
    $cliBUManager = Get-SCSMClassInstance -id $BUManagerGUID

    $Activities = $cliSR.GetRelatedObjectsWhereSource($relWorkItemContainsActivity.ID)
            
            foreach ($activity in $Activities)
                {
                    $cliActivity = Get-SCClassInstance -Id $activity.EnterpriseManagementObject.Id
                    if ($cliActivity.SequenceId -eq ($cliAC.SequenceId - 1))
                        {
                            $cliMAActivity = $cliActivity
                        }
                    
                }

    if ($AffectedLicenseUsers.Count -eq 1)
        {
            $TitlePart =  $AffectedLicenseUsers[0] + " from $Project"
        }
    else
        {
            $TitlePart =  "users from $Project"
        }
    $AffectedUsersList = $AffectedLicenseUsers -join ", "

    $cliSR.Description =  $("Software Name: {0}" -f $SoftwareName) + ";`r`n" + $("Software Version: {0}" -f $SoftwareVersion) + `
                          ";`r`n" + $("Software Edition: {0}" -f $SoftwareEdition) + ";`r`n" + $("Software Language: {0}" -f $SoftwareLanguage) + `
                          ";`r`n" + $("Licenses Number: {0}" -f $LicensesNumber) + ";`r`n" + $("Environment: {0}" -f $UsingEnvironment) + `
                          ";`r`n" + $("Affected User(s): {0}" -f $AffectedUsersList)+ ";`r`n" + $("Reason: {0}" -f $AdditionalInfo)
    $cliSR.SupportGroup = "Enum.268250e6ad354e1e80677c360e879fc2"

    $Reviewer = @{Decision = "DecisionEnum.NotYetVoted"
                  MustVote = $False
                          ReviewerId = "{0}"
                          Veto =  $False
                     }

    switch ($cliSR.Area){
    HERE IS WORK CODE and down part not work
    ##################################--Free Software--###########################################
           "Enum.8d0dde130dfe4eaf926d5e93e19b8f26" {
            $cliSR.Title = "Provision of Free Software ""$SoftwareName"" for $TitlePart"
            Update-SCSMClassInstance $cliSR
            #pause 1.5 minute
            Start-Sleep -Seconds 90
            # MA
            $MAProperty1 = @{Id = "$MAPrefix{0}"
                            SequenceId = 3
                            Title = "Registering of new product $SoftwareName $SoftwareVersion $SoftwareEdition $SoftwareLanguage"
                            Description = $cliSR.Description.ToString()+ ";`r`n" + $("Notes: {0}" -f $($cliMAActivity.Notes))
                            SupportGroup = "Enum.adf9ce7c02434480987b3caa98dc5d69"
                       }
            New-SCRelationshipInstance -RelationshipClass $relWorkItemContainsActivity -Source $cliSR -TargetClass $MAClass -TargetProperty $MAProperty1
            # RA
            $RAProperty1 = @{Id = "$RAPrefix{0}"
                            SequenceId = 4
                            Title = "Approve ""$SoftwareName"" for $TitlePart"
                            Description = "Approve ""$SoftwareName"" for user(s) $AffectedUsersList from project $Project"
                            Stage = "ActivityStageEnum.Approve"
                            ApprovalCondition = "ApprovalEnum.Unanimous"
                            ApprovalPercentage = 100
                            }
            $RArelinst1 = New-SCRelationshipInstance -RelationshipClass $relWorkItemContainsActivity -Source $cliSR -TargetClass $RAClass -TargetProperty $RAProperty1 -PassThru
            $relReviewerInst1 = New-SCRelationshipInstance -RelationshipClass $relReviewActivityHasReviewer -Source $RArelinst1.TargetObject -TargetClass $clsReviewer -TargetProperty $Reviewer -PassThru
            New-SCRelationshipInstance -RelationshipClass $relReviewerIsUser -Source $relReviewerInst1.TargetObject -Target $cliManager
            # MA
            $MAProperty2 = @{Id = "$MAPrefix{0}"
                            SequenceId = 5
                            Title = "Prepare RA for approve ""$SoftwareName"" for $TitlePart"
                            Description = "Providing a distribution kit for evaluation. Upload ""$SoftwareName"" to ""\\fs\Shared\Recycle""." + "`r`n" + "Provide reviewers from RA with URL." 
                            SupportGroup = "Enum.268250e6ad354e1e80677c360e879fc2"
                       }
            New-SCRelationshipInstance -RelationshipClass $relWorkItemContainsActivity -Source $cliSR -TargetClass $MAClass -TargetProperty $MAProperty2
            # RA
            # Load AD module
            If ( ! (Get-module ActiveDirectory )) {
                Import-Module ActiveDirectory
            }
            $SIDs = @()
            
            Get-ADGroupMember -Identity $ApproversGroup | ForEach-Object {
                $SIDs += $_.SID.Value
            }

            $Percentage = [math]::truncate(100/($SIDs.Count))

            $RAProperty2 = @{Id = "$RAPrefix{0}"
                            SequenceId = 6
                            Title = "Safety assessment ""$SoftwareName"""
                            Description = "Approve or Reject"
                            Stage = "ActivityStageEnum.Approve"
                            ApprovalCondition = "ApprovalEnum.Percentage"
                            ApprovalPercentage = $Percentage
                            }
            $RArelinst2 = New-SCRelationshipInstance -RelationshipClass $relWorkItemContainsActivity -Source $cliSR -TargetClass $RAClass -TargetProperty $RAProperty2 -PassThru
            
            foreach ($SID in $SIDs)
                {
                    $cliUser = Get-SCSMClassInstance -Class $clsUser |? {$_.SID -eq $SID}
                    $relReviewerInst = New-SCRelationshipInstance -RelationshipClass $relReviewActivityHasReviewer -Source $RArelinst2.TargetObject -TargetClass $clsReviewer -TargetProperty $Reviewer -PassThru
                    New-SCRelationshipInstance -RelationshipClass $relReviewerIsUser -Source $relReviewerInst.TargetObject -Target $cliUser
                }

            # MA
            $MAProperty3 = @{Id = "$MAPrefix{0}"
                            SequenceId = 7
                            Title = "Registration of assessment results ""$SoftwareName"""
                            Description = "Register the results of assessment on ""https://ihome/sites/IT/Lists/Corporate Software Use Approval/view.aspx"""
                            SupportGroup = "Enum.268250e6ad354e1e80677c360e879fc2"
                       }
            New-SCRelationshipInstance -RelationshipClass $relWorkItemContainsActivity -Source $cliSR -TargetClass $MAClass -TargetProperty $MAProperty3
            # MA
            $MAProperty4 = @{Id = "$MAPrefix{0}"
                            SequenceId = 8
                            Title = "Provision of installation pack $SoftwareName $SoftwareVersion $SoftwareEdition $SoftwareLanguage"
                            Description = "Provide requester with to ""\\fs\Shared\Recycle""."
                            SupportGroup = "Enum.268250e6ad354e1e80677c360e879fc2"
                       }
            New-SCRelationshipInstance -RelationshipClass $relWorkItemContainsActivity -Source $cliSR -TargetClass $MAClass -TargetProperty $MAProperty4

           }
        default { 
            Write-Error "There was not choosen appropriate Area in $($cliSR.Id)"
        }
    }
    #pause 1.5 minute
    Start-Sleep -Seconds 90

    its script create MA and RA when I choose in parent SR Area, when I choose Free Software all my 6 MA and RA created, but my Powershel activity go to Failed and I have error which I show in my last post
  • Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭
    Anywhere you are building a relationship could be the culprit that is causing your PSA to fail.  The reason the PSA fails is because there was some error.  In this case, the error is that you're trying to pass an array of objects rather than a single object into a parameter that expects a single object.  My best guess after a glance at your script would be this section:
       foreach ($SID in $SIDs)
                {
                    $cliUser = Get-SCSMClassInstance -Class $clsUser |? {$_.SID -eq $SID}
                    $relReviewerInst = New-SCRelationshipInstance -RelationshipClass $relReviewActivityHasReviewer -Source $RArelinst2.TargetObject -TargetClass $clsReviewer -TargetProperty $Reviewer -PassThru
                    New-SCRelationshipInstance -RelationshipClass $relReviewerIsUser -Source $relReviewerInst.TargetObject -Target $cliUser
                }

    If you have duplicate users in your SCSM, you could have more than one object with the same SID and therefore $cliUser could potentially be an array of users rather than a single user.  
  • Roman_NepomniashchiiRoman_Nepomniashchii Customer IT Monkey ✭
    Anywhere you are building a relationship could be the culprit that is causing your PSA to fail.  The reason the PSA fails is because there was some error.  In this case, the error is that you're trying to pass an array of objects rather than a single object into a parameter that expects a single object.  My best guess after a glance at your script would be this section:
       foreach ($SID in $SIDs)
                {
                    $cliUser = Get-SCSMClassInstance -Class $clsUser |? {$_.SID -eq $SID}
                    $relReviewerInst = New-SCRelationshipInstance -RelationshipClass $relReviewActivityHasReviewer -Source $RArelinst2.TargetObject -TargetClass $clsReviewer -TargetProperty $Reviewer -PassThru
                    New-SCRelationshipInstance -RelationshipClass $relReviewerIsUser -Source $relReviewerInst.TargetObject -Target $cliUser
                }

    If you have duplicate users in your SCSM, you could have more than one object with the same SID and therefore $cliUser could potentially be an array of users rather than a single user.  
    Thank you very much!!! it was a my problem I took the first element of the array and AC is compleated, in dev environment I have duplicate user!
Sign In or Register to comment.