Wim-ms’s Opsmgr 2007 Weblog

A blog about opsmgr 2007

Powershell snippet – fixing kb942865

Posted by wim-ms on April 15, 2008

Here some powershell code to fix kb942865, you’ll get this if you use dbcreatewizard to create your databases on your SQL server, instead of using the installer.


function Pause ($Message="Press any key to continue...")
{
Write-Host -NoNewLine $Message
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Write-Host ""
}


function checkMemberDatabase {
#http://suppport.microsoft.com/kb/942865
write-host "checking if memberdatabase needs fixing"
pause
$cn = new-object system.data.SqlClient.SqlConnection("Data Source=SQLSERVER\INSTANCE;Integrated Security=SSPI;Initial Catalog=OperationsManagerDW");
$ds = new-object "System.Data.DataSet" "dsOpsdata"
$q = "SELECT * from MemberDatabase"
$da = new-object "System.Data.SqlClient.SqlDataAdapter" ($q, $cn)
$da.Fill($ds)
$dtOpsdata = new-object "System.Data.DataTable" "dtOpsData"
$dtOpsdata = $ds.Tables[0]
if ([string]::IsNullOrEmpty($dtOpsdata)) {
write-host "upgrading member database - fixing kb92865"
$q="EXEC MemberDatabaseAttach 'SQLSERVER\INSTANCE', 'OperationsManagerDW', 1, 1, 1"
$da = new-object "System.Data.SqlClient.SqlDataAdapter" ($q, $cn)
$da.Fill($ds)
checkMemberDatabase
} else {
write-host "member database ok"
}
}

Don’t forget to replace “SQLSERVER\INSTANCE” (2 times) in your SQL server (and instance) containing the OperationsManagerDW

Advertisements

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

 
%d bloggers like this: