简体   繁体   中英

PowerShell, BizTalk and changing Host Instance configuration

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

$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

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
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM