Remove object from an array

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 1 year and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
smarbar@gmail.com
Posts: 1
Last visit: Fri May 13, 2022 8:27 am

Remove object from an array

Post by smarbar@gmail.com »

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***
Product: PowerShell Studio 2022 (64 Bit)
Build: v5.8.206
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.22000.0
PowerShell version(s): Tried 5.1 & 7.2

*** Please add details and screenshots as needed below. ***

DO NOT POST LICENSES, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

I have an array of JSON objects imported from a file into a variable, I am trying to remove one of the objects from the variable. I have tried various options as below and they all work when I test them in VSCode but it doesnt seem to work in Powershell Studio.

I have tried filtering the record and replacing the current variable as well as make a new variable with filtered results, again none work in Studio but all work in VSCode.

e.g.1
$newCon = $nc | Where-Object { $_ -ne $deleteRecord }

e.g.2
foreach ($c in $nc)
{
if ($c -ne $deleteRecord)
{
$newCon += $c
}
}
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 3:14 pm
Answers: 39
Been upvoted: 30 times

Re: Remove object from an array

Post by brittneyr »

Without the full script, I cannot determine what is wrong. Debugging may help you identify the problem.

You also may find the following helpful:
https://www.sapien.com/blog/2014/11/18/ ... owershell/
Brittney
SAPIEN Technologies, Inc.
This topic is 1 year and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.