Author Posts

April 4, 2017 at 11:19 pm

I'm new to BizTalk and am unsure how to approach something. I am using the BizTalkFactory.Powershell.Extensions SnapIn which I have scripted some things like starting and stopping host instances etc. This script works just fine when I run it as x86. However I also have some code that does a bunch of other things like creating, stopping removing IIS application pools etc which seem to not work as x86. If I add all my code snipits into one continuous script as I need to I have to switch back and forth between x86 and x64.

Is there a way to load the BizTalk snapin to run under x64 or call the x86 snipits from the x64 script? I currently have something like:

&C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe {
    Write "Switch to 32-bit mode to register Powershell extension"
    LoadBizTalkSnapin
    StopHostInstances
    StopApplications
    UninstallBizTalkApplications
    Write "Exit this instance of 32 bit shell"
}
UninstallApplications
StopApplicationPools
if($BareBones){
    RemoveApplicationPools
    RemoveFromGAC
    DeleteFolder
    &C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe {
        Write "Switch to 32-bit mode to register Powershell extension"
        RemoveAdapterBinding
        RemoveHost
        RemoveHostInstance
        Write "Exit this instance of 32 bit shell"
    }
}

Previously when I tested the code below it worked:

&C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe {
    Add-PSSnapin -Name BizTalkFactory.Powershell.Extensions
    New-PSDrive -Name BizTalk -PSProvider BizTalk -Root "BizTalk:\" -Instance $DBInstance -Database BizTalkMgmtDb
}

However, once I changed the actual code to refer to functions I have written it no longer worked. Any help in pointing me in the right direction would be extremely appreciated.

April 4, 2017 at 11:24 pm

Short answer: no.

Also, there's no long answer. 64-bit and 32-bit don't play along in the same runspace. However...

However, once I changed the actual code to refer to functions I have written it no longer worked. Any help in pointing me in the right direction would be extremely appreciated.

I don't think I understand what you're saying. "...refer to functions I have written?"

April 4, 2017 at 11:34 pm

What I meant about using a function was...
The following works without using a function:

&C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe {
    Add-PSSnapin -Name BizTalkFactory.Powershell.Extensions
    New-PSDrive -Name BizTalk -PSProvider BizTalk -Root "BizTalk:\" -Instance $DBInstance -Database BizTalkMgmtDb
}

However this does not work:

function BizTalkSnapin{
    Add-PSSnapin -Name BizTalkFactory.Powershell.Extensions
    New-PSDrive -Name BizTalk -PSProvider BizTalk -Root "BizTalk:\" -Instance $DBInstance -Database BizTalkMgmtDb
}

&C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe {
    BizTalkSnapin
}

April 4, 2017 at 11:37 pm

Ok, sure – that's because, in a new PowerShell.exe instance, your functions don't exist and aren't loaded by default. Look what you've done there: You've defined the function, but then launched a brand-new copy of PowerShell. That copy is a whole new process and doesn't know about your function.

For that to work, your function would need to be in a script module (.psm1) file, properly located in one of the module folders where PowerShell "knows" to look. Assuming you're using PowerShell v2 or later.