![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | power shell in a script Hi all . i write the following command : get-process |where-object {$_.handles -gt 500} and i save it to a text file named test.msh now i want to use this simple script i made and i write the following command : c:\msh\test.msh |sort-object handles |format-list processname,handle but i get the following error : PS C:\MSH> c:\msh\test.msh |sort-object handles |format-list processname,handle Can't execute a document in the middle of a pipeline: C:\msh\test.msh. At line:1 char:16 + c:\msh\test.msh <<<< |sort-object handles |format-list processname,handle my question is how can i use a saved command line to a text file and use it in the power shell script in order to organize it ? is there something im doing wrong ? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: power shell in a script I would strongly recommend actually installing powershell.. you are working on a VERY early beta. Brandon Shell --------------- Blog: http://www.bsonposh.com/ PSH Scripts Project: www.codeplex.com/psobject d> Hi all . d> d> i write the following command : get-process |where-object {$_.handles d> -gt 500} d> d> and i save it to a text file named test.msh d> d> now i want to use this simple script i made and i write the following d> command : d> d> c:\msh\test.msh |sort-object handles |format-list processname,handle d> d> but i get the following error : d> d> PS C:\MSH> c:\msh\test.msh |sort-object handles |format-list d> processname,handle d> Can't execute a document in the middle of a pipeline: d> C:\msh\test.msh. d> At line:1 char:16 d> + c:\msh\test.msh <<<< |sort-object handles |format-list d> processname,handle d> my question is how can i use a saved command line to a text file and d> use it in the power shell script in order to organize it ? is there d> something im doing wrong ? d> |
My System Specs![]() |
| | #3 (permalink) |
| | Re: power shell in a script don5 wrote: Quote: > Hi all . > > i write the following command : get-process |where-object {$_.handles -gt 500} > > and i save it to a text file named test.msh > > now i want to use this simple script i made and i write the following > command : > > c:\msh\test.msh |sort-object handles |format-list processname,handle > > but i get the following error : > > PS C:\MSH> c:\msh\test.msh |sort-object handles |format-list > processname,handle > Can't execute a document in the middle of a pipeline: C:\msh\test.msh. > At line:1 char:16 > + c:\msh\test.msh <<<< |sort-object handles |format-list processname,handle > > > my question is how can i use a saved command line to a text file and use it > in the power shell script in order to organize it ? is there something im > doing wrong ? > > fine. Maybe consider going to the release version of PowerShell. Might be a bug/issue with one of the beta versions of Monad. Marco -- Microsoft MVP - Windows PowerShell http://www.microsoft.com/mvp PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com |
My System Specs![]() |
| | #4 (permalink) |
| | Re: power shell in a script On Dec 3, 9:59 am, don5 <d...@xxxxxx> wrote: Quote: > Hi all . > > i write the following command : get-process |where-object {$_.handles -gt 500} > > and i save it to a text file named test.msh > > now i want to use this simple script i made and i write the following > command : > > c:\msh\test.msh |sort-object handles |format-list processname,handle > > but i get the following error : > > PS C:\MSH> c:\msh\test.msh |sort-object handles |format-list > processname,handle > Can't execute a document in the middle of a pipeline: C:\msh\test.msh. > At line:1 char:16 > + c:\msh\test.msh <<<< |sort-object handles |format-list processname,handle > > my question is how can i use a saved command line to a text file and use it > in the power shell script in order to organize it ? is there something im > doing wrong ? this release uses the extension .ps1. Second, to executes a script on a command line you have to use .\sciptname.ps1 So for you example it would be... ..\get-p.ps1 | sort-object handles | format-list processname, handle Hope that helps. Jim |
My System Specs![]() |
| | #5 (permalink) |
| | Re: power shell in a script hi , i used what you wrote here and here is the error i get PS C:\MSH> c:\msh\test.ps1 |sort-object handles |format-list processname,handle File C:\msh\test.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details. At line:1 char:16 + c:\msh\test.ps1 <<<< |sort-object handles |format-list processname,handle PS C:\MSH> any idea ? "Jsimpson" wrote: Quote: > On Dec 3, 9:59 am, don5 <d...@xxxxxx> wrote: Quote: > > Hi all . > > > > i write the following command : get-process |where-object {$_.handles -gt 500} > > > > and i save it to a text file named test.msh > > > > now i want to use this simple script i made and i write the following > > command : > > > > c:\msh\test.msh |sort-object handles |format-list processname,handle > > > > but i get the following error : > > > > PS C:\MSH> c:\msh\test.msh |sort-object handles |format-list > > processname,handle > > Can't execute a document in the middle of a pipeline: C:\msh\test.msh. > > At line:1 char:16 > > + c:\msh\test.msh <<<< |sort-object handles |format-list processname,handle > > > > my question is how can i use a saved command line to a text file and use it > > in the power shell script in order to organize it ? is there something im > > doing wrong ? > I think you have 2 problems in your example. First, Powershell in > this release uses the extension .ps1. Second, to executes a script on > a command line you have to use .\sciptname.ps1 > > So for you example it would be... > > ..\get-p.ps1 | sort-object handles | format-list processname, handle > > Hope that helps. > > Jim > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: power shell in a script As I said before... you need to update your monad to Powershell. Your install is pre RC install. Brandon Shell --------------- Blog: http://www.bsonposh.com/ PSH Scripts Project: www.codeplex.com/psobject d> hi , i used what you wrote here and here is the error i get d> d> PS C:\MSH> c:\msh\test.ps1 |sort-object handles |format-list d> processname,handle d> File C:\msh\test.ps1 cannot be loaded because the execution of d> scripts is d> disabled on this system. Please see "get-help d> about_signing" for more details. d> At line:1 char:16 d> + c:\msh\test.ps1 <<<< |sort-object handles |format-list d> processname,handle PS C:\MSH> d> d> any idea ? d> d> "Jsimpson" wrote: d> Quote: Quote: >> On Dec 3, 9:59 am, don5 <d...@xxxxxx> wrote: >> Quote: >>> Hi all . >>> >>> i write the following command : get-process |where-object >>> {$_.handles -gt 500} >>> >>> and i save it to a text file named test.msh >>> >>> now i want to use this simple script i made and i write the >>> following command : >>> >>> c:\msh\test.msh |sort-object handles |format-list processname,handle >>> >>> but i get the following error : >>> >>> PS C:\MSH> c:\msh\test.msh |sort-object handles |format-list >>> processname,handle >>> Can't execute a document in the middle of a pipeline: >>> C:\msh\test.msh. >>> At line:1 char:16 >>> + c:\msh\test.msh <<<< |sort-object handles |format-list >>> processname,handle >>> my question is how can i use a saved command line to a text file and >>> use it in the power shell script in order to organize it ? is there >>> something im doing wrong ? >>> >> this release uses the extension .ps1. Second, to executes a script >> on a command line you have to use .\sciptname.ps1 >> >> So for you example it would be... >> >> ..\get-p.ps1 | sort-object handles | format-list processname, handle >> >> Hope that helps. >> >> Jim >> |
My System Specs![]() |
| | #7 (permalink) |
| | Re: power shell in a script well , i looked at the version i have and its windows POWERSHELL ver 1.0 isnt that the one i should have ? "Brandon Shell [MVP]" wrote: Quote: > As I said before... you need to update your monad to Powershell. > > Your install is pre RC install. > > Brandon Shell > --------------- > Blog: http://www.bsonposh.com/ > PSH Scripts Project: www.codeplex.com/psobject > > d> hi , i used what you wrote here and here is the error i get > d> > d> PS C:\MSH> c:\msh\test.ps1 |sort-object handles |format-list > d> processname,handle > d> File C:\msh\test.ps1 cannot be loaded because the execution of > d> scripts is > d> disabled on this system. Please see "get-help > d> about_signing" for more details. > d> At line:1 char:16 > d> + c:\msh\test.ps1 <<<< |sort-object handles |format-list > d> processname,handle PS C:\MSH> > d> > d> any idea ? > d> > d> "Jsimpson" wrote: > d> Quote: Quote: > >> On Dec 3, 9:59 am, don5 <d...@xxxxxx> wrote: > >> > >>> Hi all . > >>> > >>> i write the following command : get-process |where-object > >>> {$_.handles -gt 500} > >>> > >>> and i save it to a text file named test.msh > >>> > >>> now i want to use this simple script i made and i write the > >>> following command : > >>> > >>> c:\msh\test.msh |sort-object handles |format-list processname,handle > >>> > >>> but i get the following error : > >>> > >>> PS C:\MSH> c:\msh\test.msh |sort-object handles |format-list > >>> processname,handle > >>> Can't execute a document in the middle of a pipeline: > >>> C:\msh\test.msh. > >>> At line:1 char:16 > >>> + c:\msh\test.msh <<<< |sort-object handles |format-list > >>> processname,handle > >>> my question is how can i use a saved command line to a text file and > >>> use it in the power shell script in order to organize it ? is there > >>> something im doing wrong ? > >>> > >> I think you have 2 problems in your example. First, Powershell in > >> this release uses the extension .ps1. Second, to executes a script > >> on a command line you have to use .\sciptname.ps1 > >> > >> So for you example it would be... > >> > >> ..\get-p.ps1 | sort-object handles | format-list processname, handle > >> > >> Hope that helps. > >> > >> Jim > >> > > |
My System Specs![]() |
| | #8 (permalink) |
| | Re: power shell in a script On Dec 4, 3:17 pm, don5 <d...@xxxxxx> wrote: Quote: > well , i looked at the version i have and its windows POWERSHELL ver 1.0 > isnt that the one i should have ? > > "Brandon Shell [MVP]" wrote: Quote: > > As I said before... you need to update your monad to Powershell. Quote: > > Your install is pre RC install. Quote: > > Brandon Shell > > --------------- > > Blog:http://www.bsonposh.com/ > > PSH Scripts Project: www.codeplex.com/psobject Quote: > > d> hi , i used what you wrote here and here is the error i get > > d> > > d> PS C:\MSH> c:\msh\test.ps1 |sort-object handles |format-list > > d> processname,handle > > d> File C:\msh\test.ps1 cannot be loaded because the execution of > > d> scripts is > > d> disabled on this system. Please see "get-help > > d> about_signing" for more details. > > d> At line:1 char:16 > > d> + c:\msh\test.ps1 <<<< |sort-object handles |format-list > > d> processname,handle PS C:\MSH> > > d> > > d> any idea ? > > d> > > d> "Jsimpson" wrote: > > d> Quote: > > >> On Dec 3, 9:59 am, don5 <d...@xxxxxx> wrote: Quote: Quote: > > >>> Hi all . Quote: Quote: > > >>> i write the following command : get-process |where-object > > >>> {$_.handles -gt 500} Quote: Quote: > > >>> and i save it to a text file named test.msh Quote: Quote: > > >>> now i want to use this simple script i made and i write the > > >>> following command : Quote: Quote: > > >>> c:\msh\test.msh |sort-object handles |format-list processname,handle Quote: Quote: > > >>> but i get the following error : Quote: Quote: > > >>> PS C:\MSH> c:\msh\test.msh |sort-object handles |format-list > > >>> processname,handle > > >>> Can't execute a document in the middle of a pipeline: > > >>> C:\msh\test.msh. > > >>> At line:1 char:16 > > >>> + c:\msh\test.msh <<<< |sort-object handles |format-list > > >>> processname,handle > > >>> my question is how can i use a saved command line to a text file and > > >>> use it in the power shell script in order to organize it ? is there > > >>> something im doing wrong ? Quote: Quote: > > >> I think you have 2 problems in your example. First, Powershell in > > >> this release uses the extension .ps1. Second, to executes a script > > >> on a command line you have to use .\sciptname.ps1 Quote: Quote: > > >> So for you example it would be... Quote: Quote: > > >> ..\get-p.ps1 | sort-object handles | format-list processname, handle Quote: Quote: > > >> Hope that helps. Quote: Quote: > > >> Jim If you really have PowerShell version 1, your original problem was both your method of executing a script and the extension on the script. Jsimpson's advice to change the extension to .ps1 and to run it using .\<script name>.ps1 gets you most of the way there. PowerShell's default policy for running scripts is "Restricted", which means no scripts of any kind can be executed. This is a security measure. In order to run a script, you need to set the PowerShell's execution policy; this is done with the Set-ExecutionPolicy Cmdlet. Type "Get-Help Set-ExecutionPolicy -Full" for details, but the main point is that you need to tell PowerShell what types of scripts you consider safe. RemoteSigned, in my personal opinion, is a good trade- off between convenience and safety: PSH$ Set-ExecutionPolicy RemoteSigned The RemoteSigned policy "requires that all scripts and configuration files downloaded from the Internet be signed by a trusted publisher" (from the help). This means that scripts you write for your own use can be used without signing them first. Good luck. Jeff |
My System Specs![]() |
| | #9 (permalink) |
| | Re: power shell in a script What do you get back when you run this command? (Get-Command "$PSHome\PowerShell.exe").FileVersionInfo "don5" <don5@xxxxxx> wrote in message news:71970E9E-1624-4952-98E7-004037C666A5@xxxxxx Quote: > well , i looked at the version i have and its windows POWERSHELL ver 1.0 > isnt that the one i should have ? > > "Brandon Shell [MVP]" wrote: > Quote: >> As I said before... you need to update your monad to Powershell. >> >> Your install is pre RC install. >> >> Brandon Shell >> --------------- >> Blog: http://www.bsonposh.com/ >> PSH Scripts Project: www.codeplex.com/psobject >> >> d> hi , i used what you wrote here and here is the error i get >> d> >> d> PS C:\MSH> c:\msh\test.ps1 |sort-object handles |format-list >> d> processname,handle >> d> File C:\msh\test.ps1 cannot be loaded because the execution of >> d> scripts is >> d> disabled on this system. Please see "get-help >> d> about_signing" for more details. >> d> At line:1 char:16 >> d> + c:\msh\test.ps1 <<<< |sort-object handles |format-list >> d> processname,handle PS C:\MSH> >> d> >> d> any idea ? >> d> >> d> "Jsimpson" wrote: >> d> Quote: >> >> On Dec 3, 9:59 am, don5 <d...@xxxxxx> wrote: >> >> >> >>> Hi all . >> >>> >> >>> i write the following command : get-process |where-object >> >>> {$_.handles -gt 500} >> >>> >> >>> and i save it to a text file named test.msh >> >>> >> >>> now i want to use this simple script i made and i write the >> >>> following command : >> >>> >> >>> c:\msh\test.msh |sort-object handles |format-list processname,handle >> >>> >> >>> but i get the following error : >> >>> >> >>> PS C:\MSH> c:\msh\test.msh |sort-object handles |format-list >> >>> processname,handle >> >>> Can't execute a document in the middle of a pipeline: >> >>> C:\msh\test.msh. >> >>> At line:1 char:16 >> >>> + c:\msh\test.msh <<<< |sort-object handles |format-list >> >>> processname,handle >> >>> my question is how can i use a saved command line to a text file and >> >>> use it in the power shell script in order to organize it ? is there >> >>> something im doing wrong ? >> >>> >> >> I think you have 2 problems in your example. First, Powershell in >> >> this release uses the extension .ps1. Second, to executes a script >> >> on a command line you have to use .\sciptname.ps1 >> >> >> >> So for you example it would be... >> >> >> >> ..\get-p.ps1 | sort-object handles | format-list processname, handle >> >> >> >> Hope that helps. >> >> >> >> Jim >> >> >> >> |
My System Specs![]() |
| | #10 (permalink) |
| | Re: power shell in a script the output i get from this command is : ProductVersion FileVersion FileName -------------- ----------- -------- 6.0.5430.0 6.0.5430.0 (w... C:\WINDOWS\system32\WindowsPowerShell\v1.0\PowerShell.exe and by the way , now that i run for instance .\testscript.msh (testscript.msh stands for a simple script i made - get-service |where-object {$_.displayname -eq "telnet"} a black screen occurs every 1 second with nothing in it. and it keeps on appearing. i have to press ctrl c in order for these screens to stop. i dont understand why my script is not running. its a very simple script. "Brandon Shell [MVP]" wrote: Quote: > What do you get back when you run this command? > > (Get-Command "$PSHome\PowerShell.exe").FileVersionInfo > > "don5" <don5@xxxxxx> wrote in message > news:71970E9E-1624-4952-98E7-004037C666A5@xxxxxx Quote: > > well , i looked at the version i have and its windows POWERSHELL ver 1.0 > > isnt that the one i should have ? > > > > "Brandon Shell [MVP]" wrote: > > Quote: > >> As I said before... you need to update your monad to Powershell. > >> > >> Your install is pre RC install. > >> > >> Brandon Shell > >> --------------- > >> Blog: http://www.bsonposh.com/ > >> PSH Scripts Project: www.codeplex.com/psobject > >> > >> d> hi , i used what you wrote here and here is the error i get > >> d> > >> d> PS C:\MSH> c:\msh\test.ps1 |sort-object handles |format-list > >> d> processname,handle > >> d> File C:\msh\test.ps1 cannot be loaded because the execution of > >> d> scripts is > >> d> disabled on this system. Please see "get-help > >> d> about_signing" for more details. > >> d> At line:1 char:16 > >> d> + c:\msh\test.ps1 <<<< |sort-object handles |format-list > >> d> processname,handle PS C:\MSH> > >> d> > >> d> any idea ? > >> d> > >> d> "Jsimpson" wrote: > >> d> > >> >> On Dec 3, 9:59 am, don5 <d...@xxxxxx> wrote: > >> >> > >> >>> Hi all . > >> >>> > >> >>> i write the following command : get-process |where-object > >> >>> {$_.handles -gt 500} > >> >>> > >> >>> and i save it to a text file named test.msh > >> >>> > >> >>> now i want to use this simple script i made and i write the > >> >>> following command : > >> >>> > >> >>> c:\msh\test.msh |sort-object handles |format-list processname,handle > >> >>> > >> >>> but i get the following error : > >> >>> > >> >>> PS C:\MSH> c:\msh\test.msh |sort-object handles |format-list > >> >>> processname,handle > >> >>> Can't execute a document in the middle of a pipeline: > >> >>> C:\msh\test.msh. > >> >>> At line:1 char:16 > >> >>> + c:\msh\test.msh <<<< |sort-object handles |format-list > >> >>> processname,handle > >> >>> my question is how can i use a saved command line to a text file and > >> >>> use it in the power shell script in order to organize it ? is there > >> >>> something im doing wrong ? > >> >>> > >> >> I think you have 2 problems in your example. First, Powershell in > >> >> this release uses the extension .ps1. Second, to executes a script > >> >> on a command line you have to use .\sciptname.ps1 > >> >> > >> >> So for you example it would be... > >> >> > >> >> ..\get-p.ps1 | sort-object handles | format-list processname, handle > >> >> > >> >> Hope that helps. > >> >> > >> >> Jim > >> >> > >> > >> > >> |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Power Shell? | PowerShell | |||
| How to schedule a Power Shell script | PowerShell | |||
| Executing Power Shell Scripts from Windows Shell | PowerShell | |||
| How to pass arguments to a power shell script | PowerShell | |||
| How do you run a Power Shell Script against a list of machines? | PowerShell | |||