none
Config Item Owner as reviewer

    Pergunta

  • Hi all,

    Carrying on from - http://social.technet.microsoft.com/Forums/en-US/systemcenterservicemanager/thread/d31d7fe4-4dee-4345-a2b2-6bcea9a9e1d2

    I was trying to get a powersehll script to pull the business owner of the configuration item added and set it to a reviewer in a certain review activity in my change process.

    When i walk through my script on the server the script works.

    However when i try and run it from a workflow it fails!

    Even if my powershell script is only 1 line long i get an error from the workflow.

    Error is mostly object is not an instance of an object, even if the script just says

    Import-Module Smlets
    Write-Host $ChangeRequestID

    Is there something im missing when im setting up my workflow?

    Import-Module Smlets
    Write-Host $ChangeRequestID
    $RelationWorkItemConfigItem = Get-SCSMRelationshipClass -Name System.WorkItemAboutConfigItem$
    $RelationConfigItemOwner                                        = Get-SCSMRelationshipClass -Name System.ConfigItemOwnedByUser$
    $RelationActivity                                                                                                              = Get-SCSMRelationshipClass -Name System.WorkItemContainsActivity$
    $RelationRevIsUser                                                                                        = Get-SCSMRelationshipClass -Name System.ReviewerIsUser$
    $RelationRAHasReviewer                                                             = Get-SCSMRelationshipClass -Name System.ReviewActivityHasReviewer$
    $ClassReviewActivity                                                                      = Get-SCSMClass -Name System.WorkItem.Activity.ReviewActivity$
    $ChangeRequest                                                                                                                             = Get-SCSMObject -id $ChangeRequestID
    $AssociatedCIs                                                                                                                  = Get-SCSMRelatedObject $ChangeRequest -relationship $RelationWorkItemConfigItem
    if (@($AssociatedCIs).Length -eq 1){
                    $AssociatedCI = $AssociatedCIs
    }elseif(@($AssociatedCIs).Length -gt 1){
                    $AssociatedCI = $AssociatedCIs[0]
    }else{
                    Write-Host "No Accociated CIs"
                    exit 0
    }
    $BusinessOwner = Get-SCSMRelatedObject $AssociatedCI -relationship $RelationConfigItemOwner
    if(!$BusinessOwner){
                    Write-Host "No Accociated Business Owner"
                    exit 0
    }
    $Ractivities = Get-SCSMRelatedObject -SMObject $ChangeRequest -Relationship $RelationActivity | Where{$_.TypeName -eq $ClassReviewActivity}
    if(@($Ractivities).Length -eq 1){
                    $Ractivity = $Ractivities
    }elseif(@($Ractivities).Length -gt 1){
                    $Ractivity = $Ractivities | ForEach-Object {$_ | Where {$_.title -eq "130 - RELEASE TO LIVE"}}
    }else{
                    Write-Host "No Accociated Review Activities"
                    exit 0
    }
    $Reviewer = New-SCSMObject -class (Get-SCSMClass -Name System.Reviewer$) -prop @{ ReviewerId = "{0}" } -nocommit
    $ro1 = New-SCSMRelationshipObject -nocommit -rel $RelationRAHasReviewer -sou $Ractivity -tar $Reviewer
    $ro2 = New-SCSMRelationshipObject -nocommit -rel $RelationRevIsUser -Sour $Reviewer -targ $BusinessOwner
    $ro1.Commit()
    $ro2.Commit()
    remove-module SMLets -force 

    segunda-feira, 11 de junho de 2012 07:36

