简体   繁体   中英

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. 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. I think I'm doing something wrong with $cred , but can't figure out what.

$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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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