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

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>