代码之家  ›  专栏  ›  技术社区  ›  STORM

PowerShell:收到错误“术语“…”未被识别为cmdlet、函数、脚本文件或可操作程序的名称”

  •  0
  • STORM  · 技术社区  · 7 年前

    我在尝试执行另一个文件中的PowerShell函数时遇到了大问题。

    这是我的首字母。ps1文件:

    $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"
    

    文件 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.

    1 回复  |  直到 7 年前
        1
  •  0
  •   Sergey Tunnik    7 年前

    引用文件时尝试添加点:

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

    这种技术被称为点源。

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

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