Chapter 7. Putting MSH to Work

In this book, we’ve covered a number of MSH’s new features and explored some areas that separate it from other shells available today. Some of these changes are significant and some are subtle, but it’s clear that the command shell is different with MSH. In this final chapter, we’ll look at some applied uses of MSH, including more advanced script techniques, and wrap up with a series of small, task-focused examples.

Invoke Commands with &

If you’ve been exploring the shell, you may have noticed that MSH and cmd.exe treat filenames differently. For example, if a file is dragged from Explorer onto the command prompt window in MSH, the window still acts as though the filename were typed in, but the behavior can differ.

For example, dragging a file HelloWorld.exe from the folder D:\Apps in an Explorer window onto either a cmd.exe or MSH window will result in "D:\Apps\HelloWorld.exe" being typed at the prompt. However, Examples 7-1 and 7-2 show how the two shells differ in their interpretation of the action.

Example 7-1. Entering a fully qualified path in cmd.exe
D:\> "D:\Apps\HelloWorld.exe"
Hello, World!
Example 7-2. Entering a fully qualified path in MSH
MSH D:\MshScripts> "D:\Apps\HelloWorld.exe"
D:\Apps\HelloWorld.exe

cmd.exe is running the program, whereas MSH is happy to echo back the string that it’s just been given. This difference can be reconciled with the ampersand (&) syntax, which forces MSH to interpret a string as a command.

How Do I Do That?

MSH ...

Get Monad (AKA PowerShell) now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.