在BizTalk服务器上远程执行PowerShell脚本

时间:2017-07-06 03:22:55

标签: biztalk

我正在尝试运行PowerShell脚本,以便从本地计算机返回BizTalk服务器上的主机实例的状态。当我从BizTalk服务器尝试此脚本时,我能够获取信息,但是我无法使用invoke命令运行该脚本。已经启用了远程处理,因为我可以使用invoke命令运行基本的写入主机。远程运行时没有显示结果。我使用的脚本和我得到的输出如下。

Invoke-command -ComputerName XXXXXXXXXXXXXX -ScriptBlock{
write-host "HELLO"
Write-Host "`nHost Instance Information ("$hostInstances.Count")" -fore DarkGray

foreach ($hostInstance in $hostInstances) {
    switch ($hostInstance.servicestate) {
        1 { $hostInstanceState = "Stopped" }
        2 { $hostInstanceState = "Start pending" }
        3 { $hostInstanceState = "Stop pending" }
        4 { $hostInstanceState = "Running" }
        5 { $hostInstanceState = "Continue pending" }
        6 { $hostInstanceState = "Pause pending" }
        7 { $hostInstanceState = "Paused" }
        8 { $hostInstanceState = "Unknown" }
    }
    switch ($hostInstance.HostType) {
        1 { $hostInstanceType = "In-process" }
        2 { $hostInstanceType = "Isolated" }
    }
    if ($hostInstanceState -eq "Running") {
        Write-Host $hostInstance.hostname "($hostInstanceType)" "- "  -NoNewline
        Write-Host $hostInstanceState -fore green
    }
    elseif ($hostInstanceState -eq "Stopped") {
            if ($hostInstance.IsDisabled -eq $true ) {
                Write-Host $hostInstance.hostname "($hostInstanceType)" "- " -NoNewline
                Write-Host $hostInstanceState "(Disabled)" -fore red
            }
            else {
                Write-Host $hostInstance.hostname "($hostInstanceType)" "- " -NoNewline
                Write-Host $hostInstanceState -fore Red
            }
    }
    else {
        if ($hostInstanceType -eq "In-process") {
            Write-Host $hostInstance.hostname "($hostInstanceType)" "- " -NoNewline
            Write-Host $hostInstanceState "(Disabled:$($hostInstance.IsDisabled))" -fore DarkYellow
        }
        else {
            Write-Host $hostInstance.hostname "($hostInstanceType)"
        }
    }
}
}

输出是:

  

PS C:\ windows \ system32> C:\ Users \用户SRamadugu \桌面\ bizzzzz.ps1

     

您好

     

主机实例信息()

     

()

     

跟踪主机

2 个答案:

答案 0 :(得分:0)

您是否在BizTalk服务器上启用了Powershell远程命令?

Powershell Remoting

答案 1 :(得分:0)

您必须在远程导入模块BizTalkFactory.PowerShell.Extensions.dll:

Invoke-command -ComputerName XXXXXXXXXXXXXX -ScriptBlock {
   Import-Module $remoteBizTalkPowerShellExtensionsPath -force
...