0
votes

I have big problem when trying to execute a PowerShell function which is in another file.

This is my initial .ps1 file:

$scriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent

$file = Get-Item $scriptDir\JSONFile1.json
$plaintext = $file | Get-Content

.\Functions\Add-Folder.ps1 -AdlsAccountName "Hello World"

The file Add-Folder.ps1 consists of the following content:

[CmdletBinding()]
Param(
   [Parameter(Mandatory=$True,Position=1)]
   [string] $AdlsAccountName
)

Write-Host $AdlsAccountName

But when i execute this .ps1 script i receive the following error:

##[error]The term '.\Add-Folder.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

1

1 Answers

0
votes

Try to add dot when you referencing files:

. .\Functions\Add-Folder.ps1 -AdlsAccountName "Hello World"

This technique named dot sourcing.

More info: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scripts

https://ss64.com/ps/source.html