Link to home
Start Free TrialLog in
Avatar of Pau Lo
Pau Lo

asked on

powershell execution

How to you run a powershell script?

Downloaded the tool:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe

I open the powershell gui (powershell .exe)

Change the directory to where my ps1 file is so now at my powershell command prompt I have:

PS C:\documents and settings\me\desktop>

and I enter the name of the script i.e. myscript.ps1

so I have executed

PS C:\documents and settings\me\desktop>myscript.ps1

I get an error:

The term 'myscript.ps1' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and tr
y again.
At line:1 char:10
+ revgui.ps1 <<<<

Where am I going wrong?
Avatar of soostibi
soostibi
Flag of Hungary image

You have to use relative or absolute path:

.\mycsript.ps1

or

& 'C:\documents and settings\me\desktop\myscript.ps1'

Second time as the path include space you have to put it into quotation marks and use the invoke operator (&).

You also have to enable script execution before:

set-executionpolicy remotesigned
Avatar of Pau Lo
Pau Lo

ASKER

Thanks

Do you first execute set-executionpolicy remotesigned (and hit return)

or is it one continual string i.e.

PS C:\documents and settings\me\desktop> set-executionpolicy remotesigned & & 'C:\documents and settings\me\desktop\myscript.ps1'

Regards
Set-executionpolicy is a separate expression.
Avatar of Pau Lo

ASKER

Cheers
Avatar of Pau Lo

ASKER

I now get an error whilst execting:

PS C:\documents and settings\me\desktop> .\ms.ps1

that reads:

File C:\documents and settings\me\Desktop\ms.ps1 cannot be loaded. The file C:\documents and settings\me\Desktop\ms.ps1 is not digitally signed. The script will not execute on the system. Please see "get-help about_signng" for more details..
At line:1 char:12
+ .\ms.ps1 <<<<
Avatar of Pau Lo

ASKER

I am running it under basic domain user priveleges not domain admin but I do have local admin account for this machine if required
Have you run:

set-executionpolicy remotesigned

Avatar of Pau Lo

ASKER

Yeah
Strange, it should run it.
Try the following:

set-executionpolicy bypass

And try to run the script again.
Avatar of Pau Lo

ASKER

Will do gimme two mins
Avatar of Pau Lo

ASKER

When I issue that (Set-executionpolicy bypass) command I get:

Set-ExecutionPolicy : A parameter cannot be found that matches parameter name 'bypass'. At line:1 char:20 +set executionpolicy <<<< bypass
So you have PowerShell 1.0?
Avatar of Pau Lo

ASKER

Hi soostibi - yeah thats right, why do you ask?
Just wondering how to resolve this issue. For v1.0 you may use:

set-executionpolicy unrestricted
Avatar of Pau Lo

ASKER

will give it a go when back in the office, cheers
Avatar of Pau Lo

ASKER

maybe i should download the latest version of pweshell, would that be v2?
ASKER CERTIFIED SOLUTION
Avatar of soostibi
soostibi
Flag of Hungary image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pau Lo

ASKER

Cool, it works.