PowerShell's Write-Host is similar to the WScript.Echo command. But as
usual PowerShell's commands are just that bit easier to understand and
achieve a little bit more than VBScript.
In the case of Windows 7 and Server
2008, you don't need to download any extra files, just 'Add Feature' Windows PowerShell.
However, for older operating systems, installing can be confusing because
there are different versions of PowerShell for XP, Windows Server 2003 and
Vista. For such legacy systems only, you need to
download PowerShell from Microsoft's site.
Once you have installed PowerShell 2.0, I recommend choosing the
ISE (Integrated Scripting Engine) version, it
will save you buying a text editor.
Note 1: Observe how there is no extra punctuation between "The Literal "
(MacAddress :)
and the $variable ($objItem.MACAddress). For that reason I left a space just before the
closing speech mark.
Challenge: Just to test your own understanding,
experiment with changing "MACAddress : " to Plain "MAC ".
Guy
Recommends: WMI Monitor and It's Free!
Windows Management Instrumentation (WMI) is one of the hidden
treasures of Microsoft operating systems. Fortunately, Solarwinds
have created a
Free WMI Monitor so that you can discover these gems of performance
information, and thus improve your PowerShell scripts. Take the guess work out of which WMI counters to use when scripting the
operating system, Active Directory or Exchange Server.
Plain Write-Host really is straight-forward to use.
One of the few tricky scenarios is when you try to be flashy and combine
literals and $variables through the use of quotes.
# PowerShell Write Host Single Quotes $Now =
Get-Date Write-Host 'Today is $Now -enjoy! '
Note 2: Write-Host interprets a single quote as a literal,
sadly it ignores $Now and the underlying Get-Date.
Note 3: This result is probably what the designer of the
above script
intended. If you run this example then you see today's date surrounded
seamlessly by a
few words.
Challenge: For UK readers try swapping this code:
Get-Date -Uformat "%A %d-%m-%Y"
# Extra parameters for PowerShell's Write-Host Clear-host Get-Help
Write-Host -full
Two parameters, which most script writers use sooner or later are
-BackGroundColor and -ForeGroundColor.
PowerShell Color Parameters
Take care with Write-Host ForeGroundColor and BackGroundColor as you can produce some truly hideous
combinations thus!
# PowerShell Color Parameters $Date = Get-Date
Write-Host $Date -ForeGroundColor green -b magenta Write-Host $Date
-fore yellow -back green Write-Host $Date -f red -BackGroundColor
darkblue
Apart from black and white, other Write-Host colors include, gray,
blue, red and yellow.
Guy Recommends: A Free Trial of the Network Performance Monitor
(NPM)
Solarwinds'
Orion performance monitor
will help you discover what's happening on your network. This
utility will also guide you through troubleshooting; the dashboard will
indicate whether the root cause is a broken link, faulty equipment or
resource overload.
Perhaps the NPM's best feature is the way it suggests solutions to network
problems. Its
second best feature is the ability to monitor the health of individual VMWare
virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you take advantage of Solarwinds' offer.
# PowerShell CSV Cmdlet Research Clear-Host Get-Command
-noun Host
Out-Host looks interesting, there again researching PowerShell cmdlets
with -noun or -verb always throws up at least one surprise.
Summary of PowerShell Write-Host
With PowerShell's Write-Host what you see is what you get on screen.
It's an easy cmdlet to understand, especially if you are familiar echo
commands from other scripting languages.
My advice is keep experimenting with Write-Host until you find the particular
output your task requires.
If you like this page then please share it with your friends
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.
Windows Management Instrumentation (WMI) is one of the hidden
treasures of Microsoft operating systems.
Fortunately, Solarwinds
have created the
Free WMI Monitor so that you can actually see and understand these gems of
performance information. Take the guess work out of which
WMI counters to use for applications like Microsoft Active Directory,
SQL or Exchange Server.