sanjay
sanjay

Reputation: 65

Remote execution of PowerShell script on BizTalk servers

I am trying to run a PowerShell script to return the status of host instances on a BizTalk server from my local machine. When I tried this script from the BizTalk server I am able to get the information, however I am not able to run that script using invoke command.ps remoting is already enabled because I can run a basic write-host using the invoke command. No result is getting displayed when I run it remotely. The script I used and the output I am getting are below.

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

Output is :

PS C:\windows\system32> C:\Users\SRamadugu\Desktop\bizzzzz.ps1

HELLO

Host Instance Information ( )

()

Tracking Host(s)

Upvotes: 0

Views: 495

Answers (2)

felixmondelo
felixmondelo

Reputation: 1474

You have to import module BizTalkFactory.PowerShell.Extensions.dll on remote:

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

Upvotes: 0

Steven Van Eycken
Steven Van Eycken

Reputation: 566

Have you enabled Powershell Remote Commands on your BizTalk server?

Powershell Remoting

Upvotes: 0

Related Questions