Greetings of the Day

by Jun 29, 2017

Here is a simple approach that takes an array of strings and returns a random string that you could use for custom greetings in PowerShell:

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

$greetings | Get-Random

All you need to do is add the code to your profile script, for example like this:

# 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!'

$greetings | Get-Random
'@ | Add-Content -Path $Profile.CurrentUserAllHosts -Encoding Default

Once done, PowerShell will greet you with a custom message.

Twitter This Tip! ReTweet this Tip!