powershell - 函数中的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
我在这里想念什么?
提前致谢。
解决方案
推荐阅读
- cluster-analysis - 如何使用 SVM 进行无服务集群 scikit-learn
- ruby-on-rails - 如何获取以 .html 结尾的 URL(使用 rails 5)
- tensorflow - 什么是 Tensorflow 版本 2.0.0 中没有属性“GraphDef”的“tensorflow”?
- c# - 将 RemoteAuthenticationHandler CallbackPath 与 IApplicationBuilder 路径匹配一起使用
- java - 如何在我的代码中实现“BigInteger 到 Integer,反之亦然”,无法解决不兼容的类型错误
- java - 使用私钥生成 JSON Web 令牌 (JWT)
- google-colaboratory - 如何以编程方式检查连接到哪个运行时 Google Colab 笔记本?
- postgresql - 如何设置 Narayana ConnectionManager 使其在某些事务后不会停止
- rust - 如何在 rust 中找到或插入 Vec
- c# - 是否可以通过 PostgreSQL 的某些 IF 条件使用 WHERE?