Run whole script with different credentials

Hi Team,
I am having a script which maps drives for robocopy and then does changes on a group of files on the destination folder. How do I run this whole script with different credentials depending on the domain. I tried creating a hashtable with diff credentials and then running the script inside invoke-command using credentials parameter but I get below error;
Cannot process argument transformation on parameter ‘Credential’. Cannot invoke this function because the current host does not implement it.

Regards,
Kishor

Well, without seeing your code, or at least some of it, it’s impossible to tell you what the error is referring to.

However, “to run an entire script under different credentials” you would use Start-Process or Invoke-Command. But you can’t provide a hash table of credentials to either of those; you need to flat-out provide a credential. You’ll probably have to write a “wrapper” script that makes the decision on which credential to use.

Hi Don,
Thanks for your time, below is the link for the script;
https://gist.github.com/kdsuvarna/c29a35d813477e537769b0b4a07d52f5

Regards,
Kishor

Another thing to mention is I am running this script in a ‘Run .Net’ SCO activity which is failing with this error.

Thanks,
Kishor

You would need, then, to have SCO running the script under alternate credentials. There’s not a way to assert a new identity within the script itself.

Thank you Don!