Solved

Powershell Command does not execute in Powershell Script?

Posted on 2011-09-13
10
2,363 Views
Last Modified: 2013-08-02
I have created a single line Powershell Script - Path.ps1.  The single command is
'ls'.

The 'Path.ps1' script is in "C:\WINDOWS\system32\WindowsPowerShell\v1.0\PS1" Directory.  If I execute the Path.ps1 script, while in that specific Directory.  I get following error msg.

PS C:\WINDOWS\system32\WindowsPowerShell\v1.0\PS1> path.ps1
The term 'path.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,
 verify that the path is correct and try again.
At line:1 char:9
+ path.ps1 <<<< 
    + CategoryInfo          : ObjectNotFound: (path.ps1:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
If I execute this command at the PowerShell Command Prompt it executes.

PS C:\WINDOWS\system32\WindowsPowerShell\v1.0\PS1\ls and I I get a directory list written to console.

Why does ' Path.ps1' script fail, when the 'ls' command executes?

Thanks  for any assistance in understanding this.

Mike
0
Comment
Question by:mhotto
10 Comments
 
LVL 13

Expert Comment

by:Govvy
ID: 36531129
Use this command

>& path.ps1
0
 
LVL 8

Accepted Solution

by:
Acosta Technology Services earned 100 total points
ID: 36531184
Try:  .\path.ps1   (  .\   needs to be  manually entered  )
0
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 36531270
Sometimes the current working directory (.\) is not part of the path.  Explicitly telling it to search the current path with (.\) will make it work.  The "ls" command is a builtin type command (alias for GCI) so it doesn't need a path specified.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mhotto
ID: 36531871
To: operationnos & Goovy,

operationnos, I must have ff something, cause I did try the .\  Path qualifier, preceding my question and Path.ps1 script still failed.  However, reading your proposed solution made it work.

I still have a clarification question.  If I move up one Directory

'C:\WINDOWS\system32\WindowsPowerShell\v1.0', and try to execute .\Path.ps1',  the script fails.  I have the Environ Path (WIN XP PRO SP3), set to

%CommonProgramFiles%\Microsoft Shared\Windows Live;C:\product\10.1.3.1\OracleAS_1\jdk\bin;C:\product\10.1.3.1\OracleAS_1\ant\bin;C:\oracle\product\10.2.0\client_1\bin;C:\oraclexe\app\oracle\product\10.2.0\server\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM;C:\Program Files\QuickTime\QTSystem\;C:\product\10.1.3.1\OracleAS_1\MOBILE\sdk\bin;C:\Program Files\java\jdk-6u3\jre\bin\client;c:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\WinMerge;C:\WINDOWS\system32\WindowsPowerShell\v1.0\ps1;C:\VEDIT

How/What do I do to execute script files, from the POWERSHELL COMMAND LINE CURRENT DIRECTORY?  Example -  Current CMND LINE DIR: '>PS C:\'  '.\Path.ps1' Console Output is directory listing of C:\?

To Govvy:

I did try '&Path.ps1' and & 'Path.ps1' ,  I m guessing that the '&' is an Alias parameter/variable that should call/run the scrip - Path.ps1t.   I think that's an important attribute, I'd like to make work?  But it failed, "The term 'path.ps1' is not recognized ...."

My overall objective with using Powershell is to setup a bunch of simple script files that basically run Powershell formal commands from any Command Line Location, with my own names?  Think of the old DOS BAT FILES.

Your help and expertise is appreciated.  And my experience w Powershell is going on about 3 wks.

Thanks

0
 
LVL 16

Expert Comment

by:Dale Harris
ID: 36537299
If I were you and you wanted a bunch of pre-made functions/subroutines at your fingertips on startup, I would put it in a startup script.

Example shown here:
http://poshtips.com/2010/05/19/more-on-powershell-profile-startup-scripts/

Example on how to set one up:
http://poshtips.com/2009/11/17/setting-up-a-startup-profile-script-in-powershell/

HTH,

Dale Harris
0
 
LVL 8

Expert Comment

by:Brent Challis
ID: 36571114
If you want to effectively rename the cmdlets, you can create your own aliases for them.  To have this happen every time you start Powershell or any variation on Powershell such as a management shell for sharepoint or exchange, create a file called profile.ps1 in the C:\Windows\System32\WindowsPowerShell\v1.0 directory and put the cmdlets to create the aliases in it (e.g. new-alias list get-childitem).
 
That said creating your own aliases can be a mixed blessing as it means that you environment is not the same as the standard setup which can increase the amount of learning needed by new staff.

0
 
LVL 16

Assisted Solution

by:Bryan Butler
Bryan Butler earned 100 total points
ID: 36583548
Maybe try adding ".\" to you path in a session:

$env:Path = $env:Path + ";.\"

Or the complete path.  EX:

$env:Path = $env:Path + ";C:\Program Files\Test\bin"


0

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
export dirsync errors detail to a CSV file. 2 29
Powershell script include embedded images 10 42
Powershell Code 4 30
need assistance with a VBscript 3 31
Synchronize a new Active Directory domain with an existing Office 365 tenant
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question