且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将对象转换为字符串?

更新时间:2022-06-17 04:50:40

当您使用 ... |Select-Object PropertyName 时,它会生成一个具有名为 PropertyName 的属性的对象code>,从输入项上的相应属性中复制值.

When you use ... |Select-Object PropertyName, it produces an object with a property named PropertyName, copying the value from the corresponding property on the input item.

使用 Select-Object -ExpandProperty PropertyNameForEach-Object MemberName 来获取属性的值:

Use Select-Object -ExpandProperty PropertyName or ForEach-Object MemberName to get just the value of the property:

$a = Get-Item . | Select-Object -ExpandProperty Name 
# or 
$a = Get-Item . | ForEach-Object Name

... 或直接引用属性:

... or reference the property directly:

$a = (Get-Item .).Name