Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Start learning PS

Reply
 
Old 05-11-2007   #1 (permalink)
gurbao


 
 

Start learning PS

Hi
as a starter, I want to create some scripts to manipulate a file or
two.
The idea is to script up a simple todo.txt file to add add entries
(activities), change entries, search entries etc. (Like http://www.todotxt.com)
I want to manipulate the file by adding commands at the commant
prompt, e.g. "add <some text here>" or "list <searchcriteria>".

As a "proof of concept" I was thinking of using a .bat files that
again would call different .ps1 scriptfiles to manipulate the file.
E.g.

list.bat:
C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -noprofile -
nologo -noninteractive -command "& 'list.ps1 %1' "

list.ps1:
gc c:\temp\todo.txt | where {$_ -match $args[0]} | sort

However I can't get this to work. All I get is:

The term 'list.ps1 work' is not recognized as a cmdlet, function,
operable prog
ram, or script file. Verify the term and try again.
At line:1 char:2
+ & <<<< 'list.ps1 work'

I have changed the Set-ExecutionPolicy to RemoteSigned.

Can someone please tell me what I am doing wrong or how I should do
this?

Thanks,


My System SpecsSystem Spec
Old 05-11-2007   #2 (permalink)
RichS


 
 

RE: Start learning PS

Couple of points

Why call the powershell scripts from batch files? You could put the folder
containing the scripts on your path and then call them directly.

If you have to call them this way then you need to give the full path to the
script eg

...... - comand c:\scripts\list.ps1 etc

if you are trying to run list.ps1 from the folder its in then remember that
the current folder isn't automatically on the path in Powershell so you need
to use

..\list.ps1


--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"gurbao" wrote:

> Hi
> as a starter, I want to create some scripts to manipulate a file or
> two.
> The idea is to script up a simple todo.txt file to add add entries
> (activities), change entries, search entries etc. (Like http://www.todotxt.com)
> I want to manipulate the file by adding commands at the commant
> prompt, e.g. "add <some text here>" or "list <searchcriteria>".
>
> As a "proof of concept" I was thinking of using a .bat files that
> again would call different .ps1 scriptfiles to manipulate the file.
> E.g.
>
> list.bat:
> C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -noprofile -
> nologo -noninteractive -command "& 'list.ps1 %1' "
>
> list.ps1:
> gc c:\temp\todo.txt | where {$_ -match $args[0]} | sort
>
> However I can't get this to work. All I get is:
>
> The term 'list.ps1 work' is not recognized as a cmdlet, function,
> operable prog
> ram, or script file. Verify the term and try again.
> At line:1 char:2
> + & <<<< 'list.ps1 work'
>
> I have changed the Set-ExecutionPolicy to RemoteSigned.
>
> Can someone please tell me what I am doing wrong or how I should do
> this?
>
> Thanks,
>
>

My System SpecsSystem Spec
Old 05-11-2007   #3 (permalink)
gurbao


 
 

Re: Start learning PS

Hi

thanks for your input.

I have done as you suggested; skipping the .bat files and calling
the .ps1 scripts directly.

But what am I doing wrong when I can't get the params into the script?

list.ps1:
$args[0]

Calling this script with a parameter ("list test)"will not display
anything. Why?

Thanks,

On May 11, 10:31 am, RichS <R...@discussions.microsoft.com> wrote:
> Couple of points
>
> Why call the powershell scripts from batch files? You could put the folder
> containing the scripts on your path and then call them directly.
>
> If you have to call them this way then you need to give the full path to the
> script eg
>
> ..... - comand c:\scripts\list.ps1 etc
>
> if you are trying to run list.ps1 from the folder its in then remember that
> the current folder isn't automatically on the path in Powershell so you need
> to use
>
> .\list.ps1
>
> --
> Richard Siddaway
> Please note that all scripts are supplied "as is" and with no warranty
> Blog:http://richardsiddaway.spaces.live.com/
> PowerShell User Group:http://www.get-psuguk.org.uk
>
>
>
> "gurbao" wrote:
> > Hi
> > as a starter, I want to create some scripts to manipulate a file or
> > two.
> > The idea is to script up a simple todo.txt file to add add entries
> > (activities), change entries, search entries etc. (Likehttp://www.todotxt.com)
> > I want to manipulate the file by adding commands at the commant
> > prompt, e.g. "add <some text here>" or "list <searchcriteria>".

>
> > As a "proof of concept" I was thinking of using a .bat files that
> > again would call different .ps1 scriptfiles to manipulate the file.
> > E.g.

>
> > list.bat:
> > C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -noprofile -
> > nologo -noninteractive -command "& 'list.ps1 %1' "

>
> > list.ps1:
> > gc c:\temp\todo.txt | where {$_ -match $args[0]} | sort

>
> > However I can't get this to work. All I get is:

>
> > The term 'list.ps1 work' is not recognized as a cmdlet, function,
> > operable prog
> > ram, or script file. Verify the term and try again.
> > At line:1 char:2
> > + & <<<< 'list.ps1 work'

>
> > I have changed the Set-ExecutionPolicy to RemoteSigned.

>
> > Can someone please tell me what I am doing wrong or how I should do
> > this?

>
> > Thanks,- Hide quoted text -

>
> - Show quoted text -



My System SpecsSystem Spec
Old 05-11-2007   #4 (permalink)
gurbao


 
 

Re: Start learning PS


Hi,
just for clarification;
it works fine from the PS prompt, but I am having trouble with the
output running the script from the DOS prompt.

Thanks,


On May 11, 4:02 pm, gurbao <aud...@gmail.com> wrote:
> Hi
>
> thanks for your input.
>
> I have done as you suggested; skipping the .bat files and calling
> the .ps1 scripts directly.
>
> But what am I doing wrong when I can't get the params into the script?
>
> list.ps1:
> $args[0]
>
> Calling this script with a parameter ("list test)"will not display
> anything. Why?
>
> Thanks,
>
> On May 11, 10:31 am, RichS <R...@discussions.microsoft.com> wrote:
>
>
>
> > Couple of points

>
> > Why call the powershell scripts from batch files? You could put the folder
> > containing the scripts on your path and then call them directly.

>
> > If you have to call them this way then you need to give the full path to the
> > script eg

>
> > ..... - comand c:\scripts\list.ps1 etc

>
> > if you are trying to run list.ps1 from the folder its in then remember that
> > the current folder isn't automatically on the path in Powershell so you need
> > to use

>
> > .\list.ps1

>
> > --
> > Richard Siddaway
> > Please note that all scripts are supplied "as is" and with no warranty
> > Blog:http://richardsiddaway.spaces.live.com/
> > PowerShell User Group:http://www.get-psuguk.org.uk

>
> > "gurbao" wrote:
> > > Hi
> > > as a starter, I want to create some scripts to manipulate a file or
> > > two.
> > > The idea is to script up a simple todo.txt file to add add entries
> > > (activities), change entries, search entries etc. (Likehttp://www.todotxt.com)
> > > I want to manipulate the file by adding commands at the commant
> > > prompt, e.g. "add <some text here>" or "list <searchcriteria>".

>
> > > As a "proof of concept" I was thinking of using a .bat files that
> > > again would call different .ps1 scriptfiles to manipulate the file.
> > > E.g.

>
> > > list.bat:
> > > C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -noprofile -
> > > nologo -noninteractive -command "& 'list.ps1 %1' "

>
> > > list.ps1:
> > > gc c:\temp\todo.txt | where {$_ -match $args[0]} | sort

>
> > > However I can't get this to work. All I get is:

>
> > > The term 'list.ps1 work' is not recognized as a cmdlet, function,
> > > operable prog
> > > ram, or script file. Verify the term and try again.
> > > At line:1 char:2
> > > + & <<<< 'list.ps1 work'

>
> > > I have changed the Set-ExecutionPolicy to RemoteSigned.

>
> > > Can someone please tell me what I am doing wrong or how I should do
> > > this?

>
> > > Thanks,- Hide quoted text -

>
> > - Show quoted text -- Hide quoted text -

>
> - Show quoted text -



My System SpecsSystem Spec
Old 05-11-2007   #5 (permalink)
hecks@hotmail.co.uk


 
 

Re: Start learning PS

On May 11, 7:56 pm, gurbao <aud...@gmail.com> wrote:
> Hi,
> just for clarification;
> it works fine from the PS prompt, but I am having trouble with the
> output running the script from the DOS prompt.
>
> Thanks,
>
> On May 11, 4:02 pm, gurbao <aud...@gmail.com> wrote:
>
> > Hi

>
> > thanks for your input.

>
> > I have done as you suggested; skipping the .bat files and calling
> > the .ps1 scripts directly.

>
> > But what am I doing wrong when I can't get the params into the script?

>
> > list.ps1:
> > $args[0]

>
> > Calling this script with a parameter ("list test)"will not display
> > anything. Why?

>
> > Thanks,

>
> > On May 11, 10:31 am, RichS <R...@discussions.microsoft.com> wrote:

>
> > > Couple of points

>
> > > Why call the powershell scripts from batch files? You could put the folder
> > > containing the scripts on your path and then call them directly.

>
> > > If you have to call them this way then you need to give the full path to the
> > > script eg

>
> > > ..... - comand c:\scripts\list.ps1 etc

>
> > > if you are trying to run list.ps1 from the folder its in then remember that
> > > the current folder isn't automatically on the path in Powershell so you need
> > > to use

>
> > > .\list.ps1

>
> > > --
> > > Richard Siddaway
> > > Please note that all scripts are supplied "as is" and with no warranty
> > > Blog:http://richardsiddaway.spaces.live.com/
> > > PowerShell User Group:http://www.get-psuguk.org.uk

>
> > > "gurbao" wrote:
> > > > Hi
> > > > as a starter, I want to create some scripts to manipulate a file or
> > > > two.
> > > > The idea is to script up a simple todo.txt file to add add entries
> > > > (activities), change entries, search entries etc. (Likehttp://www.todotxt.com)
> > > > I want to manipulate the file by adding commands at the commant
> > > > prompt, e.g. "add <some text here>" or "list <searchcriteria>".

>
> > > > As a "proof of concept" I was thinking of using a .bat files that
> > > > again would call different .ps1 scriptfiles to manipulate the file.
> > > > E.g.

>
> > > > list.bat:
> > > > C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -noprofile -
> > > > nologo -noninteractive -command "& 'list.ps1 %1' "

>
> > > > list.ps1:
> > > > gc c:\temp\todo.txt | where {$_ -match $args[0]} | sort

>
> > > > However I can't get this to work. All I get is:

>
> > > > The term 'list.ps1 work' is not recognized as a cmdlet, function,
> > > > operable prog
> > > > ram, or script file. Verify the term and try again.
> > > > At line:1 char:2
> > > > + & <<<< 'list.ps1 work'

>
> > > > I have changed the Set-ExecutionPolicy to RemoteSigned.

>
> > > > Can someone please tell me what I am doing wrong or how I should do
> > > > this?

>
> > > > Thanks,- Hide quoted text -

>
> > > - Show quoted text -- Hide quoted text -

>
> > - Show quoted text -


What line are you using exactly? This works fine here:

powershell c:\scripts\test.ps1 test

-Hecks

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Learning .NET .NET General
Virtualization learning Virtual Server
Learning Script? VB Script
Learning .NET for PowerShell PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46