Collections:
Other Resources:
Console Input and Output in Windows PowerShell Scripts
How to manage console input and output in Windows PowerShell scripts? I want to write a PowerShell script that "talks" with the user.
✍: FYIcenter.com
You need to use the "Write-Host" and "Read-Host" cmdlets to manage console input and output.
The "Write-Host" cmdlet allows to write information to the console with some formatting controls.
The "Read-Host" cmdlet allows to read a single line from the console.
Here is a sample script on how to use "Write-Host" and "Read-Host" cmdlets to manage console input and output:
<# My-Game.ps1 - The random number game
#>
$n = Get-Random -Minimum 1 -Maximum 10
Write-Host "I have a number between 1 and 10."
Write-Host "Please take a guess:"
$a = Read-Host
While ($a -ne $n) {
Write-Host "Wrong answer. Try again:"
$a = Read-Host
}
"Congratulation, you won!"
Try it. You will love this game:-)
⇒ Execution Loops in Windows PowerShell Scripts
⇐ Out-Host - Standard Output in Windows PowerShell Scripts
2016-10-30, ∼2683🔥, 0💬
Popular Posts:
How to uninstall OpenOffice.org 2.2? If you want to uninstall OpenOffice.org 2.2, you should follow ...
What is the scheduled task "\G2MUploadTask-S-1-5-21 -..."on my Windows 7 computer? "\G2MUploadTask-S...
I am unable to copy data from my external hard-disk (NTFS). When I try to repair it from cmd using c...
product key for adding features to windows 8 The product key you require is MBFBV-W3DP2-2MVKN-PJCQD- ...
How do I install simplified and traditional Chinese language packs on my Windows XP system? Installi...