Rob Bowman
Rob Bowman

Reputation: 8701

Call a Powershell Function

I am new to Powershell and having trouble calling a function contained within a script file.

Can anyone tell me how to do this please.

I have a function defined as follows:

    function Install-BizTalkApplicationTest
{

 param(
  [Parameter(Position=0,Mandatory=$true,HelpMessage="Msi file should be existing")]
  [ValidateScript({Test-Path $_})]
  [Alias("msi")]
  [string]$MsiFile,

  [Parameter(Position=1,HelpMessage="Path wherein the resource file will be installed")]
  [Alias("path")]
  [string]$ApplicationInstallPath,

  [Parameter(Position=2,Mandatory=$true,HelpMessage="Only valid parameters are Local,Dev,Test and Prod")]
  [Alias("env")]
  [ValidateSet("Local","Dev","Prod","Test")]
  [string]$Environment,

  [bool]$BTDeployMgmtDB=$true,
  [bool]$SkipUndeploy=$true
  )

  Write-Host "param MsiFile = {0}" -f $MsiFile

 }

This function is contained in a file called TestScript.ps1

I open a Powershell command window and enter .\Testscript1.ps1. I don't get any feedback, just taken to the next PS> line.

So I try to execute by entering the function name Install-BizTalkApplicationTest. I then get the error "The term '.\Install-BizTalkApplicationTest' is not recognized as the name of a cmdlet, function, sxript file, or operable program"

Could anyone please advise how to call a function (with params) that is contained within a script file?

Thanks, Rob.

Upvotes: 1

Views: 1924

Answers (1)

J. Steen
J. Steen

Reputation: 15578

To load a script file, you have to prepend with a .. So, in full, . .\Testscript1.ps1.

Upvotes: 2

Related Questions