Búsqueda de sitios web

Diversión del viernes: otro mensaje navideño


Function Prompt {

#only change background color if in December
if ((Get-Date).Month -eq 12 -And (Get-Date).Day -lt 25) {
Switch ($host.ui.RawUI.BackgroundColor) {

"DarkGreen" { $c = "DarkRed" }
"DarkRed"   { $c = "DarkGreen" }
 Default    { 
            #get a random color
            $c = Get-Random -InputObject "DarkRed","DarkGreen"
            }

} #switch

$host.ui.RawUI.BackgroundColor = $c
}

"PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "

}

Incluí algo de lógica para que mi personalización solo ocurra durante el mes de diciembre y antes de Navidad. El mensaje cambia el color de fondo de su consola entre Rojo oscuro y Verde oscuro. La primera vez que lo ejecute, el mensaje seleccionará un color aleatoriamente. Es posible que desee ejecutar Clear-Host o CLS después de cargar el mensaje.

Después de eso, el color de fondo cambiará dejándote con un efecto como este:

Es interesante ver cómo se escriben diferentes comandos en la consola. Incluso podrías combinar ambas sugerencias si estás de humor especialmente festivo.

Function Prompt {

#only change background color if in December
if ((Get-Date).Month -eq 12 -And (Get-Date).Day -lt 25) {
Switch ($host.ui.RawUI.BackgroundColor) {

"DarkGreen" { $c = "DarkRed" }
"DarkRed"   { $c = "DarkGreen" }
 Default    { 
            #get a random color
            $c = Get-Random -InputObject "DarkRed","DarkGreen"
            }

} #switch

$host.ui.RawUI.BackgroundColor = $c


#get current year
    $year = (Get-Date).year
    #get a timespan between Christmas for this year and now

    $time=[datetime]"25 December $year" - (Get-Date)
    #turn the timespan into a string and strip off the milliseconds
    $timestring = $time.ToString().Substring(0,11)

    #get random string of decorative characters
    $front = -join (14,15,42 | Get-Random -Count 2 | Foreach { $_ -as [char] })
    $back = -join (14,15,42 | Get-Random -Count 2 | Foreach { $_ -as [char] })
    $text="[{0}Christmas in {1}{2}]" -f $front,$timestring,$back

    #get each character in the text and randomly assign each a color
    $text.tocharArray() | foreach {

    $i = get-random -Minimum 1 -Maximum 20
    switch ($i) {
      {$i -le 20 -and $i -gt 15} { $color = "Red"}
      {$i -le 16 -and $i -gt 10} { $color = "Green" }
      {$i -le 10 -and $i -gt 5}{ $color = "DarkGreen"}
      default {$color = "White"}
    }

    #write each colorized character
    write-host $_ -nonewline -foregroundcolor $color
    } #foreach

} #if Christmas time

"PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "

} #end prompt function

Probablemente no haya ningún valor práctico en esto aparte de divertirse y tal vez comprender algunos conceptos de secuencias de comandos de PowerShell. Espero que tus compras navideñas vayan bien. Ten un excelente fin de semana.

Artículos relacionados