PowerShell – Fun With Loading $Profile

If you run $profile, you will get a path returned similar to the following:

If you have a .ps1 with the file name, you can pre-load or execute scripts upon launching PowerShell.

For example, check out the following. PowerShell can greet you based on the time of day:

Add-Type -AssemblyName System.Speech
$name = [Environment]::UserName
$theTime = (Get-Date).Hour

if ($theTime -le 12)
       [string]$theGreeting = "Good morning "
if (($theTime -ge 12) -and ($theTime -le 18))
     [string] $theGreeting = "Good afternoon "
if (($theTime -ge 19) -and ($theTime -le 24))
      [string]$theGreeting = "Good evening "

$theVoice = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer 
$theVoice.Speak("$theGreeting $name")


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s