Greetings of the Day (with Voice)

by Jun 30, 2017

In the previous tip we explained how you can add a personal greeting to your PowerShell profile. This greeting can also be spoken out, provided your volume is turned up. This works for all Powershell hosts including VSCode.

This will add the code to your profile script:

# create profile if it does not yet exist
$exists = Test-Path -Path $Profile.CurrentUserAllHosts
if (!$exists) 
{ 
  $null = New-Item -Path $Profile.CurrentUserAllHosts -ItemType File -Force 
}

# add code to profile
@'
$greetings = 
'Hello there!',
'Glad to see you!',
'Happy coding!',
'Have a great day!',
'May the PowerShell be with you!'

$text = $greetings | Get-Random
$null = (New-Object -COM Sapi.SpVoice).Speak($text)
'@ | Add-Content -Path $Profile.CurrentUserAllHosts -Encoding Default

To edit the profile, run this:

 
PS> notepad $profile.CurrentUserAllHosts
 

Twitter This Tip! ReTweet this Tip!