Additional Topics
If you will be editing or creating Scripts you should find a better editor than Notepad, something with Syntax Highlighting will make it much easier to code and spot errors. Some suggestions:
powershell_ise.exe
or just ise
from within PowerShell, or look in the Start Menu for "Windows PowerShell ISE"If you run across a VBScript (.VBS file) you can run it with either WSCRIPT.EXE
or CSCRIPT.EXE
. Wscript
is the Windows Scripting Host, and won't open a console, but any output is done via pop-up message boxes. Cscript
is the Console Scripting Host - so while a Console opens the output is all at console. Example:
cscript.exe //nologo c:\path\and\NameOfScript.VBS
When pasting single or multiple commands from the Web or an MS Word Doc to a Console/Shell (or into a script file) keep in mind that may blogs will mangle the commands. PowerShell.exe and CMD.exe aren't very forgiving at times. So extra spaces need to be removed, or added. Funny characters may need to be trimmed, and those curly "smart quotes" may need to changed to regular "double" or 'single' quotes. Sometimes dashes need to be changed from longer Em- and En-dashes to regular hyphens/dashes, a > redirection sign will display as the HTML ">" entity, or the \ may be missing or swapped for a /. If something still doesn't work: check to see if spaces were added/removed (like Get -Content -Path someFile.txt) or removed (like Get-Content-Path someFile.txt).
As you begin to explore the CLI and discover useful commands or techniques it's often helpful to start a text file to keep CLI notes and example commands in. If you use one of the
above Editors you can save your "notes" file with a .PS1 extension so the syntax highlighting kicks in. Use lines beginning with #
for your comments.
And make the very first line exit
so nothing will happen if you try to run it by mistake.
Other Useful Links - there's no point listing every PowerShell related site (this isn't Yahoo circa 1999!) but if you want some decent generic PowerShell info: