Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

powershell - Invoke-Command error "Parameter set cannot be resolved using the specified named parameters"

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. Use Invoke-Command
  2. Use Start-Job

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

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?

Thanks in advance...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

You can try this way:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...