Skip to content

Instantly share code, notes, and snippets.

@Tcip
Created December 11, 2024 01:59
Show Gist options
  • Save Tcip/9287b5d639b62d4954df4e7ee043f7fc to your computer and use it in GitHub Desktop.
Save Tcip/9287b5d639b62d4954df4e7ee043f7fc to your computer and use it in GitHub Desktop.
Here document in PowerShell
$doc, $marty = 'Dr. Emmett Brown', 'Marty McFly'
$time = [DateTime]'Friday, October 25, 1985 8:00:00 AM'
$diff = New-TimeSpan -Minutes 25
@"
$doc : Are those my clocks I hear?
$marty : Yeah! Uh, it's $($time.Hour) o'clock!
$doc : Perfect! My experiment worked! They're all exactly $($diff.Minutes) minutes slow.
$marty : Wait a minute. Wait a minute. Doc... Are you telling me that it's $(($time + $diff).ToShortTimeString())?
$doc : Precisely.
$marty : Damn! I'm late for school!
"@
@Tcip
Copy link
Author

Tcip commented Dec 11, 2024

Output

Dr. Emmett Brown : Are those my clocks I hear?
Marty McFly : Yeah! Uh, it's 8 o'clock!
Dr. Emmett Brown : Perfect! My experiment worked! They're all exactly 25 minutes slow.
Marty McFly : Wait a minute. Wait a minute. Doc... Are you telling me that it's 08:25?
Dr. Emmett Brown : Precisely.
Marty McFly : Damn! I'm late for school!

How to execute the PowerShell script

CMD
powershell .'Marty McFly (here-strings).ps1'

PowerShell
.'Marty McFly (here-strings).ps1'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment