Solved

Powershell Command does not execute in Powershell Script?

Posted on 2011-09-13
10
2,328 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DFS issue 3 26
format log file 2 21
PowerShell Move Folders and Files 3 12
Powershell query for OU membership 5 36
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A brief introduction to what I consider to be the best editor for PowerShell.
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

829 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