Share via


How to Use Powershell to add WorkflowActivities to GAC and AIC

FIM ScriptBox Item

Summary

This script is intended to make the process of adding or updating new Workflow Activities to FIM by adding DLLs to the GAC and creating (if needed) a corresponding AIC object within the portal to enable FIM to access the new code.

Script Code

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
#-- InstallAIC.PS1
#--
#-- Registers a DLL into the GAC and installs it into the AIC (providing it has the WorkflowPart and UIpart elements)

#-- Usage: installaic.ps1 <full path to dll>
#-- e.g. installaic.ps1 "c:\program files\microsoft forefront identity manager\2010\service\ocg.MyWorkflow.dll"

#-- GAC elements adapted from http://codeimpossible.com/2010/7/21/Installing-Assemblies-to-GAC-with-PowerShell

Param ($dllpath)

#--------------------------------------------------------------------------------------------------------------------
#--
Function AddChangeToResource
{
Param($Resource, $AttributeName, $AttributeValue, $Operation)
    
$ImportChange = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportChange
$ImportChange.Operation = $Operation
$ImportChange.AttributeName = $AttributeName
$ImportChange.AttributeValue = $AttributeValue
$ImportChange.FullyResolved = 1
$ImportChange.Locale = "Invariant"
 
If($Resource.Changes -eq $null)
{$Resource.Changes = (,$ImportChange)}
Else 
{$Resource.Changes += $ImportChange}
    
}
#--------------------------------------------------------------------------------------------------------------------

#--------------------------------------------------------------------------------------------------------------------
#--
function SubmitResource
{
   Param($Resource)

   $Resource | Import-FIMConfig -ErrorVariable Err `
                                -ErrorAction SilentlyContinue 
   If($Err){Throw $Err}

}
#--------------------------------------------------------------------------------------------------------------------

#--------------------------------------------------------------------------------------------------------------------
#--
Function CreateResource
{
Param($ObjectType, $DisplayName)    

$NewResource = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject
$NewResource.ObjectType = $ObjectType
$NewResource.SourceObjectIdentifier = [System.Guid]::NewGuid().ToString()

AddChangeToResource $newResource "DisplayName" $DisplayName "1"
                                 
Return $NewResource
}

#-- Loads in the handler for the GAC
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") | Out-Null    
$publish = New-Object System.EnterpriseServices.Internal.Publish

if (-not (Test-Path $dllpath))
{
throw new Exception "$dllpath does not exist"
}

$assembly = [System.Reflection.Assembly]::LoadFile( $dllpath )
$publickey = $assembly.GetName().GetPublicKey()
$aicstring = [System.Reflection.Assembly]::LoadFile( $dllpath ).FullName

$basename = $aicstring.Remove($aicstring.IndexOf(","))

$wfpart = $null
$uipart = $null

$types = $assembly.GetExportedTypes()

foreach ($exportType in $types)
{
if ($exportType.BaseType.Name -eq "ActivitySettingsPart") { $uipart = "$exporttype"}
if ($exportType.BaseType.Name -eq "SequenceActivity") { $wfpart = "$exporttype"}
}

if ($publickey.length -eq 0)
{
throw new exception "The Assembly $dllpath must be strongly signed"
}

$publish.GacInstall( $dllpath )

$aic = export-fimconfig -onlybaseresources -customconfig "/ActivityInformationConfiguration[DisplayName='$basename']"
if ($aic -eq $null)
{
$new_aic = CreateResource "ActivityInformationConfiguration" $basename
AddChangeToResource $new_aic "ActivityName" $wfpart "0"
AddChangeToResource $new_aic "AssemblyName" $aicstring "0" 
AddChangeToResource $new_aic "TypeName" $uipart "0"
AddChangeToResource $new_aic "IsActionActivity" $true "0"
AddChangeToResource $new_aic "IsAuthorizationActivity" $true "0"
AddChangeToResource $new_aic "IsConfigurationType" $false "0"
AddChangeToResource $new_aic "IsAuthenticationActivity" $false "0"
SubmitResource $new_aic
}

 

Note

To provide feedback about this script, create a post on the FIM TechNet Forum.
For more FIM related Windows PowerShell scripts, see the FIM ScriptBox.

 


See Also