FIM component database information script

I was chatting to a colleague about ideas for topics for this blog and he said why not post some of your scripts. I’m not a fan of posting scripts as most of the scripts I write that fulfil any real purpose are usually driven out of necessity which means they’re often functional but not as complete as they could be (in other words I whip up quick and dirty scripts and never go back and finish them properly). A lot of my FIM PowerShell scripts make heavy use of two function libraries that I’ve written that I dot source, whereas I should have written them as PS modules. Therefore I’m going to post one or two small, simple scripts that I use from time to time and at some point in the future I’ll hopefully have time to convert my current library of functions into a PS module or two and share that via codeplex or something.

Get FIM Database Information

This is a simple PS script that pulls some registry values, if they exist, and outputs the database details of either the FIM Service or the FIM Synchronization Service. It’s intended to be run locally, i.e. on a box running either the FIM Service or the FIM Synchronization Service (or both, i.e. in the lab) and simply outputs where the configured database is in a reasonably pleasing manner.

## GetFimDbInfo.ps1 v1.0ps1
##   Paul Williams (pawill@microsoft.com) Microsoft Services Feb. 2009
##
## Simple script that reads the FIM Service and/or FIM Synchronization Service database
## information from the local registry, i.e. this must run on-box.
##

###################################################################################################
[String]$fIMSvcRegKeyPath = "registry::hklm\System\CurrentControlSet\Services\FIMService";
[String]$fIMSyncSvcRegKeyPath = "registry::hklm\System\CurrentControlSet\Services\FIMSynchronizationService\Parameters";
###################################################################################################

# print script info.
Write-Host "`nGetFimDbInfo.ps1 v01.00.00ps1 Paul Williams (pawill@microsoft.com) Feb. 2009.`n";

###################################################################################################
# Functions
###################################################################################################
# void PrintFIMServiceDBInfo()
# Outputs the database server and name if the service is installed locally.
function PrintFIMSvcDBInfo
{
    if(Test-Path -Path $fIMSvcRegKeyPath)
    {
        Write-Host "The Forefront Identity Manager Service is installed on this system.  Locating DB info...";

        $fIMSvcRegKey = Get-ItemProperty -Path $fIMSvcRegKeyPath;
        Write-Host "`tForefront Identity Manager Service Database Server: " -NoNewline;
        Write-Host $fIMSvcRegKey.DatabaseServer -ForegroundColor Yellow;

        Write-Host "`tForefront Identity Manager Service Database Name:   " -NoNewline;
        Write-Host $fIMSvcRegKey.DatabaseName -ForegroundColor Yellow;

        Write-Host "";

    }
    else
    {
        Write-Host "The Forefront Identity Manager Service is not installed on this computer."
    }
}

# void PrintFIMSyncSvcDBInfo()
# Outputs the database instance and name if the service is installed locally.
function PrintFIMSyncSvcDBInfo
{
    if(Test-Path -Path $fIMSyncSvcRegKeyPath)
    {
        Write-Host "The Forefront Identity Manager Synchronization Service is installed on this system.  Locating DB info...";

        $fIMSyncSvcRegKey = Get-ItemProperty -Path $fIMSyncSvcRegKeyPath;
        Write-Host "`tForefront Identity Manager Synchronization Service Database Server: " -NoNewline;
        if(![String]::IsNullOrEmpty($fIMSyncSvcRegKey.Server))
        {
            [String]$sQLInstance = $fIMSyncSvcRegKey.Server;
        }
        else
        {
            [String]$sQLInstance = Get-Content Env:\COMPUTERNAME;
        }

        if(![String]::IsNullOrEmpty($fIMSyncSvcRegKey.SQLInstance))
        {
            $sQLInstance += "\" + $fIMSyncSvcRegKey.SQLInstance;
        }
        else
        {
            $sQLInstance += " (default instance)";
        }
        Write-Host $sQLInstance -ForegroundColor Yellow;

        Write-Host "`tForefront Identity Manager Synchronization Service Database Name:   " -NoNewline;
        if($fIMSyncSvcRegKey.DBName -ne $null)
        {
            Write-Host $fIMSyncSvcRegKey.DBName -ForegroundColor Yellow;
        }

        Write-Host "";

    } else
    {
        Write-Host "The Forefront Identity Manager Synchronization Service is not installed on this computer.";
    }
}

###################################################################################################
# Body
###################################################################################################
Write-Host "Attempting to locate and output Forefront Identity Manager component database information...`n";
PrintFIMSvcDBInfo;
PrintFIMSyncSvcDBInfo;

Here’s a sample of the output from one of my development machines that actually runs both services on the same box.

Figure 1: Sample output

Try not to pay too much attention to the names I’ve chosen for the database. J

Advertisements

About Paul Williams

IT consultant working for Microsoft specialising in Identity Management and Directory Services.
This entry was posted in FIM, Scripting and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s