The PowerShell notebook provides a rich interactive experience through its host. The following are some examples.
Blue
, and you can see the output is rendered in blue afterwards:$host.UI.RawUI.ForegroundColor = [System.ConsoleColor]::Blue
$PSVersionTable
Write-Host "Something to think about ..." -ForegroundColor Blue -BackgroundColor Gray
Write-Warning "Warning"
Write-Verbose "Verbose" -Verbose
Write-Debug "Debug" -Debug
Write-Host -NoNewline
as expected:Write-Host "Hello " -NoNewline -ForegroundColor Red
Write-Host "World!" -ForegroundColor Blue
$cred = Get-Credential
"$($cred.UserName), password received!"
Write-Verbose "Ask for name" -Verbose
$name = Read-Host -Prompt "What's your name? "
Write-Host "Greetings, $name!" -ForegroundColor DarkBlue
Read-Host -Prompt "token? " -AsSecureString
Get-Command nonExist -ErrorAction Inquire
Write-Output | ForEach-Object { "I received '$_'" }
Get-Process | select -First 5 | % { start-sleep -Milliseconds 300; $_ }
## Demo the progress bar
For ($i=0; $i -le 100; $i++) {
Write-Progress -Id 1 -Activity "Parent work progress" -Status "Current Count: $i" -PercentComplete $i -CurrentOperation "Counting ..."
For ($j=0; $j -le 10; $j++) {
Start-Sleep -Milliseconds 5
Write-Progress -Parent 1 -Id 2 -Activity "Child work progress" -Status "Current Count: $j" -PercentComplete ($j*10) -CurrentOperation "Working ..."
}
if ($i -eq 50) {
Write-Verbose "working hard!!!" -Verbose
"Something to output"
}
}