Windows PowerShell Read-Host (Input Box)
When you need user input, then employ Read-Host with associated variables. This is PowerShell’s equivalent of MsgBox() in VBScript.
Windows PowerShell Read-Host Topics
♣
PowerShell Script To Generate an Input Box
# PowerShell Read-Host Input Box
Clear-Host
$YearCalc = Read-Host "When were you born?"
$Now = (Get-Date -uformat "%Y") -$YearCalc
$Maybe = $Now -1
Write-Host "You are $Maybe or $Now years old "
Note 1: $YearCalc is the variable that holds the value you enter into the input box.
Note 2: I am sure that you can do better with the math and with the logic.
Guy Recommends: Free WMI Monitor for PowerShell
Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft’s 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. Give this WMI monitor a try – it’s free.
Download your free copy of WMI Monitor
Further Research on Read-Host
PowerShell’s Read-Host Parameters
# PowerShell Read-Host Parameters
Clear-Host
Get-Help Read-Host -full
If you want a more secure input box, try -AsSecureString this will displays asterisks (****) in place of the characters that the user types in the box. You could also experiment with -prompt.
Creating a Pop-up Message
Here is a technique where PowerShell creates a ComObject, which in turn, has a method to produce a pop-up message.
$WshShell = New-Object -ComObject wscript.shell
$Time = Get-Date -UFormat %R
$Message ="Test for $Env:computername at: " + $Time
$PopUp = $WshShell.popup("$Message",0,"Task Scheduler Pop-up",1)
Guy Recommends: SolarWinds Free Network Bandwidth Monitor
This freeware monitor is great for checking whether your network’s load-balancing is performing as expected, for example, are two interfaces are getting about equal traffic?
It’s easy to install and straightforward to configure. You will soon be running tests to see how much network bandwidth your applications consume.
The GUI has a lovely balance between immediate network traffic data in the middle, combined with buttons to seek related data and configuration settings. Give this monitor a try, it’s free!
Download your free network bandwidth monitor
If you need more comprehensive network analysis software:
Download a free trial of NPM (Network Performance Monitor)
Here is PowerShell Script to Check for a Process
The concept is to produce a message box if a named process (iExplore) is actually running as reported in Task Manager.
# PowerShell script to test if a program is running.
Clear-Host
$i =1
$Victim = "iExplore"
# PowerShell function to produce the payload function
function Output-MsgBox
{
$WshShell = New-Object -ComObject wscript.shell
$Message ="$Victim is running "
$PopUp = $WshShell.popup("$Message",0,"Your Alert ",1)
}
# Test if a list of processes contains a particular item
For (1..1000) {
$Alerty = Get-Process
if($Alerty.ProcessName -Contains $Victim) {
Output-MsgBox; Start-Sleep 100}
Else {Write-Host "No $Victim $i";Start-Sleep 10} $i++
}
Note 3: I recommend you change this line in your script:
$Victim = "iExplore"
Note 4: This script is ripe for modifying, particularly in finessing the ‘If.. else’ logic.
Researching Similar PowerShell Cmdlets
# PowerShell Item Cmdlet Research
Clear-Host
Get-Command -Noun Host
You may already know about Write-Host and Clear-Host (cls), but there is also Out-Host. PowerShell -Noun or -verb research always throws up at least one surprise.
Summary of PowerShell Read Host
When you need user input, then employ Read-Host with associated variables. This is PowerShell’s equivalent of MsgBox() in VBScript.
If you like this page then please share it with your friends
See more Microsoft PowerShell output tutorials:
• PShell Home • Out-File • Out-GridView • ConvertTo-Csv • ConvertTo-Html • ConvertFrom-Csv
• Tee-Object • Import-CSV • Format-Table • PowerShell Here-String • ConvertFrom-JSON
• Export-CliXml • Format-List • Read-Host • PowerShell Get-History • -f format • Pipe to file
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.