Subscribe to Windows IT Pro
March 27, 2009 12:00 AM

Q. How can I launch a Windows PowerShell instance to run a command from a cmd.exe prompt?

Windows IT Pro
InstantDoc ID #101752
Rating: (0)

A. To start a PowerShell session, you just need to run the "start powershell" command. However, you can also pass a command through the -Command switch. If you don't want the PowerShell instance to close once the command has run, you can also pass the -NoExit switch. For example, you may want to start a number of PowerShell instances to monitor counters on two different servers. The commands below fire up four PowerShell environments, each monitoring different counters on different servers. Run the following four commands from a cmd.exe instance.

start powershell -NoExit -Command "&{ Get-Counter
 '\\savdalvs01\Cluster Shared Volumes(\ClusterStorage
\Volume1)\IO Writes' -Continuous }"

start powershell -NoExit -Command "&{ Get-Counter
 '\\savdalvs01\Cluster Shared Volumes(\ClusterStorage
\Volume1)\Redirected IO Writes' -Continuous }"

start powershell -NoExit -Command "&{ Get-Counter 
'\\savdalvs02\Cluster Shared Volumes(\ClusterStorage
\Volume1)\IO Writes' -Continuous }"

start powershell -NoExit -Command "&{ Get-Counter
'\\savdalvs02\Cluster Shared Volumes(\ClusterStorage
\Volume1)\Redirected IO Writes' -Continuous }"
Related Reading:
Check out hundreds more useful Q&As like this in John Savill's FAQ for Windows. Also, watch instructional videos made by John at ITTV.net.

Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.