[玩转系统] 看着我!
作者:精品下载站 日期:2024-12-14 07:43:08 浏览:13 分类:玩电脑
看着我!
这是这个功能,然后我会解释如何使用它。
Function Invoke-Flasher {
<#
.Synopsis
Display a flashing message.
.Description
This command will present a flashing message that you can use at the end of a script or command to signal the user. By default the command will write a message to the console that alternates the background color between the current console color and a red. You can press any key to end the function and restore the original background color.
You can also use the -FullScreen switch which will alternate the background color of the entire PowerShell console. Be aware that you will lose any script output that was displayed on the screen.
This command will NOT work in the PowerShell ISE.
.Example
PS C:\> Get-Process | Sort WS -Descending | select -first 5 ; Invoke-Flasher
This is a command line example of what a basic script would look like.
.Example
PS C:\> $data = get-eventlog Security ; Invoke-Flasher "Security logs retrieved." -fullscreen ; $data
This example uses the fullscreen parameter because the command output was saved to a variable.
.Notes
Last Updated: August 10, 2014
Version : 0.9
Learn more:
PowerShell in Depth: An Administrator's Guide (http://www.manning.com/jones2/)
PowerShell Deep Dives (http://manning.com/hicks/)
Learn PowerShell in a Month of Lunches (http://manning.com/jones3/)
Learn PowerShell Toolmaking in a Month of Lunches (http://manning.com/jones4/)
****************************************************************
* 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. *
****************************************************************
.Link
https://jdhitsolutions.com/blog/2014/08/look-at-me
.Link
Write-Host
.Inputs
None
.Outputs
None
#>
[cmdletbinding()]
Param(
[Parameter(Position=0)]
[string]$Text="The command has completed.",
[string]$Color = "red",
[Switch]$FullScreen
)
#save current background color
$bg = $host.ui.RawUI.BackgroundColor
$Running = $True
#set cursor position
$Coordinate = $host.ui.RawUI.CursorPosition
While ($Running) {
if ($host.ui.RawUI.BackgroundColor -eq $bg) {
$host.ui.RawUI.BackgroundColor = $color
if ($FullScreen) { Clear-Host}
}
else {
$host.ui.RawUI.BackgroundColor = $bg
if ($FullScreen) { Clear-Host}
}
#set the cursor position
$host.ui.rawui.CursorPosition=$Coordinate
Write-Host "`n$Text Press any key to continue . . ."
#see if a key has been pushed
if ($host.ui.RawUi.KeyAvailable) {
$key = $host.ui.RawUI.ReadKey("NoEcho,IncludeKeyUp,IncludeKeyDown")
if ($key) {
$Running = $False
}
} #if key available
start-sleep -Milliseconds 500
} #while
$host.ui.RawUI.BackgroundColor = $bg
if ($FullScreen) { Clear-Host}
}
此函数仅适用于 PowerShell 控制台,不适用于 PowerShell ISE,因为它使用 $host.ui.rawui 中的 ReadKey() 方法来检测用户是否按下任何键。该函数的主要部分不断循环,直到按下某个键。每次主机 UI 的背景颜色都会在当前颜色和红色或您指定的任何控制台颜色之间切换。每次通过脚本都会写下您的文本和“按任意键继续”。我每次都使用主机的坐标属性写入屏幕上的同一位置,这样就不会滚动。
默认情况下,Write-Host 线将通过交替背景颜色来“闪烁”。或者您可以使用 -FullScreen 参数,该参数每次都会清除主机。如果您在脚本中使用此选项,请确保脚本的主要部分将数据保存在某处,因为您不会看到它。这是一个如何使用它的示例。
#dot source the function
. c:\scripts\Invoke-Flasher.ps1
cls
$computers = get-content computers.txt
$data = Get-Process -computername $Computers | group Machinename -AsHashTable
$data.GetEnumerator() | foreach { $_.value | sort WS -Descending | Select -first 5 | format-table -group Machinename}
Invoke-Flasher
脚本的主要部分完成后,结果后会显示闪烁的消息。如果你想使用全屏方法,你可以尝试这样的方法:
#dot source the function
. c:\scripts\Invoke-Flasher.ps1
cls
$computers = get-content computers.txt
$data = Get-Process -computername $Computers | group Machinename -AsHashTable
$output = $data.GetEnumerator() | foreach { $_.value | sort WS -Descending | Select -first 5 | format-table -group Machinename}
Invoke-Flasher -fullscreen
$output
当脚本的主要部分完成时,您将看到一个闪烁的屏幕,其中包含文本消息。按任意键,您就会得到结果。
我不得不说我对这个功能很感兴趣,并且已经可以想到一些改进它的方法。如果您有建议或觉得这有用,希望您告诉我。
猜你还喜欢
- 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