使用不同的凭据运行ScriptBlock(Run ScriptBlock with different credentials)

编程入门 行业动态 更新时间:2024-10-28 14:22:26
使用不同的凭据运行ScriptBlock(Run ScriptBlock with different credentials)

我有一个脚本,它决定了一个用户标识符,一旦我拥有了这个用户标识符,我想使用不同的凭证针对这个用户标识符运行一个脚本块。 这可能吗? 任何人都可以告诉我这个例子吗? 我很感激。 提前致谢。 :-)

I have a script, that determines a userid, once I have that userid, I want to run a script block against that userid using different credentials. Is this possible? Can anyone show me examples of this? I appreciate it. Thanks in advance. :-)

最满意答案

我明白了,感谢Trevor Sullivan指引我朝着正确的方向前进。 我最终只是将我的第二个ps1文件放入一个scriptblock中,并将其作为一个工作运行,并将主脚本中的参数传递给它,如下所示

$job = Start-Job -scriptblock { param ($username) some code to run against the variable that was passed in } -Args $target -credential $Cred

$ target是我想传递给我的scriptblock的变量。 $ username是scriptblock接受的参数谢谢。

I got it, thanks to Trevor Sullivan for pointing me in the right direction. I ended up just putting my second ps1 file into a scriptblock, and running it as a job, and passing it the arguments from the main script, like this

$job = Start-Job -scriptblock { param ($username) some code to run against the variable that was passed in } -Args $target -credential $Cred

$target being the variable I want to pass to my scriptblock. $username being the parameter that the scriptblock accepts Thanks.

更多推荐

本文发布于:2023-07-05 02:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1032098.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:凭据   ScriptBlock   credentials   Run

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!