[玩转系统] 周五乐趣:给你的圣诞礼物
作者:精品下载站 日期:2024-12-14 07:40:50 浏览:13 分类:玩电脑
周五乐趣:给你的圣诞礼物
多年来,PowerShell 社区中的许多人分享了圣诞节和节日相关的内容。我收集了它们,并对某些情况进行了一些调整。今年,我决定将它们全部封装在一个模块中供您使用。这适用于 PowerShell 2.0 及更高版本。
#requires -version 2.0
<#
Christmas.psm1
A PowerShell module with a collection of holiday themed functions.
****************************************************************
* DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED *
* THOROUGHLY IN A LAB ENVIRONMENT. USE AT YOUR OWN RISK. IF *
* YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, *
* DO NOT USE IT OUTSIDE OF A SECURE, TEST SETTING. *
****************************************************************
#>
Function Start-Jingle {
Param ([switch]$FullSong)
#The first number is the reciprocal of the duration and the rest is the
#note and octave (which we use for getting the frequency).
#For example, 4A4 is a quarter A note
if ($fullSong) {
$notes = write `
4A4 4A4 2A4 4A4 4A4 2A4 4A4 4C4 4F3 8G3 1A4 `
4Bb4 4Bb4 4Bb4 8Bb4 4Bb4 4A4 4A4 8A4 8A4 4A4 4G3 4G3 4A4 2G3 2C4 `
4A4 4A4 2A4 4A4 4A4 2A4 4A4 4C4 4F3 4G3 1A4 4Bb4 4Bb4 4Bb4 4Bb4 `
4Bb4 4A4 4A4 8A4 8A4 4C4 4C4 4Bb4 4G3 1F3 4C3 4A4 4G3 4F3 2C3 8C3 8C3 `
4C3 4A4 4G3 4F3 1D3 4D3 4Bb4 4A4 4G3 '1E3' 4C4 4C4 4Bb4 4G3 `
1A4 4C3 4A4 4G3 4F3 1C3 4C3 4A4 4G3 4F3 1D3 `
4D3 4Bb3 4A4 4G3 4C4 4C4 4C4 8C4 8C4 4D4 4C4 4Bb4 4G3 4F3 2C4 4A4 4A4 2A4 `
4A4 4A4 2A4 4A4 4C4 4C3 8G3 1A4 4Bb4 4Bb4 4Bb4 8Bb4 4Bb4 4A4 4A4 8A4 8A4 `
4A4 4G3 4G3 4A4 2G3 2C4 4A4 4A4 2A4 4A4 4A4 2A4 4A4 4C4 4F3 8G3 `
1A4 4Bb4 4Bb4 4Bb4 4Bb4 4Bb4 4A4 4A4 8A4 8A4 4C4 4C4 4Bb4 4G3 1F3
} else {
#first verse only
$notes = write 4A4 4A4 2A4 4A4 4A4 2A4 4A4 4C4 4F3 8G3 1A4 `
4Bb4 4Bb4 4Bb4 8Bb4 4Bb4 4A4 4A4 8A4 8A4 4A4 4G3 4G3 4A4 2G3 2C4 `
4A4 4A4 2A4 4A4 4A4 2A4 4A4 4C4 4F3 4G3 1A4 4Bb4 4Bb4 4Bb4 4Bb4 `
4Bb4 4A4 4A4 8A4 8A4 4C4 4C4 4Bb4 4G3 1F3
}
function Play([int] $freq, [int] $duration)
{
[console]::Beep($freq, $duration);
}
#
# Note is given by fn=f0 * (a)^n
# a is the twelth root of 2
# n is the number of half steps from f0, positive or negative.
# f0 used here is A4 at 440 Hz
#
$f0 = 440;
$a = [math]::pow(2,(1/12)); # Twelth root of 2
function GetNoteFreq([string]$note)
{
# n is the number of half steps from the fixed note.
$note -match '([A-G#]{1,2})(\d+)' | out-null
$octave = ([int] $matches[2]) - 4;
$n = $octave * 12 + ( GetHalfStepsFromA $matches[1] );
$freq = $f0 * [math]::Pow($a, $n);
return $freq;
}
function GetHalfStepsFromA([string] $note)
{
switch($note)
{
'A' { 0 }
'A#' { 1 }
'Bb' { 1 }
'B' { 2 }
'C' { 3 }
'C#' { 4 }
'Db' { 4 }
'D' { 5 }
'D#' { 6 }
'Eb' { 6 }
'E' { 7 }
'F' { 8 }
'F#' { 9 }
'Gb' { 9 }
'G' { 10 }
'G#' { 11 }
'Ab' { 11 }
}
}
$StandardDuration = 1000;
foreach($note in $notes)
{
$note -match '(\d)(.+)' | out-null
$duration = $StandardDuration / ([int] $matches[1]);
$playNote = $matches[2];
$freq = GetNoteFreq $playNote;
#write-host $playNote $freq $duration;
Play $freq $duration
start-sleep -milli 50
}
} #end Start-Jingle
Function New-Tree {
Param([string]$Caption="Happy Holidays from PowerShell")
cls
write-host "`n"
$Peek = " ^ "
$tree = "/|\"
$i = 20
$pos = $host.ui.rawui.CursorPosition
write-host -fore 'Red' ($peek.PadLeft($i -1).PadRight(36) * 2)
write-host -fore 'green' ($tree.PadLeft($i -1).PadRight(36) * 2)
1..16 |% {
$tree = $tree -replace "/(.*)\",'//$1\'
write-host -fore 'green' ($tree.PadLeft($i).PadRight(36) * 2)
$i++
}
write-host -fore 'green' ("|||".PadLeft(19).PadRight(36) *2 )
write-host -fore 'green' ("|||".PadLeft(19).PadRight(36) *2)
$rect = New-Object System.Management.Automation.Host.Rectangle
$rect.top = $pos.y
$rect.Right = 70
$rect.Bottom = $pos.y + 19
$buffer = $host.ui.rawui.getbuffercontents($rect)
$R = New-Object system.random
$ball = New-Object System.Management.Automation.Host.BufferCell
$ball.Character = '@'
$ball.backgroundColor = $host.ui.rawui.BackgroundColor
1..120 |% {
sleep -m 120
$rx = $r.Next(19)
$ry = $r.Next(70)
$ball.ForegroundColor = $r.next(16)
if ($buffer[$rx,$ry].Character -eq '/') {$buffer[$rx,$ry] = $ball}
if ($buffer[$rx,$ry].Character -eq '\') {$buffer[$rx,$ry] = $ball}
$host.ui.rawui.SetBufferContents($pos,$buffer)
}
Write-Host "`n$([char]14) **$Caption** $([char]14) `n" -ForegroundColor Red
} #end New-Tree
Function Get-Greeting {
cls
$XmasMsg =
@"
.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:.
. * .
. /.\ Merry Christmas .
. /..'\ from all of us .
. /'.'\ in PowerShell .
. /.''.'\ .
. /.'.'.\ .
. /'.''.'.\ .
. ^^^[_]^^^ .
. .
. .
. .
.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:.
"@
Write-Host -ForegroundColor Green $XmasMsg
Start-Sleep 5
$Msg1 =
@"
_...
o_.-"` `\
.--. _ `'-._.-'""-; _
.' \`_\_ {_.-a"a-} _ / \
_/ .-' '. {c-._o_.){\|` |
(@`-._ / \{ ^ } \ _/
`~\ '-._ /'. } \} .-.
|>:< '-.__/ '._,} \_/ / ())
| >:< `'---. ____'-.|(`"`
\ >:< \_\_\ | ;
\ \-{}-\/ \
\ '._\' /)
'. /(
`-._ _____ _ _____ __.'\ \
/ \ / \ / \ \ \
_.'/^\'._.'/^\'._.'/^\'.__) \
,==' `---` '---' '---' )
`"""""""""""""""""""""""""""""""`
"@
$msg2 =
@"
___
/` `'.
/ _..---;
| /__..._/ .--.-.
|.' e e | ___\_|/____
(_)'--.o.--| | | |
.-( `-' = `-|____| |____|
/ ( |____ ____|
| ( |_ | | __|
| '-.--';/'/__ | | ( `|
| '. \ )"";--`\ /
\ ; |--' `;.-'
|`-.__ ..-'--'`;..--'`
"@
$msg3 =
@"
* ,
_/^\_
< >
* /.-.\ *
* `/&\` *
,@.*;@,
/_o.I %_\ *
* (`'--:o(_@;
/`;--.,__ `') *
;@`o % O,*`'`&\
* (`'--)_@ ;o %'()\ *
/`;--._`''--._O'@;
/&*,()~o`;-.,_ `""`)
* /`,@ ;+& () o*`;-';\
(`""--.,_0 +% @' &()\
/-.,_ ``''--....-'`) *
* /@%;o`:;'--,.__ __.'\
;*,&(); @ % &^;~`"`o;@(); *
/(); o^~; & ().o@*&`;&%O\
`"="==""==,,,.,="=="==="`
__.----.(\-''#####---...___...-----._
'` \)_`"""""`
.--' ')
o( )_-\
`"""` `
"@
$msg4 =
@"
.--------.
* . |________| . *
| __|/\
* .-'======\_\o/.
/___________<>__\
|||||| / (o) (o) \
|||||| | _ O _ | .
. |||||| | (_) (_) |
|||||| \ '---' / *
\====/ [~~~~~~~~~]
\// _/~||~`|~~~~~\_
_||-'`/ || | \`'-._ *
* .-` )| ; || |) ; '.
/ `--.| || | | `\
| \ |||||) |-, \ .
\ .; _ ; |_, |
`'''||` ,\ (_) /, `.__/
||.` '. .' `. *
* || ` ' ' ` \
|| ;
. * || | .
|| | *
|| |
.__.-""-.__.-"""|| ;.-"""-.__.-""-.__.
|| /
||'. .'
|| '-._ _ _ _ _.-'
`""`
"@
$msg5 =
@"
_
.-(_)
/ _/
.-' \
/ '.
,-~--~-~-~-~-,
{__.._...__..._} ,888,
,888, /\##" 6 6 "##/\ ,88' `88,
,88' '88,__ |(\` (__) `/)| __,88' `88
,88' .8(_ \_____\_ '----' _/_____/ _)8. 8'
88 (___)\ \ '-.__ __.-' / /(___)
88 (___)88 | '--' | 88(___)
8' (__)88,___/ \___,88(__)
__`88,_/__________________\_,88`__
/ `88, |88| ,88' \
/ `88, |88| ,88' \
/____________`88,_/_,88`____________\
/88888888888888888;8888;88888888888888888\
/^^^^^^^^^^^^^^^^^^`/88\^^^^^^^^^^^^^^^^^^\
/ |88| \============, \
/_ __ __ __ _ __ |88|_|^ MERRY | _ ___\
|;:. |88| | CHRISTMAS! | |
|;;:. |88| '============' |
|;;:. |88| |
|::. |88| |
|;;:' |88| |
|:;, |88| |
'---------------------""""---------------------'
"@
For($i = 1; $i -le 5; $i++) {
If([bool]!($i%2)) {
Write-Host -ForegroundColor Green (Get-Content Variable:msg$i)
} else {
Write-Host -ForegroundColor Red (Get-Content Variable:msg$i)
}
Start-Sleep -Seconds 3
} #for
} #end Get-Greeting
Function Get-Holiday {
#get start-jingle script block
$sb = (dir function:start-jingle).scriptblock
start-job -ScriptBlock $sb -Name JingleJob | out-null
start-sleep -Seconds 2
New-Tree
Wait-Job -Name JingleJob | Remove-Job
} #end Get-Holiday
Function Prompt {
$today = Get-Date
#test if today is Christmas
if ($today.Month -eq 12 -AND $today.day -eq 25) {
$text = "Merry Christmas!"
}
else {
$currYr = $Today.Year
$xmas = [datetime]"12/25/$currYr"
#test if Christmas has passed for this year.
if ($today -gt $xmas) {
$xmas = $xmas.AddYears(1)
}
$tspan = ($xmas-$today).ToString()
#strip off ms
$time=$tspan.substring(0,$tspan.LastIndexOf("."))
$text="[**~Christmas in $($time)~**]"
}
#write each character in a different color
$text.tocharArray() | foreach {
if ((Get-Random -min 1 -max 10) -gt 5) {
$color="RED"
}
else {
$color="GREEN"
}
write-host $_ -nonewline -foregroundcolor $color
}
Write (" PS " + (Get-Location) + "> ")
} #end function
Export-ModuleMember -function Start-Jingle,New-Tree,Get-Greeting,Get-Holiday,Prompt
当你浏览这些函数时,你可能会弄清楚其中一些函数的作用,但我不想破坏这个惊喜。但这里有一个例子。
获取该模块的副本并查看其中的命令。
get-command -module Christmas
不需要运行 Prompt,因为它会在您加载模块时自动运行。请注意,如果删除该模块,您将无法恢复旧的提示。只需重新启动 PowerShell 即可。
希望您度过一个快乐健康的假期和美好的新年。
猜你还喜欢
- 03-30 [玩转系统] 如何用批处理实现关机,注销,重启和锁定计算机
- 02-14 [系统故障] Win10下报错:该文件没有与之关联的应用来执行该操作
- 01-07 [系统问题] Win10--解决锁屏后会断网的问题
- 01-02 [系统技巧] Windows系统如何关闭防火墙保姆式教程,超详细
- 12-15 [玩转系统] 如何在 Windows 10 和 11 上允许多个 RDP 会话
- 12-15 [玩转系统] 查找 Exchange/Microsoft 365 中不活动(未使用)的通讯组列表
- 12-15 [玩转系统] 如何在 Windows 上安装远程服务器管理工具 (RSAT)
- 12-15 [玩转系统] 如何在 Windows 上重置组策略设置
- 12-15 [玩转系统] 如何获取计算机上的本地管理员列表?
- 12-15 [玩转系统] 在 Visual Studio Code 中连接到 MS SQL Server 数据库
- 12-15 [玩转系统] 如何降级 Windows Server 版本或许可证
- 12-15 [玩转系统] 如何允许非管理员用户在 Windows 中启动/停止服务
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[影视] 黑道中人 Alto Knights(2025)剧情 犯罪 历史 电影
[古装剧] [七侠五义][全75集][WEB-MP4/76G][国语无字][1080P][焦恩俊经典]
[实用软件] 虚拟手机号 电话 验证码 注册
[电视剧] 安眠书店/你 第五季 You Season 5 (2025) 【全10集】
[电视剧] 棋士(2025) 4K 1080P【全22集】悬疑 犯罪 王宝强 陈明昊
[软件合集] 25年6月5日 精选软件22个
[软件合集] 25年6月4日 精选软件36个
[短剧] 2025年06月04日 精选+付费短剧推荐33部
[短剧] 2025年06月03日 精选+付费短剧推荐25部
[软件合集] 25年6月3日 精选软件44个
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电视剧] 欢乐颂.5部全 (2016-2024)
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[影视] 【稀有资源】香港老片 艺坛照妖镜之96应召名册 (1996)
[剧集] 神经风云(2023)(完结).4K
[剧集] [BT] [TVB] [黑夜彩虹(2003)] [全21集] [粤语中字] [TV-RMVB]
[实用软件] 虚拟手机号 电话 验证码 注册
[资源] B站充电视频合集,包含多位重量级up主,全是大佬真金白银买来的~【99GB】
[影视] 内地绝版高清录像带 [mpg]
[书籍] 古今奇书禁书三教九流资料大合集 猎奇必备珍藏资源PDF版 1.14G
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电影] 美国队长4 4K原盘REMUX 杜比视界 内封简繁英双语字幕 49G
[电影] 死神来了(1-6)大合集!
[软件合集] 25年05月13日 精选软件16个
[精品软件] 25年05月15日 精选软件18个
[绝版资源] 南与北 第1-2季 合集 North and South (1985) /美国/豆瓣: 8.8[1080P][中文字幕]
[软件] 25年05月14日 精选软件57个
[短剧] 2025年05月14日 精选+付费短剧推荐39部
[短剧] 2025年05月15日 精选+付费短剧推荐36部
- 最新评论
-
- 热门tag