Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

chain commands

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 08-01-2007   #1 (permalink)
GodOfLions
Guest


 

chain commands

Is there a way to "chain" commands in powershell?

For example:

Clear-host <then> Write-host some text <then> $Variable = "text" <then>
Write-host $Variable

This is just a simple example. The reason I ask is that I would like to be
able to pass three commands to be run one after the other to a powershell
command, without having to write a script all the time.

A more complex example would be:

powershell Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
<then> new-mailcontact -Identity forward-SomeUser -ExternalEmailAddress
joe@joe.com <then> set-mailbox -Identity SomeUser -forwardingaddress
forward-SomeUser

Right now I have to write a PS script that gets passed the two variables,
and then run the script. I'd like to be able to just run the powershell
command straight up with the commands all on one line.

Using the Pipes does not work, as I've tried that one already. I remember in
CMD you could use the & to "chain" commands together.

Any help on this would be greatly appreciated.

My System SpecsSystem Spec
Old 08-01-2007   #2 (permalink)
dreeschkind
Guest


 

RE: chain commands

Clear-host; Write-host some text; $Variable = "text"; Write-host $Variable

--
greetings
dreeschkind

"GodOfLions" wrote:

> Is there a way to "chain" commands in powershell?
>
> For example:
>
> Clear-host <then> Write-host some text <then> $Variable = "text" <then>
> Write-host $Variable
>
> This is just a simple example. The reason I ask is that I would like to be
> able to pass three commands to be run one after the other to a powershell
> command, without having to write a script all the time.
>
> A more complex example would be:
>
> powershell Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
> <then> new-mailcontact -Identity forward-SomeUser -ExternalEmailAddress
> joe@joe.com <then> set-mailbox -Identity SomeUser -forwardingaddress
> forward-SomeUser
>
> Right now I have to write a PS script that gets passed the two variables,
> and then run the script. I'd like to be able to just run the powershell
> command straight up with the commands all on one line.
>
> Using the Pipes does not work, as I've tried that one already. I remember in
> CMD you could use the & to "chain" commands together.
>
> Any help on this would be greatly appreciated.

My System SpecsSystem Spec
Old 08-01-2007   #3 (permalink)
GodOfLions
Guest


 

RE: chain commands

That works, thank you a lot for that helps me out with some bothersome issues.

Where is the semi-colon ( feature documented? I couldn't find mention of
it when I looked around.

"dreeschkind" wrote:

> Clear-host; Write-host some text; $Variable = "text"; Write-host $Variable
>
> --
> greetings
> dreeschkind
>
> "GodOfLions" wrote:
>
> > Is there a way to "chain" commands in powershell?
> >
> > For example:
> >
> > Clear-host <then> Write-host some text <then> $Variable = "text" <then>
> > Write-host $Variable
> >
> > This is just a simple example. The reason I ask is that I would like to be
> > able to pass three commands to be run one after the other to a powershell
> > command, without having to write a script all the time.
> >
> > A more complex example would be:
> >
> > powershell Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
> > <then> new-mailcontact -Identity forward-SomeUser -ExternalEmailAddress
> > joe@joe.com <then> set-mailbox -Identity SomeUser -forwardingaddress
> > forward-SomeUser
> >
> > Right now I have to write a PS script that gets passed the two variables,
> > and then run the script. I'd like to be able to just run the powershell
> > command straight up with the commands all on one line.
> >
> > Using the Pipes does not work, as I've tried that one already. I remember in
> > CMD you could use the & to "chain" commands together.
> >
> > Any help on this would be greatly appreciated.

My System SpecsSystem Spec
Old 08-01-2007   #4 (permalink)
Kiron
Guest


 

Re: chain commands

I've only seen PowerShell's statement separator ';' mentioned once in the
Help contents. It's in the second example of Get-ExecutionPolicy help's
content:

(((get-help Get-ExecutionPolicy).examples).example)[1]

You can read a bit more about it here:
http://blogs.msdn.com/powershell/arc...injection.aspx

--
Kiron

My System SpecsSystem Spec
Old 08-01-2007   #5 (permalink)
dreeschkind
Guest


 

RE: chain commands

"GodOfLions" wrote:

> Where is the semi-colon ( feature documented? I couldn't find mention of
> it when I looked around.


Unfortunately, it seems that this is missing in the help.
However, many programming/scripting languages (Pascal, C, C++, Java,
JavaScript, C# etc.) use the semi-colon as command delimiter/end-of-line
character. There are many things that are borrowed from other languages, but
also some unique syntax elements. All the details of the PowerShell language
(and much more) is covered in Bruce Payette's book "PowerShell in Action". He
is the key designer of the PowerShell language.

--
greetings
dreeschkind
My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
A chain of problems...starting with check disk. JT12 Vista performance & maintenance 1 07-17-2008 03:09 PM
What is the chain link picture in the left collum? dan53gsd General Discussion 2 05-12-2008 12:56 PM
filter chain emails guitardude Live Mail 6 04-16-2008 04:46 PM
Chain of upgrades Cynthia J. Vista installation & setup 9 01-28-2007 07:28 PM
How can I alter the dependency property inheritance chain? Pascal Bourque Avalon 4 05-01-2006 10:08 AM


Update your Vista Drivers Update Your Vista Drivers Now!!

Vistax64.com 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 2005-2008
Page generated in 0.30137 seconds with 10 queries