First published on MSDN on Oct 28, 2014
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.
http://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 .
You have successfully Backed up your RCDC Configuration.
## http://blogs.msdn.com/connector_space ##
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.