RCDC - Session 1 - Backing up your RCDC Files.
There are 2 ways to Back up your RCDC Configuration Files, The Easy way Automated with Script or the not as easy way Manual Back Up Procedure, I recommend useing the Automated with Script method after you first install to have a back up of all default RCDC Configuration files and maybe periodicly acording to your back up procedures policy. Of course there are times when you will need to back up individual RCDC Configuration files and in those cases the Manual method will be used.
Previously there was not a clean way to back up all of your RCDC Configuration Files.You could spend the time backing up each RCDC configuration manually which could take a while and one of the major problems with that was how easy it is to only back up the Configuration Files for User Interfaces that you think you need to back up. In the past i would get contacted by people who accidentally overwrote a configuration file for the wrong RCDC File. When trying to update their User Create Configuration file they may have accidentally updated the Set Creation RCDC configuration. Unfortunately there is no undo Button so if you don't have that particular RCDC backed up than you may be in a situation where you are either tying rebuild, or repair the XML file. I usually take periodic backups of a users RCDC Configuration to avoid these types of scenarios.
Automated with Script
The Following Script will back up the Environments RCDC Collection useing the Display Name of each RCDC File as opposed to the Guid of the RCDC configuration Object which alot of the scripts that i have seen have used.
Updated 10/28/2014 6:39 PM...Script now includes a Folder Picker which allows you to select where you would like to Save the RCDC Configuration Files.
https://blogs.msdn.com/b/connector\_space/
#------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Script to back all the Resource Control Display Configuration Objects
# This script is intended to be run before upgrade to FIM 2010 R2
#------------------------------------------------------------------------------------------------------
if(@(get-module | where-object {$_.Name -eq "ActiveDirectory"} ).count -eq 0) {import-module ActiveDirectory}
####----------Select Folder to save output
$object = New-Object -ComObject Shell.Application
$folder = $object.BrowseForFolder(0, "Select File Output Location !", 0, "C:\")
$Dir = $folder.Self.Path
#------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------
# Script Parameter Declarations
# Data Warehouse machine name
##[parameter(Mandatory=$false)]
$ConfigurationBackupPath = $Dir + '\FIMBackup'
# End Script parameter declarations
#------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------
# Script constant declarations
Set-Variable -Name constantFIMPowerShellSnapInName -Option Constant -Value "FIMAutomation" -ErrorAction SilentlyContinue
Set-Variable -Name constantRCDCFolderName -Option Constant -Value "ResourceControlDisplayConfiguration" -ErrorAction SilentlyContinue
Set-Variable -Name constantRCDCObjectFilter -Option Constant -Value "/ObjectVisualizationConfiguration" -ErrorAction SilentlyContinue
Set-Variable -Name constantLineSeperator -Option Constant -Value "----------------------------------------------------------------------------------------------------------" -ErrorAction SilentlyContinue
# End Script constant declarations
#------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------
# Function definitions
#--------------------------------------------------------------
# Checks to see if the user running the script is an
# administrative user
#--------------------------------------------------------------
function In-Administrator-Mode
{
# check that current user is in administrators group.
try
{
# get the current user who is executing the script.
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$windowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal($CurrentUser)
# Is the user in the Admin grooup.
return $windowsPrincipal.IsInRole("Administrators")
}
catch
{
Write-Error $_
return $false
}
}
#--------------------------------------------------------------
# Checks to see if the FIMAutomation is installed.
#--------------------------------------------------------------
function Is-FIM-Powershell-SnapIn-Registered
{
try
{
# get registry key value
Add-PSSnapin -Name $constantFIMPowerShellSnapInName -ErrorAction SilentlyContinue
return $true
}
catch
{
Write-Error $_
return $false
}
}
#--------------------------------------------------------------
# Writes an informational message to the Console
# $message : message text to be written to the console
#--------------------------------------------------------------
function Write-Informational-Message([String]$message)
{
Write-Host $message -ForegroundColor "green"
}
#--------------------------------------------------------------
# Writes an error message to the Console
# $message : message text to be written to the console
#--------------------------------------------------------------
function Write-Error-Message([String]$message)
{
Write-Host $message -ForegroundColor "red"
}
#--------------------------------------------------------------
# Saves the RCDC objects to files
# $rcdcs : List of objects to be saved
# $filePath : Path to save the files at.
#--------------------------------------------------------------
##function Save-RCDC-Objects([Object[]]$rcdcs, [String]$filePath)
##{
## foreach($rcdc in $rcdcs)
##{
## $fileName = $rcdc.ResourceManagementObject.ObjectIdentifier.Substring(9) + ".xml"
## $fullPath = Join-Path -Path $filePath -ChildPath $fileName
## ConvertFrom-FIMResource $rcdc -File $fullPath
##}
##}
function Save-RCDC-Objects([Object[]]$rcdcs, [String]$filePath)
{
foreach($rcdc in $rcdcs)
{
#$fileName = $rcdc.ResourceManagementObject.ObjectIdentifier.Substring(9) + ".xml"
$attributes = $rcdc.ResourceManagementObject.ResourceManagementAttributes
foreach($attrib in $attributes)
{
if($attrib.AttributeName.Contains("DisplayName"))
{
$fileName = $attrib.Value + ".xml"
break
}
}
$fileName
$fullPath = Join-Path -Path $filePath -ChildPath $fileName
ConvertFrom-FIMResource $rcdc -File $fullPath
[xml] $xml = Get-Content $fullPath
foreach($o in $xml.Results.ExportObject.ResourceManagementObject.ResourceManagementAttributes.ResourceManagementAttribute)
{
if($o.AttributeName -eq "ConfigurationData")
{
echo $o.Value > $fullPath
break
}
}
}
}
# End Function declarations
#------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------
# Main Script Logic
try
{
Write-Host $constantLineSeperator
Write-Informational-Message "Resource Control Display Configuration backup script."
Write-Informational-Message "This script will back up all resource control display configuration objects."
# Check to see if the script is being run by an administrative user
$inAdminMode = In-Administrator-Mode
if ($inAdminMode -ne $true)
{
Write-Error-Message "This script is not being run by an administrator. Please re-run script as an administrative user"
EXIT
}
# check to see if the FIM powershell snapin is installed
Write-Host $constantLineSeperator
Write-Informational-Message "Starting Pre-Requisite checks before script execution"
Write-Host $constantLineSeperator
Write-Informational-Message "Pre-Requisite check #1"
Write-Informational-Message "Checking to see if FIM commandlets are installed"
$isFIMPSSnapinInstalled = Is-FIM-Powershell-SnapIn-Registered
if($isFIMPSSnapinInstalled -eq $false)
{
Write-Error-Message "FIM commandlets are not installed on this machine. Please run the script on a machine where FIM service is installed."
Write-Host $constantLineSeperator
EXIT
}
Write-Informational-Message "FIM commandlets are installed on local machine"
# check to see if the configuration back-up path is valid
Write-Informational-Message "Pre-Requisite Check #2"
Write-Informational-Message "Checking to see if the configuration backup folder path is valid"
if((Test-Path $ConfigurationBackupPath -PathType container) -ne $true)
{
Write-Informational-Message "Configuration Backup directory does not exist. Creating the directory"
New-Item $ConfigurationBackupPath -type directory | out-null
Write-Informational-Message "Configuration Backup directory created"
}
Write-Informational-Message "All Pre-Requisite checks passed."
Write-Host $constantLineSeperator
Write-Host $constantLineSeperator
Write-Informational-Message "Setting up folders to backup the configuration settings"
Write-Host $constantLineSeperator
# check to see if the RCDC folder is already present. If not, create it.
$rcdcPath = Join-Path -Path $ConfigurationBackupPath -ChildPath $constantRCDCFolderName
$saveMessage = "The configuration settings will be saved at : " + $rcdcPath
Write-Host $saveMessage -foregroundcolor "yellow"
if((Test-Path $rcdcPath -PathType container) -eq $true)
{
Write-Informational-Message "The specified directory is already present"
if((Get-ChildItem $rcdcPath) -ne $null)
{
Write-Informational-Message "There is already a saved back-up in this directory"
Write-Informational-Message "Please save the contents in another directory before re-running this script"
Write-Host $constantLineSeperator
EXIT
}
}
else
{
Write-Informational-Message "Creating the resource control display configuration backup directory"
New-Item $rcdcPath -type directory | out-null
Write-Informational-Message "Created the resource control display configuration backup directory"
}
# get all the rcdc objects from the FIM Service store.
Write-Host $constantLineSeperator
Write-Informational-Message "Gathering all resource control display configuration objects"
$rcdcObjects = Export-FIMConfig -CustomConfig $constantRCDCObjectFilter
$resultMessage = "Found " + $rcdcObjects.Count + " objects"
Write-Informational-Message $resultMessage
Write-Host $constantLineSeperator
# Write them out to files as XML
Write-Host $constantLineSeperator
Write-Informational-Message "Saving all the resource control display configuration objects"
Save-RCDC-Objects $rcdcObjects $rcdcPath
Write-Informational-Message "Successfully saved all the resource control display configuration objects"
Write-Host $constantLineSeperator
}
catch [Exception]
{
Write-Error-Message "Script execution failed with the following exception message"
Write-Host $_.Exception.ToString()
}
# End Script code
#------------------------------------------------------------------------------------------------------
Note: Script only Backs up Actual RCDC XML File not the Localization Files.
Manual Back Up Procedure.
- From the Administration Page Click on Resource Control Display Configuration
- Once the RCDC Page is loaded lets locate grab the most current XML file for the Configuration for User Creation RCDC, If you already have a copy of the Current XML File for this RCDC you can skip to the step of Editing the RCDC section of this post. Be careful not to click on the wrong link, it is extremely easy to accidentally grab the wrong XML file which you would then edit and upload to the intended RCDC file. The XML information contains information about the type of attributes and resource that the RCDC is for so it is easily broken,
- Once you locate the RCDC Configuration for User Creation, Notice the 2nd column which represents Target Resource Type tells you what resource this RCDC is for.
- After you click on the RCDC "Configuration for User Create" take a look at your options within the RCDC Window.
- Within this window you could change the Display Name and Target Resource Type if desired but i would strongly not recommending changing the Target Resource Type section which essentially binds this RCDC to the User resource with in the FIM Portal. It may also be important to note that you should only ever have 1 RCDC set for each resource type and action. (Another words do not change the following 2 options)
- Notice that there are 2 Configuration Data sections.
- The first Configuration Data section is where we could view the current RCDC file or upload a new one. We will come back to this section shortly.
- Now look at the 2nd Configuration Data section, this is where we will download or extract the current RCDC file.
- Click on the Link Export Configuration within the 2nd Configuration Section, this would open up a popup window to save the RCDC XML File.
- Click on the down arrow next to the Save button, this will display a drop down for different Save options.
- Select the Save As Option, Selecting the Save As option allows you to change the default name of configuration.xml to something else usually something more user friendly. Its also important to not that the RCDC Back Up Script located on this Blog saves all RCDC Files will the correct Display Name of each RCDC to make it easy to locate the File you wish to modify.
- For the File Name I recommend naming the file something that not only makes it easy to identify which RCDC this XML file is for but when you saved it. In this example i used a format (Identification and date and time) For Example User Create Identifies this XML File is for the Configuration for User Creation RCDC, and 126214_1800 Identifies the date and time this XML file was saved. (1262014_1800 = December 6, 2014 06:00 PM) The reason i name these files this way is when your modifying RCDCs its important to make your modifications 1 step at a time making changes to 1 attribute at a time, saving and testing this file each step of the way.
- Now the File has been saved hopefully in a folder located somewhere that is easy to find and easy to backup if needed. you can now click on the Close button to close the window.
- You are now presented with the Page the Basic or the initial page that was displayed when you first opened the RCDC. Click on Cancel to close this window, no changes were made at this time so no need to click on Ok. This also protects you just incase while you were exploring the RCDC information and you accidentally changed something.
You have successfully Backed up your RCDC Configuration.
## https://blogs.msdn.com/connector_space ##
Comments
- Anonymous
October 28, 2014
Great job on this script Anthony! Will be very helpful in our environment!