Solved

Powershell Command does not execute in Powershell Script?

Posted on 2011-09-13
10
2,454 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

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

Technology Partners: 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!

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
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…

738 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