Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
59 lines (50 sloc) 1.14 KB
layout title excerpt permalink tags categories published comments author_profile header gallery
single
Remove a PowerShell Object property
In this article we'll see how to remove a property from a Powershell Object
powershell
powershell
true
true
false
teaserlogo teaser image caption
images/headers/Code01_1920x500.jpg
image_path url title

Someone at work was recently asking me about the following: How to remove a property from a PowerShell Object ?

Here is how you can achieve that.

Create a PowerShell Object

$MyObject = New-Object -Typename PSCustomObject -Property @{
    ComputerName = $env:ComputerName
    MacAddress = '00:11:22:33:44:55'
    Description = 'My Computer'
}

$MyObject returns:

ComputerName    Description MacAddress
------------    ----------- ----------
DESKTOP-HPHHRC5 My Computer 00:11:22:33:44:55

Remove the property

$MyObject.PSObject.properties.remove('Description')

$MyObject returns:

ComputerName    MacAddress
------------    ----------
DESKTOP-HPHHRC5 00:11:22:33:44:55