首页 > 解决方案 > 函数中的Powershell调用命令

问题描述

我试图在函数内执行调用命令,但很难让定义的变量通过。

  function Set-RemoteLocalAdmin {

    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [string]$ComputerName,
    [String] $UserId
    )
      $sb = {​
param($userid)
    add-LocalGroupMember -Group "Administrators" -Member "$UserId"}

Invoke-Command -ComputerName $ComputerName -Scriptblock $sb -argumentlist $userid 
}


错误:术语“​”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。+ CategoryInfo : ObjectNotFound: (​:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException + PSComputerName : COMPUTERNAME-1

术语“param”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。+ CategoryInfo : ObjectNotFound: (param:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException + PSComputerName : COMPUTERNAME-1

在管理员组中找不到成员 BUILTIN\。+ CategoryInfo:ObjectNotFound:(BUILTIN:String)[Add-LocalGroupMember],MemberNotFoundException + FullyQualifiedErrorId:MemberNotFound,Microsoft.PowerShell.Commands.AddLocalGroupMemberCommand + PSComputerName:COMPUTERNAME-1


我在这里想念什么?

提前致谢。

标签: powershell

解决方案


推荐阅读