0

I have a Powershell script file called "ExecutBizTalkAppMSI.ps1" This contains a single function called "Install-BizTalkApplication". I need to execute the function on a remote server, so I use the "Invoke-Command" cmdlet as follows:

Invoke-Command -Computer $TargetServer -FilePath .\ExecuteBizTalkAppMSI.ps1 -argumentlist $MSI, $InstallFolderOnTargetServer, $Environment

Problem is, although the target script runs (I added a Write-Host directly after the Param() section), the function "Install-BizTalkApplication" is not executed.

Can anyone please let me know what I need to do to make this happen?

2
  • You probably will need to share some actual code to get help in troubleshooting this. Commented Aug 1, 2012 at 12:10
  • I'm not so sure - I just need to know if it's possible to execute a function within a script using the Invoke-Command cmdlet. If not, then what does the target script need to look like - how does it know which function to execute? Commented Aug 1, 2012 at 12:20

2 Answers 2

1

I suspect the script looks like that:

# start
function Foo {}
# end

That won't work. Two options:

  • get rid of function name {} and run script as is
  • define a function first, and run it as last step in a script

Example:

# script 1
param ($foo, $bar)
# function body...

# script 2
param ($foo, $bar)
function foo {
param ($foo, $bar)
# function body
}

foo -foo $foo -bar $bar
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Bartek that worked. Since I only have a single function contained within the script file, I decided to remove the function{}
0

You say it "contains a function called"... So, if you run that script on your local machine with those arguments.. i.e:

.\ExecuteBizTalkAppMSI.ps1 $MSI $InstallFolderOnTargetServer $Environment

It wouldn't work, because you're running a script which just loads a function, and then stops, correct? That's your problem.

If so, you'll need to add a param statement to the top of the script, before the function:

param($MSI, $InstallFolderOnTargerServer, $Environment)

And then at the bottom, outside of the function you'll have to add:

Install-BizTalkApplication $MSI $InstallFolderonTarget $Environment

This will allow the script to accept arguments, and then pass those arguments to a statement that calls the function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.