Windows Powershell属性:描述对象是什么

2019-09-30 14:46:35王旭

----             ----             -----------
1                ar               阿拉伯语

PS C:Powershell> [System.Globalization.CultureInfo] 33

LCID             Name             DisplayName
----             ----             -----------
33               id               印度尼西亚语

属性中包含对象

一个对象的属性用来存储数据,反过来这些数据又可以存储其它对象。$host有两个比较特别的属性UI和PrivateData。把$host对象输出到控制台上后,除了UI和PrivateData所有的属性都会被转换成确定的文本:


PS C:Powershell> $Host

Name  : ConsoleHost
Version          : 2.0
InstanceId        : 7fefa1fa-fb2e-47c7-a867-c13b123da5c2
UI                : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture    : zh-CN
CurrentUICulture  : zh-CN
PrivateData       : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed  : False
Runspace          : System.Management.Automation.Runspaces.LocalRunspace

原因是这两个属性中又包含了一个对象:


PS C:Powershell> $Host.UI

RawUI
-----
System.Management.Automation.Internal.Host.InternalHostRawUserInterface

PS C:Powershell> $Host.UI.RawUI

ForegroundColor : DarkYellow
BackgroundColor : DarkMagenta
CursorPosition : 0,23
WindowPosition : 0,0
CursorSize : 25
BufferSize  : 100,200
WindowSize  : 100,61
MaxWindowSize   : 100,62
MaxPhysicalWindowSize : 160,62
KeyAvailable       : False
WindowTitle       : Windows PowerShell

“RawUI” 为 “Raw User Interface” 提供了配置Powershell控制台用户界面的接口。上面的属性可以读取,但是个别却不能更改。

只读属性和读写属性

属性可以准确的描述对象,一旦属性更改了。这一更改也会体现在对象上。如果不能更改,属性就是“只读”属性。