Todas as Respostas

  • I must be doing something wrong, the workflow runs, the realted object is correct, but when the workflow tries to run the script it fails!

    and every ps script/Bat file, cmd line i try to get a workflow to run fails.

    Even powershell workflows i have downloaded from other that they say are working, fail for me when the workflow tries to run the script.

    Is there a step i'm missing

    segunda-feira, 11 de junho de 2012 10:58
  • <ManagementPack ContentReadable="true" SchemaVersion="2.0" OriginalSchemaVersion="1.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <Manifest> <Identity> <ID>AddBusinessOwnerAsReviewer</ID> <Version>1.0.0.0</Version> </Identity> <Name>AddBusinessOwnerAsReviewer</Name> <References> <Reference Alias="System"> <ID>System.Library</ID> <Version>7.5.8501.0</Version> <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> </Reference> <Reference Alias="Console"> <ID>Microsoft.EnterpriseManagement.ServiceManager.UI.Console</ID> <Version>7.5.1561.0</Version> <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> </Reference> <Reference Alias="System_WorkItem_ChangeRequest_Library"> <ID>System.WorkItem.ChangeRequest.Library</ID> <Version>7.5.1561.0</Version> <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> </Reference> <Reference Alias="EnterpriseManagement"> <ID>Microsoft.EnterpriseManagement.ServiceManager.UI.Administration</ID> <Version>7.5.1561.0</Version> <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> </Reference> <Reference Alias="SystemCenter"> <ID>Microsoft.SystemCenter.Library</ID> <Version>7.0.8427.0</Version> <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> </Reference> <Reference Alias="SystemCenter1"> <ID>Microsoft.SystemCenter.Subscriptions</ID> <Version>7.5.1561.0</Version> <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> </Reference> <Reference Alias="Core"> <ID>ServiceManager.Core.Library</ID> <Version>7.5.1561.0</Version> <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> </Reference> <Reference Alias="Windows"> <ID>Microsoft.Windows.Library</ID> <Version>7.5.8501.0</Version> <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> </Reference> </References> </Manifest> <TypeDefinitions> <ModuleTypes> <WriteActionModuleType ID="AddBusinessOwnerToCR.WindowsPowerShellScript.2af77959_ef63_4526_84b4_65f80cd2a7ee.MT" Accessibility="Public" RunAs="Core!Microsoft.SystemCenter.ServiceManager.WorkflowAccount" Batching="false"> <Configuration> <IncludeSchemaTypes> <SchemaType>Windows!Microsoft.Windows.PowerShellSchema</SchemaType> </IncludeSchemaTypes> <xsd:element name="ChangeRequestID" type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema" /> </Configuration> <OverrideableParameters> <OverrideableParameter ID="ChangeRequestID" Selector="$Config/ChangeRequestID$" ParameterType="string" /> </OverrideableParameters> <ModuleImplementation Isolation="Any"> <Composite> <MemberModules> <WriteAction ID="AddBusinessOwnerToCR.WindowsPowerShellScript.2af77959_ef63_4526_84b4_65f80cd2a7ee.PSWA" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction"> <ScriptName>DoWork.ps1</ScriptName> <ScriptBody>param ( [string]$ChangeRequestID ) $File = "C:\Temp\Logs\AddBusinessOwnerToCR.log" Get-Date | Out-File -append $File Write-Host $ChangeRequestID | Out-File -append $File</ScriptBody> <SnapIns></SnapIns> <Parameters> <Parameter> <Name>ChangeRequestID</Name> <Value>$Config/ChangeRequestID$</Value> </Parameter> </Parameters> <TimeoutSeconds>300</TimeoutSeconds> <StrictErrorHandling>true</StrictErrorHandling> <SerializationDepth>3</SerializationDepth> </WriteAction> </MemberModules> <Composition> <Node ID="AddBusinessOwnerToCR.WindowsPowerShellScript.2af77959_ef63_4526_84b4_65f80cd2a7ee.PSWA" /> </Composition> </Composite> </ModuleImplementation> <InputType>System!System.BaseData</InputType> </WriteActionModuleType> </ModuleTypes> </TypeDefinitions> <Categories> <Category ID="AddBusinessOwnerAsReviewer.Category" Value="Console!Microsoft.EnterpriseManagement.ServiceManager.ManagementPack"> <ManagementPackName>AddBusinessOwnerAsReviewer</ManagementPackName> <ManagementPackVersion>1.0.0.0</ManagementPackVersion> </Category> <Category ID="AddBusinessOwnerToCRCategory" Target="AddBusinessOwnerToCR" Value="EnterpriseManagement!Microsoft.EnterpriseManagement.ServiceManager.Rules.WorkflowSubscriptions" /> </Categories> <Monitoring> <Rules> <Rule ID="AddBusinessOwnerToCR" Enabled="true" Target="SystemCenter!Microsoft.SystemCenter.SubscriptionWorkflowTarget" ConfirmDelivery="true" Remotable="true" Priority="Normal" DiscardLevel="100"> <Category>Notification</Category> <DataSources> <DataSource ID="DS" TypeID="SystemCenter1!Microsoft.SystemCenter.CmdbInstanceSubscription.DataSourceModule"> <Subscription> <InstanceSubscription Type="$MPElement[Name='System_WorkItem_ChangeRequest_Library!System.WorkItem.ChangeRequest']$"> <UpdateInstance></UpdateInstance> </InstanceSubscription> <PollingIntervalInSeconds>60</PollingIntervalInSeconds> <BatchSize>100</BatchSize> </Subscription> </DataSource> </DataSources> <WriteActions> <WriteAction ID="WA" TypeID="SystemCenter1!Microsoft.EnterpriseManagement.SystemCenter.Subscription.WindowsWorkflowTaskWriteAction"> <Subscription> <WindowsWorkflowConfiguration> <AssemblyName>AddBusinessOwnerToCR</AssemblyName> <WorkflowTypeName>WorkflowAuthoring.AddBusinessOwnerToCR</WorkflowTypeName> <WorkflowParameters> <WorkflowParameter Name="windowsPowerShellScript1_ChangeRequestID" Type="string">$Data/BaseManagedEntityId$</WorkflowParameter> </WorkflowParameters> <RetryExceptions></RetryExceptions> <RetryDelaySeconds>60</RetryDelaySeconds> <MaximumRunningTimeSeconds>300</MaximumRunningTimeSeconds> </WindowsWorkflowConfiguration> </Subscription> </WriteAction> </WriteActions> </Rule> </Rules> <Tasks> <Task ID="AddBusinessOwnerToCR.WindowsPowerShellScript.2af77959_ef63_4526_84b4_65f80cd2a7ee" Accessibility="Public" Enabled="true" Target="Windows!Microsoft.Windows.Computer" Timeout="300" Remotable="true"> <Category>Notification</Category> <WriteAction ID="AddBusinessOwnerToCR.WindowsPowerShellScript.2af77959_ef63_4526_84b4_65f80cd2a7ee.WA" TypeID="AddBusinessOwnerToCR.WindowsPowerShellScript.2af77959_ef63_4526_84b4_65f80cd2a7ee.MT"> <ChangeRequestID></ChangeRequestID> </WriteAction> </Task> </Tasks> </Monitoring> <LanguagePacks> <LanguagePack ID="ENG" IsDefault="true"> <DisplayStrings> <DisplayString ElementID="AddBusinessOwnerAsReviewer"> <Name>AddBusinessOwnerAsReviewer</Name> </DisplayString> </DisplayStrings> </LanguagePack> <LanguagePack ID="ENU" IsDefault="false"> <DisplayStrings> <DisplayString ElementID="AddBusinessOwnerAsReviewer"> <Name>AddBusinessOwnerAsReviewer</Name> </DisplayString> <DisplayString ElementID="AddBusinessOwnerToCR"> <Name>AddBusinessOwnerToCR</Name> <Description>Add the business owner of the first CI as a reviewer on the live promotion review activity</Description> </DisplayString> <DisplayString ElementID="AddBusinessOwnerToCR" SubElementID="WA"> <Name>Add the business owner of the first CI as a reviewer on the live promotion review activity</Name> <Description>Add the business owner of the first CI as a reviewer on the live promotion review activity</Description> </DisplayString> <DisplayString ElementID="AddBusinessOwnerToCR.WindowsPowerShellScript.2af77959_ef63_4526_84b4_65f80cd2a7ee"> <Name>AddBusinessOwnerToCR.WindowsPowerShellScript.2af77959_ef63_4526_84b4_65f80cd2a7ee</Name> </DisplayString> </DisplayStrings> </LanguagePack> </LanguagePacks> </ManagementPack>

    segunda-feira, 11 de junho de 2012 11:00
  • Hi,

    Seems that logs have been enable in your script. Could you please have a look at C:\Temp\Logs\AddBusinessOwnerToCR.log ?

    Possible for you to share the logs ?

    You can also use orchestrator to do that (add owner of CI to a CR)

    Here:

    http://contoso.se/blog/?p=2872
    <u5:p></u5:p>

    lakdar

    terça-feira, 12 de junho de 2012 14:12