PowerShell 从 .ps1 运行具有多个参数的函数



我正在尝试运行位于 .ps1 文件中的函数。该函数接受两个参数,可以是字符串或 int。这是我的代码:

文件名: 设置农场属性.ps1

Function SetFarm ($property_name, $property_value) `
{
    $farm = Get-SPFarm
    $farm.Properties.Add($property_name, $property_value)
    $farm.properties
}

当我进入我的PowerShell会话并键入时

.SetFarmProp.ps1
SetFarm "testkey" "testvalue1"

我收到一个错误,指出"SetFarm"不是 cmdlet、函数、脚本文件或可操作程序的可识别名称。

尝试点采购:

. .SetFarmProp.ps1
SetFarm "testkey" "testvalue1"

或者只是:

.SetFarmProp.ps1 "testkey" "testvalue1"

如果将 .ps1 文件修改为:

param ($property_name, $property_value)
{
    $farm = Get-SPFarm
    $farm.Properties.Add($property_name, $property_value)
    $farm.properties
}

最新更新