3

I am trying to run a powershell script logged on as a particular user who has no "Script running" permissions. If I wanted to run the script as a different user is it possible to just add the credentials as a parameter to the script?

./Get-Something –computerName SERVER1 –filePath C:\Whatever -credentials ??

Cheers in advance! (Powershell noob)

2
  • 3
    What, pray tell, are the "script running" permissions you refer to? Commented Jul 10, 2013 at 11:56
  • i really have no idea myself :S.... Commented Jul 11, 2013 at 0:48

2 Answers 2

7
Invoke-Command -FilePath "yourPath\yourScript.ps1" -ComputerName yourServer -Credential Get-Credential
Sign up to request clarification or add additional context in comments.

2 Comments

thanks! but how do i get the correct user info using the "-Credential Get-Credential"?
You can store credential in a variable using $cred = Get-Credential "domain\username", then use it in Invoke-Command ... -Credential $cred. If you need to maintain credential across different powershell session refer to this techrepublic.com/blog/networking/…
1

You may also create a Scheduled Task invoking the script with the powershell.exe.

This provides a chance to add parameters and to run the script with elevated rights. You do not Need much code to accomplish this.

Cheers

Oliver

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.