简体   繁体   English

以另一个用户身份运行 powershell 命令

[英]Running powershell commands as another user

I'm trying to restore a test user from the deleted objects OU and do so with a test account.我正在尝试从已删除的对象 OU 中恢复测试用户,并使用测试帐户执行此操作。 The problem is that I cannot get the test account to run the command without running into an "Access is denied" error.问题是我无法让测试帐户运行命令而不会遇到“访问被拒绝”错误。 The test user is part of a group to restore users from the deleted objects OU as I am, and I'm able to run the same command just fine.测试用户是一个组的一部分,可以像我一样从已删除的对象 OU 中恢复用户,并且我能够很好地运行相同的命令。 I think I'm doing something wrong with $cred , but can't figure out what.我想我做错了$cred ,但不知道是什么。

$Cred = get-adobject -ldapfilter "(samaccountname=LOOKATME)" -includedeletedobjects -credential "testyboi" | restore-adobject 

What am I missing?我错过了什么?

So you need to create the credential variable using所以你需要使用创建凭证变量

$cred = Get-Credential

Then you need to use that variable as the -credential parameter in your command.然后,您需要将该变量用作命令中的 -credential 参数。

get-adobject -ldapfilter "(samaccountname=LOOKATME)" -includedeletedobjects -credential 
$cred | restore-adobject

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM