PowerShell, BizTalk and changing Host Instance configuration

Tag: powershell , biztalk Author: wujg204329 Date: 2012-03-07

Yet another PowerShell/BizTalk question, but first some background:

We have a lot of (8 inprocess, 2 isolated) Host Instances on one developer environment. One of the instances has gone corrupt ("Installation Failed" as status in Admin Console). I saw that it was lacking password and tried to update it manually. No luck, the password I had was wrong and it was also the same password stored for the account in our CMDB... Oh, well. Just to reset it and change it on all host instances.

Well, I wanted to try out to do it the PowerShell way. It kind of works, but only if the instances is in ServiceState 8? ServiceState 4 (started) of course gives an error. But so does ServiceState 1 (stopped)?

Very annoying. It is the method Install that fails:

Exception calling "Install" : "A failure occurred while installing the Windows NT service BTSSvc$Test_host. Please verify the following: 1) The credentials supplied are correct and the specified user name has the "log on as service" privilege enabled. 2) All Microsoft Management Console (MMC) Service windows are closed. The Window s Service Control Manager will not allow the creation of a service if the service has been deleted but is still referenced by an open MMC window. "

Code:

$hosts = Get-WmiObject MSBTS_HostInstance -namespace 'root/MicrosoftBizTalkServer'
foreach($hostinst in $hosts)
{
    if ($hostinst.Logon -eq $acc)
    {
        if($hostinst.ServiceState -eq 1 -or 8)
        {
            write-host "Hostinstans" $hostinst.HostName "har ServiceState" $hostinst.ServiceState
            $hostinst.Install($acc, $pw, "True")
            Start-Sleep -Seconds 30
            write-host "Hostinstans" $hostinst.HostName "har nytt lösenord och ServiceState" $hostinst.ServiceState
        }
    }
}

Anyone got ideas? It is annoying the cr*p out of me!

Best regards,

Joakim

Other Answer1

$hostinst.ServiceState -eq 1 -or 8

should be rewritten

($hostinst.ServiceState -eq 1) -or ($hostinst.ServiceState -eq 8)

Try out in your PowerShell console:

3 -eq 1 -or 8

comments:

Hmmm, I see what you mean there... But, since the IF-statement returns TRUE it will run my code and try to install the hostinstance with new credentials and that, in turn, will fail if the ServiceState is other than 8 (Installation Failed)...
Don't you have to call the Map method, before calling install?
Might be so, but then is the question why it works when the instance is in ServiceState 8? Hmm, I'll try that as well...
Well, I might be doing something wrong here... I cannot invoke the method Install() on a in-process instance which is in the ServiceState 1 or 4. I can do that on a instance which is in ServiceState 8. I cannot use the method UnMap() or Map() as suggested. I get several errors that the instance is in the wrong state... Do I really have to totally uninstall the handlers, hostinstance and then the host and then re-create them again? When I do a operation like this in the Admin Console I can't see any evidence of that kind of method...

Other Answer2

Found the answer!

If the instance is in ServiceState 1 I have to uninstall it before making any changes to it! My code for this should be like this (for example):

    $hosts = Get-WmiObject MSBTS_HostInstance -namespace 'root/MicrosoftBizTalkServer'
foreach($hostinst in $hosts)
{
    if ($hostinst.Logon -eq $acc)
    {
        if(($hostinst.ServiceState -eq 1) -or ($hostinst.ServiceState -eq 8))
        {
            if($hostinst.ServiceState -eq 1)
            {
               $hostinst.Uninstall()
            }
            write-host "Hostinstans" $hostinst.HostName "har ServiceState"     $hostinst.ServiceState
            $hostinst.Install($acc, $pw, "True")
            Start-Sleep -Seconds 30
            write-host "Hostinstans" $hostinst.HostName "har nytt lösenord och ServiceState" $hostinst.ServiceState
        }
    }
}