加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

挖掘PowerShell中的Console界面

发布时间:2020-12-14 03:32:35 所属栏目:大数据 来源:网络整理
导读:在我们使用PowerShell的时候,最常见到的必定是我们的PowerShell Console界面,比如你会看到默认深蓝色的底色,白色的字体以及其它各种你在Console界面中所见到的一切。 今天我们就来挖掘下PowerShell中Console界面的一些特性。我们可以使用如下System.Conso
在我们使用PowerShell的时候,最常见到的必定是我们的PowerShell Console界面,比如你会看到默认深蓝色的底色,白色的字体以及其它各种你在Console界面中所见到的一切。

今天我们就来挖掘下PowerShell中Console界面的一些特性。我们可以使用如下System.Console类在PowerShell中查看下控制台的一些支持属性:

PS C:UsersAdministrator> [System.Console].Getmembers()|Foreach{$_.name}
get_IsInputRedirected
get_IsOutputRedirected
get_IsErrorRedirected
get_In
get_Out
get_Error
get_InputEncoding
set_InputEncoding
get_OutputEncoding
set_OutputEncoding
get_BackgroundColor
set_BackgroundColor
set_ForegroundColor
get_ForegroundColor
set_BufferHeight
get_BufferHeight
get_BufferWidth
set_BufferWidth
get_WindowHeight
set_WindowHeight
get_WindowWidth
set_WindowWidth
get_LargestWindowWidth
get_LargestWindowHeight
set_WindowLeft
get_WindowLeft
set_WindowTop
get_WindowTop
get_CursorLeft
set_CursorLeft
get_CursorTop
set_CursorTop
set_CursorSize
get_CursorSize
get_CursorVisible
set_CursorVisible
set_Title
get_Title
get_KeyAvailable
get_NumberLock
get_CapsLock
get_TreatControlCAsInput
set_TreatControlCAsInput
Beep
Beep
Clear
ResetColor
MoveBufferArea
MoveBufferArea
SetBufferSize
SetWindowSize
SetWindowPosition
SetCursorPosition
ReadKey
ReadKey
add_CancelKeyPress
remove_CancelKeyPress
OpenStandardError
OpenStandardError
OpenStandardInput
OpenStandardInput
OpenStandardOutput
OpenStandardOutput
SetIn
SetOut
SetError
Read
ReadLine
WriteLine
Write
ToString
Equals
GetHashCode
GetType
IsInputRedirected
IsOutputRedirected
IsErrorRedirected
In
Out
Error
InputEncoding
OutputEncoding
BackgroundColor
ForegroundColor
BufferHeight
BufferWidth
WindowHeight
WindowWidth
LargestWindowWidth
LargestWindowHeight
WindowLeft
WindowTop
CursorLeft
CursorTop
CursorSize
CursorVisible
Title
KeyAvailable
NumberLock
CapsLock
TreatControlCAsInput
CancelKeyPress</span>

这里我们使用了一个小技巧来获得关于[System.Console]类下面的成员,我们就拿其中的几项举例说明吧,比如CapsLock,这个成员类型是用于判断键盘是否开启了大写,我们可以按如下的方法使用:

<span style="color:#000000;">If([System.Console]::CapsLock)
{
    Write-Host "Caps lock key is enabled." 
}
Else
{
    Write-Host "Caps lock key is disabled."
}


我们也可以设置Console界面的背景色,通过使用BackgroundColor成员属性来设置,但是如何知道PowerShell支持哪些颜色呢?下面的方法可以帮助你:)

PS C:UsersAdministrator> [System.Console]::BackgroundColor|Get-Member -Static -MemberType property


   TypeName: System.ConsoleColor

Name        MemberType Definition
----        ---------- ----------
Black       Property   static System.ConsoleColor Black {get;}
Blue        Property   static System.ConsoleColor Blue {get;}
Cyan        Property   static System.ConsoleColor Cyan {get;}
DarkBlue    Property   static System.ConsoleColor DarkBlue {get;}
DarkCyan    Property   static System.ConsoleColor DarkCyan {get;}
DarkGray    Property   static System.ConsoleColor DarkGray {get;}
DarkGreen   Property   static System.ConsoleColor DarkGreen {get;}
DarkMagenta Property   static System.ConsoleColor DarkMagenta {get;}
DarkRed     Property   static System.ConsoleColor DarkRed {get;}
DarkYellow  Property   static System.ConsoleColor DarkYellow {get;}
Gray        Property   static System.ConsoleColor Gray {get;}
Green       Property   static System.ConsoleColor Green {get;}
Magenta     Property   static System.ConsoleColor Magenta {get;}
Red         Property   static System.ConsoleColor Red {get;}
White       Property   static System.ConsoleColor White {get;}
Yellow      Property   static System.ConsoleColor Yellow {get;}

我们使用Get-Member方法获得出所有静态的属性,这就是PowerShell所支持的全部的背景色了。


??

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读