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 - power shell in a script

Reply
 
Old 12-03-2007   #1 (permalink)
don5


 
 

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 SpecsSystem Spec
Old 12-03-2007   #2 (permalink)
Brandon Shell [MVP]


 
 

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 SpecsSystem Spec
Old 12-03-2007   #3 (permalink)
Marco Shaw [MVP]


 
 

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 ?
>
>
Well, I tried this with PowerShell v1 (v2 CTP actually), and it worked
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 SpecsSystem Spec
Old 12-03-2007   #4 (permalink)
Jsimpson


 
 

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 ?
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 SpecsSystem Spec
Old 12-03-2007   #5 (permalink)
don5


 
 

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 SpecsSystem Spec
Old 12-03-2007   #6 (permalink)
Brandon Shell [MVP]


 
 

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 ?
>>>
>> 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 SpecsSystem Spec
Old 12-04-2007   #7 (permalink)
don5


 
 

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 SpecsSystem Spec
Old 12-04-2007   #8 (permalink)
Jeff


 
 

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
don5,

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 SpecsSystem Spec
Old 12-04-2007   #9 (permalink)
Brandon Shell [MVP]


 
 

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 SpecsSystem Spec
Old 12-04-2007   #10 (permalink)
don5


 
 

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 SpecsSystem Spec
Reply

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


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