Wednesday, December 17, 2008

BlackBerry Disaster Recover Information

Was asked yesterday if I could write something that would periodically generate a CSV file of our BlackBerry users and their pin numbers. This "report" would be used for communication purposes in a Disaster situation. I looked on the BlackBerry server for a few minutes hunting for a way to do it from the server. No such luck. I then remembered that all the data resides in SQL Server diligently waiting to be queried. Following is a small script that I have scheduled to run once a week:

# Parse the DN to get the SAMAccountName
$SQLQuery = "SELECT DisplayName,PIN,CreationTime,MailboxSMTPAddr,
Right(MailboxDN,(LEN(MailboxDN)-CHARINDEX('s/cn=', MailboxDN)-4)) AS SamAccountName
FROM UserConfig
ORDER BY DisplayName
"

#Set up connection
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = YourServer; Database = YourDB; User ID=YourID; Password=YourPWD; Integrated Security = False"
$SqlConnection.Open()

# Setup SQL Command
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SQLQuery
$SqlCmd.Connection = $SqlConnection

# Create the table and export!
$SqlVMDataReader = $SqlCmd.ExecuteReader()
$SqlVMDataTable = New-Object System.Data.DataTable
$SqlVMDataTable.Load($SqlVMDataReader)
$SqlVMDataTable Export-Csv 'L:\DRDocs\BBPins.csv' -noTypeInformation

# Cleanup
$SqlVMDataReader.Close()
$SqlConnection.Close()

Enjoy!

1 comment:

Mitchell said...

Check out:
http://www.gwava.com/products/retain-for-blackberry-enterprise-server.html

This is a solution which will handle this and much more.