您好,欢迎访问一九零五行业门户网

PowerTip of the Day-Accessing Object Properties

原文地址: http://powershell.com/cs/blogs/tips/archive/2010/06/08/accessing-object-properties.aspx 原文: accessing object properties objects store information in various properties. there are two approaches if you would like to get to the
原文地址:http://powershell.com/cs/blogs/tips/archive/2010/06/08/accessing-object-properties.aspx
原文:
accessing object properties
objects store information in various properties. there are two approaches if you would like to get to the content of a given property. one is commonly used among developers, the other one among admins. both will get you the same result. have a look:
# access powershell
$process = get-process -id $pid
# output entire object
$process
# read cpu usage only (developer version)
$process.cpu
# read cpu usage only (pipeline version)
$process | select-object -expandproperty cpu
翻译:
访问对象属性
一个对象会把很多信息存储到大量的属性当中。如果要访问其内容通常来说有两种方法。一种是在程序员当中最常用的方法,另一种是在管理员当中常用的。两种方法的结果都是一样的:
# 获取powershell进程实例
$process = get-process -id $pid
# 显示整个对象的信息
$process
# 读取cpu使用率属性 (程序员版本)
$process.cpu
#读取cpu使用率属性 (管道版本)
$process | select-object -expandproperty cpu
笔记:
$pid是一个内部保留变量?代表当前powershell运行的实例。(有待验证)
打点访问属性的方法应该是最熟悉不过的了,管道方式然后select-object –expandproperty感觉怪怪的。
其它类似信息

推荐信息