Example: Remove an object in an array list by value of object property

  • 1 August 2017
  • Sean Huggans
Description: 

Example: Remove an object in an array list by index based on the value of the one of the object's properties

Language: 
PowerShell
Usage Type: 
Standalone
Script Source: 
$ObjectInformationStore = New-Object System.Collections.ArrayList
$ObjectStoreEntry = New-Object -TypeName PSObject
$ObjectStoreEntry | Add-Member -MemberType NoteProperty -Name AppName -Value A
$ObjectStoreEntry | Add-Member -MemberType NoteProperty -Name AppVersion -Value 1a
$ObjectStoreEntry | Add-Member -MemberType NoteProperty -Name AppPublisher -Value 1b
$ObjectStoreEntry | Add-Member -MemberType NoteProperty -Name AppDescription -Value 1c
$ObjectInformationStore.Add($ObjectStoreEntry) | Out-Null
$ObjectStoreEntry = New-Object -TypeName PSObject
$ObjectStoreEntry | Add-Member -MemberType NoteProperty -Name AppName -Value B
$ObjectStoreEntry | Add-Member -MemberType NoteProperty -Name AppVersion -Value 2a
$ObjectStoreEntry | Add-Member -MemberType NoteProperty -Name AppPublisher -Value 2b
$ObjectStoreEntry | Add-Member -MemberType NoteProperty -Name AppDescription -Value 2c
$ObjectInformationStore.Add($ObjectStoreEntry) | Out-Null
$ObjectStoreEntry = New-Object -TypeName PSObject
$ObjectStoreEntry | Add-Member -MemberType NoteProperty -Name AppName -Value C
$ObjectStoreEntry | Add-Member -MemberType NoteProperty -Name AppVersion -Value 3a
$ObjectStoreEntry | Add-Member -MemberType NoteProperty -Name AppPublisher -Value 3b
$ObjectStoreEntry | Add-Member -MemberType NoteProperty -Name AppDescription -Value 3c
$ObjectInformationStore.Add($ObjectStoreEntry) | Out-Null
 
cls
write-host "Before:"
$ObjectInformationStore | Out-String
write-host " "
 
$ObjectInformationStore.RemoveAt($ObjectInformationStore.IndexOf($($ObjectInformationStore | Where-Object -property AppName -eq "B"))) | Out-Null
 
write-host "After:"
$ObjectInformationStore | Out-String
write-host " "
Note: that all applications posted here are posted for use, both commercial and non-commercial, free of charge, and as such are provided as-is, without warranty of any kind whatsoever. visuaFUSION, FMSCUG or any other program listed here's author are not responsible for any damages or shortcomings that result from usage of any of these applications.
Error | visuaFUSION Systems Solutions Blog

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /mnt/home/visuafus/public_html/bahusa.net/includes/common.inc:2861) in drupal_send_headers() (line 1551 of /mnt/home/visuafus/public_html/bahusa.net/includes/bootstrap.inc).
  • Error: Call to undefined function mail() in DefaultMailSystem->mail() (line 79 of /mnt/home/visuafus/public_html/bahusa.net/modules/system/system.mail.inc).

Error

The website encountered an unexpected error. Please try again later.