Invoke Command question
I'm running into what I believe is a simple problem but the solution so far escapes me. I'm trying to run an exe on a list of computers. To do this I am using Invoke Command -scriptblock {script}
But the executable will run, then fail every single time due to permissions. If I run the command locally in an administrative session, it will work. So it seems like I need open cmd.exe as admin first and then run the original command. I'm not sure how to Invoke-Command on a remote machine to open up cmd.exe as admin then run the original .exe I want. As I understood it, the invoke command uses the session credentials by default if not added with -Credentials. Even if I specifically give my credentials, it still fails. Any ideas?
Posted Sep 14, 2020, 5:05 PM UTC
You must likely need the -Credential <username> on the invoke-command. TheInvoke-Command docshas a few examples. I also found thisStackExchangearticle talking about it.I just noticed you saying -credential didn't work. You want to try Enter-PsSession with your -Credential.
I've done that as well. Created a new PS-Session and used the session as part of Invoke-Command -Session $Session