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?
LVL 3
pma111Asked:
Who is Participating?
 
soostibiConnect With a Mentor Commented:
Have you tried the "unrestricted" option?
V2 is the latest version.
0
 
soostibiCommented:
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
0
 
pma111Author Commented:
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
0
Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

 
soostibiCommented:
Set-executionpolicy is a separate expression.
0
 
pma111Author Commented:
Cheers
0
 
pma111Author Commented:
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 <<<<
0
 
pma111Author Commented:
I am running it under basic domain user priveleges not domain admin but I do have local admin account for this machine if required
0
 
soostibiCommented:
Have you run:

set-executionpolicy remotesigned

0
 
pma111Author Commented:
Yeah
0
 
soostibiCommented:
Strange, it should run it.
Try the following:

set-executionpolicy bypass

And try to run the script again.
0
 
pma111Author Commented:
Will do gimme two mins
0
 
pma111Author Commented:
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
0
 
soostibiCommented:
So you have PowerShell 1.0?
0
 
pma111Author Commented:
Hi soostibi - yeah thats right, why do you ask?
0
 
soostibiCommented:
Just wondering how to resolve this issue. For v1.0 you may use:

set-executionpolicy unrestricted
0
 
pma111Author Commented:
will give it a go when back in the office, cheers
0
 
pma111Author Commented:
maybe i should download the latest version of pweshell, would that be v2?
0
 
pma111Author Commented:
Cool, it works.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.