Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a Member from a PowerShell Object?

I need to remove a member (specifically, a NoteProperty) from an object. How do I accomplish this?

like image 962
Tohuw Avatar asked Jul 28 '13 04:07

Tohuw


People also ask

How do you delete an object in PowerShell?

The Remove-ADObject cmdlet removes an Active Directory object. You can use this cmdlet to remove any type of Active Directory object. The Identity parameter specifies the Active Directory object to remove.

How do you delete a user in PowerShell?

The Remove-ADUser cmdlet removes an Active Directory user. The Identity parameter specifies the Active Directory user to remove. You can identify a user by its distinguished name (DN), GUID, security identifier (SID), or Security Account Manager (SAM) account name.

What is remove item in PowerShell?

The Remove-Item cmdlet deletes one or more items. Because it is supported by many providers, it can delete many different types of items, including files, folders, registry keys, variables, aliases, and functions.

How do I remove values from an array in PowerShell?

RemoveAt: Remove Objects by Index It was easy to find the index of “C” in such a small array list, but it you have a larger array list, you can use the IndexOf method to find the index and then use the RemoveAt method to remove the object at that index.


1 Answers

Select-Object with ExcludeProperty is good for removing a property from a collection of objects.

For removing a property from a single object this method might be more effective:

# new object with properties Test and Foo $obj = New-Object -TypeName PSObject -Property @{ Test = 1; Foo = 2 }  # remove a property from PSObject.Properties $obj.PSObject.Properties.Remove('Foo') 
like image 50
Roman Kuzmin Avatar answered Sep 26 '22 01:09

Roman Kuzmin