https://lazywinadmin.github.io/powershell/2017/06/Remove_PSObject_Property.html
本节展示如何在Powershell中操作对象的属性。
首先先自定义出来一个对像:
PS C:\> $MyObject = New-Object -TypeName PSCustomObject -Property @{
>> ComputerName = $env:ComputerName
>> MacAddress = '00:11:22:33:44:55'
>> Description = 'My Computer'
>> }
查看一下自定义的对像有什么内容:
PS C:\> $MyObject
ComputerName Description MacAddress
------------ ----------- ----------
ASBJT-JOSHJIN My Computer 00:11:22:33:44:55
调用对像的这个方法把其中的一个属性去除掉。
PS C:\> $MyObject.PSObject.properties.remove('Description')
PS C:\> $MyObject
ComputerName MacAddress
------------ ----------
ASBJT-JOSHJIN 00:11:22:33:44:55