Solved

Powershell Command does not execute in Powershell Script?

Posted on 2011-09-13
10
2,044 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
Comment Utility
Use this command

>& path.ps1
0
 
LVL 8

Accepted Solution

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

Expert Comment

by:Bryan Butler
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:mhotto
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
A procedure for exporting installed hotfix details of remote computers using powershell
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). …
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…

744 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

16 Experts available now in Live!

Get 1:1 Help Now