Is it impossible to run powershell scripts that I wrote locally without admin privileges even if the scripts themselves dont require admin rights?

0

Im a standard user without admin privileges on my windows 7 box. I wrote a powershell script that doesn't require admin privileges (it downloads data from yahoo finance and saves it as a CSV file):

$client = New-Object System.Net.WebClient
$yf_url = "http://download.finance.yahoo.com/d/quotes.csv?s=EDV,BND&f=sl1d1t1c1ohgv&e=.csv"
$yf_file = "prices.csv"
$client.DownloadFile($yf_url, $yf_file)

From Get-ExecutionPolicy I know that the security policy on my system is set to Restricted (the default), but Im wondering if there is a way to run this script without having admin privileges.

If I write a powershell script locally that doesnt require admin privileges, is there a way to set the execution policy so I can run it, without having to elevate myself to admin (which I cant do because its a work computer)?

when i runt he script with Invoke-Expression get_prices.ps1 in the folder D:\myfiles (D: is a second hard drive) I get the error message:

File D:\myfiles\get_prices.ps1 cannot be loaded because the execution of scripts is disabled on your system

Michael A

Posted 2014-06-04T16:00:07.823

Reputation: 648

what folder are you downloading to? you should be able to execute a script as a normal user if that script doesn't do anything that requires admin. do you have full control of the destination directory? – Frank Thomas – 2014-06-04T16:03:00.807

@FrankThomas yes I do. I'm downloading to the local folder which right now is simply D:\myfiles\prices.csv (D: is a second hard drive). I added part of the error message (cant copy/paste from powershell but ill type the rest in in a bit) – Michael A – 2014-06-04T16:03:45.777

Answers

2

Try running the script like this from the Run prompt or a Shortcut:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File D:\myfiles\get_prices.ps1

Tim Ferrill

Posted 2014-06-04T16:00:07.823

Reputation: 588

How can I execute command directly instead of ps file? $password = ConvertTo-SecureString "password" -AsPlainText -Force; $cred= New-Object System.Management.Automation.PSCredential ("username", $password ); $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://domain/PowerShell/ -Authentication Kerberos -Credential $cred; Import-PSSession $Session -DisableNameChecking;

When i tried it thrown error

– Mak – 2019-09-30T10:56:40.137

That works! Apparently I just need to specify the full file path for the prices.csv file. it must have been trying to write it somewhere that requird admin privileges. – Michael A – 2014-06-04T16:48:41.380

It's not an issue of admin privileges. Running powershell.exe gives you access to switches like -ExecutionPolicy, which bypasses the computer's execution policy long enough to execute that script. – Tim Ferrill – 2014-06-04T16:51:07.237