![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 Specs![]() |
| | #2 (permalink) |
| 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 Specs![]() |
| | #3 (permalink) |
| 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 ofit 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 Specs![]() |
| | #4 (permalink) |
| 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 Specs![]() |
| | #5 (permalink) |
| 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 Specs![]() |
![]() |
| 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 |