![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Learning .NET | .NET General | |||
| Virtualization learning | Virtual Server | |||
| Learning Script? | VB Script | |||
| Learning .NET for PowerShell | PowerShell | |||