Share via


FIM 2010: Cut down on your PowerShell code with the Lithnet FIM Service PowerShell module

The FIMAutomation PowerShell module requires you to write a lot of code to perform even the most basic tasks. Let’s have a look at the following example in which Paul Williams provides some very well-written code for updating the EmployeeEndDate attribute of a user using the FIMAutomation snap-in.

# It is assumed that you are executing this script locally on a server that hosts the FIM Service.
# For the purpose of this example, we're targeting a user Paul Williams with an AccountName value
# of PAULW.
[String]$targetAccountName = "paulw";
 
# Load FIMAutomation module if not already loaded
if(@(Get-PSSnapin | ? {  $_.Name -eq "FIMAutomation" } ).Count -eq 0)
{
    Add-PSSnapin FIMAutomation;
}
 
# Get the target resource's GUID
[String]$targetGuid = (
    Export-FIMConfig `
        -OnlyBaseResources `
        -CustomConfig "/Person[AccountName = '$targetAccountName']"
    ).ResourceManagementObject.ObjectIdentifier;
 
# Create the import object for the target resource
[Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject]$importObject = `
    New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject;
$importObject.ObjectType = "Person";
$importObject.TargetObjectIdentifier = $targetGuid;
$importObject.SourceObjectIdentifier = $targetGuid;
$importObject.State = [Microsoft.ResourceManagement.Automation.ObjectModel.ImportState]::Put;
 
# Create the change
[Microsoft.ResourceManagement.Automation.ObjectModel.ImportChange]$importChange = `
    New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportChange;
$importChange.Operation = [Microsoft.ResourceManagement.Automation.ObjectModel.ImportOperation]::Replace;
$importChange.AttributeName = "EmployeeEndDate";
$importChange.AttributeValue = "2012-06-01T00:00:00.000";
$importChange.FullyResolved = $true;
$importChange.Locale = "Invariant";
 
# Add the change to the import object
$importObject.Changes += $importChange;
 
# Submit to FIM Service WS endpoint
Import-FIMConfig -ImportObject $importObject; 

Now lets look at doing the same thing with the Lithnet FIM Service PowerShell module


Import-Module LithnetRMA;
$resource = Get-Resource -ObjectType Person -AttributeName AccountName -AttributeValue paulw;
$resource.EmployeeEndDate = "2012-06-01T00:00:00.000";
Save-Resource $resource;
 
The same task requires much less code, and much easier to understand. Perhaps most importantly, we don’t need to understand the inner workings of the FIM Service itself (import changes, put operations, etc) to do something as simple as updating an attribute value. Just get, set, and save.