Solved

Powershell Command does not execute in Powershell Script?

Posted on 2011-09-13
10
2,142 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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:bchallis
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article will help you understand what HashTables are and how to use them in PowerShell.
A brief introduction to what I consider to be the best editor for PowerShell.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now