调用命令错误“无法使用指定的命名参数解析参数集" [英] Invoke-Command error "Parameter set cannot be resolved using the specified named parameters"

查看:74
本文介绍了调用命令错误“无法使用指定的命名参数解析参数集"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望您能帮助我解决尝试在本地计算机上使用备用凭据执行脚本块的问题.我一直在论坛上进行彻底搜索并进行了一些谷歌搜索,并找到了两种可能的方法来解决我的问题:

Hope you can help me with a problem trying to execute a script block with alternate credentials on a local computer. I've been thoroughly searching on forums and doing some googling and found two possible approach to solve my problem:

  1. 使用调用命令
  2. 使用开始工作

使用方法 #1 我有这个代码:

Using approach #1 I had this code:

$res = Invoke-Command -Credential $migratorCreds -ScriptBlock {param($one, $two) Get-LocalUsers -parentNodeXML $one -migratorUser $two } -ArgumentList $xmlPRE,$migratorCreds

其中 Get-LocalUsers 是存储在自定义模块 (*.psm1) 中的自定义函数.

where Get-LocalUsers is a custom function stored in a custom module (*.psm1).

我的问题是每次运行此代码时都会出现以下错误:

My problem is that every time I run this code I get following error:

无法使用指定的命名参数解析参数集

Parameter set cannot be resolved using the specified named parameters

所以很明显我一定遗漏了一些东西,你能帮我解决这个话题吗?

So it's obvious that I must be missing something, could you help me on this topic?

提前致谢...

推荐答案

您遇到的错误是因为 -credential 没有 -computername 不能存在.

The error you have is because -credential without -computername can't exist.

你可以试试这个:

Invoke-Command -Credential $migratorCreds  -ScriptBlock ${function:Get-LocalUsers} -ArgumentList $xmlPRE,$migratorCreds -computername YOURCOMPUTERNAME

这篇关于调用命令错误“无法使用指定的命名参数解析参数集"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