I am trying to make it easier to run certain things with certain users from powershell.
So first I calculate username and domain needed to run a specific command, which is no problem.
But then I want to be able to run a specific command with the calculated credentials, and this fails. I have already tried the following variants:
# this does not work yet (the command works, but the alias/function doesn't
# function aduc {"runas /user:$currentUserDomain\$adminUserNameTier0 dsa.msc"}
# function aduc {& "runas /user:$currentUserDomain\$adminUserNameTier0 dsa.msc"}
# function aduc {Invoke-Command -NoNewScope -ScriptBlock {runas /user:$currentUserDomain\$adminUserNameTier0 dsa.msc}}
# function aduc {Invoke-Command -NoNewScope -ScriptBlock {& "runas /user:$currentUserDomain\$adminUserNameTier0 dsa.msc"}}
Whenever I call "aduc", I get:
aduc : The term 'runas /user:DOMAIN\USER dsa.msc' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
(I put DOMAIN\USER in the error message for data protection, of course in reality we are using real, existing values)
Any idea how to get this to work?