I have a PowerShell script/function, that takes few arguments and runs it.
Invoke-Expression ".\ScriptFile.ps1 $($Node.Name).xml C:\TempFolder\ $($Node.Name) local"
Now I want to run that as another user.
Invoke-Expression
doesn't have an inherent parameter credential
that facilitates this. On the other hand Invoke-Command
has a Credential
(Get-Credential
) parameter that facilitates running as another user. I tried replacing Invoke-Expression
with Invoke-Command
with no luck.
How do I tackle this to run the above expression as another user?
Structure of Script Resource.
Script Deploy
{
SetScript =
@"
Set-Location D:\Deploy
Invoke-Expression ".\ScriptFile.ps1 $($Node.Name).xml C:\TempFolder\ $($Node.Name) local"
"@
TestScript =
{
return $false
}
GetScript = {
return @{
GetScript = $GetScript
SetScript = $SetScript
TestScript = $TestScript
}
}
DependsOn = "[File]CopyMe"
}
P.S.: All this happens inside a SetScript of Script
User in Desired State Configuration.