PowerShell:接收错误"The term '...' is not recognized as the name of a cmdlet, function, script file, o



尝试执行另一个文件中的powershell函数时有很大的问题。

这是我的初始.ps1文件:

$scriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$file = Get-Item $scriptDirJSONFile1.json
$plaintext = $file | Get-Content
.FunctionsAdd-Folder.ps1 -AdlsAccountName "Hello World"

文件Add-Folder.ps1由以下内容组成:

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

但是当我执行此.ps1脚本时,我会收到以下错误:

##[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.

引用文件时尝试添加点:

. .FunctionsAdd-Folder.ps1 -AdlsAccountName "Hello World"

这种名为dot源的技术。

更多信息:https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about/about/about_scripts

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

相关内容

最新更新