try Something like this:
$array1=import-csv "C:\temp\log.csv"
$array2=import-csv "C:\temp\log2.csv"
#modify founded and output not founded
$toadd=$array2 | %{
$current=$_
$founded=$array1 | where pc -eq $current.pc | %{$_.date=$current.date;$_}
if ($founded -eq $null)
{
$current.city='UNKNOW'
$current
}
}
#output of $array1 modified and elements to add
$array1, $toadd
Answer from Esperento57 on Stack OverflowSharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › powershell tutorials › powershell arraylist – a beginners guide!
PowerShell ArrayList - A Beginners Guide! - SharePoint Diary
September 30, 2025 - This code will check if the ArrayList contains the element “apple” and print a message if it does. You can easily convert between ArrayList and standard PowerShell arrays:
Top answer 1 of 2
2
try Something like this:
$array1=import-csv "C:\temp\log.csv"
$array2=import-csv "C:\temp\log2.csv"
#modify founded and output not founded
$toadd=$array2 | %{
$current=$_
$founded=$array1 | where pc -eq $current.pc | %{$_.date=$current.date;$_}
if ($founded -eq $null)
{
$current.city='UNKNOW'
$current
}
}
#output of $array1 modified and elements to add
$array1, $toadd
2 of 2
0
Here is a sample I created that might help. Note: I use List types instead of ArrayList ones. Also, it assumes only one possible matching PC name in the data to be updated. You'll have to alter it to update the file since it merely updates the first List variable. Let me know how it goes.
[PSCustomObject]
{
[string] $pc,
[string] $name,
[string] $date,
[string] $city
}
[System.Collections.Generic.List[PSCustomObject]] $list1 = Import-Csv "C:\SOSamples\log.csv";
[System.Collections.Generic.List[PSCustomObject]] $list2 = Import-Csv "C:\SOSamples\log2.csv";
[PSCustomObject] $record = $null;
[PSCustomObject] $match = $null;
foreach($record in $list2)
{
# NOTE: This only retrieves the FIRST MATCHING item using a CASE-INSENSITIVE comparison
$match = $list1 | Where { $_.pc.ToLower() -eq $record.pc.ToLower() } | Select -First 1;
if($match -eq $null)
{
Write-Host "Not Found!";
$list1.Add($record);
}
else
{
Write-Host "Found!";
$match.date = $record.date;
}
}
Write-Host "--------------------------------------------------------------------"
foreach($record in $list1)
{
Write-Host $record
}
PowerShell Test-Path
powershellfaqs.com › array-contains-in-powershell
Array Contains in PowerShell [With Examples]
February 14, 2025 - Learn how to check if an array contains a value in PowerShell with examples. Follow simple steps to use the -contains operator and streamline your data handling.
Adam the Automator
adamtheautomator.com › powershell-array
PowerShell Arrays, ArrayLists & Collections: Best Practices
Below you can see that you need to explicitly create an ArrayList object using the New-Object cmdlet or by casting a standard array to an ArrayList object. Notice that in this case the BaseType is an object whereas the above examples have BaseTypes of Arrays which exhibit inheritance from the Object class. Ultimately, PowerShell is providing access to the .NET type system.
Published April 22, 2025
| How
pipe.how › new-arraylist
PowerShell Collections: ArrayList | How
January 17, 2020 - The collection on today’s topic is however not strongly typed, and therefore it can inherently contain anything. Diving a little deeper, we saw earlier that ArrayList inherits directly from System.Object while Object[] had System.Array as it’s base type.
EDUCBA
educba.com › home › data science › data science tutorials › powershell tutorial › powershell array of strings
PowerShell Array of Strings | Guide to PowerShell Array of Strings
May 19, 2023 - New-Object -TypeName ... $arrlist.Add("PowerCLI") $arrlist.Add("DevOps") ... We must use the Contains() method to check if the string array contains any specific string....
Call +917738666252
Address Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
Computer Performance
computerperformance.co.uk › home › powershell
PowerShell Basics -Contains, -CContains & -NotContains | Code Examples
January 21, 2019 - A feature of -Contains is that usually returns “True” or “False. If you are looking for a command to return a list of values, then employ -Match or -Like. # PowerShell -Contains Operator Clear-Host $ArraySimple =@("House","Flat","Bungalow") $ArraySimple -Contains "Flat" # Result PS> True
Enterprise DNA
blog.enterprisedna.co › powershell-arraylist
Powershell ArrayList: How to Build Better Scripts – Master Data Skills + AI
PowerShell supports various operators for working with ArrayLists: Range operator (..): This enables creating an array containing a range of numbers by specifying the start and end values.
Powershellexplained
powershellexplained.com › 2018-10-15-Powershell-arrays-Everything-you-wanted-to-know
Everything you wanted to know about arrays - Powershell
October 15, 2018 - Unlike the ArrayList, there is no return value on the Add method so we don’t have to void it. ... And we can still access the elements like other arrays. ... You can have a list of any type, but when you don’t know the type of objects, you can use [List[PSObject]] to contain them.
Microsoft Learn
learn.microsoft.com › en-us › powershell › scripting › learn › deep-dives › everything-about-arrays
Everything you wanted to know about arrays - PowerShell | Microsoft Learn
July 20, 2024 - By default, an array in PowerShell is created as a [psobject[]] type. This allows it to contain any type of object or value.
PowerShell Forums
forums.powershell.org › powershell help
System.Collection.Arraylists containing objects - PowerShell Help - PowerShell Forums
December 31, 2011 - by Lembasts at 2013-02-13 15:14:49 Greetings, Having been persuaded to use the system.collections.arraylist class instead of boring old arrays, I had a look at the methods and was wondering how to use some of these when your arraylist contains objects. For example, how do I sort on a property ...
SS64
ss64.com › ps › syntax-arrays.html
Create and use PowerShell Arrays
A PowerShell array holds a list of data items. The data elements of a PowerShell array need not be of the same type, unless the data type is declared (strongly typed). To create an Array just separate the elements with commas. Create an array named $myArray containing elements with a mix of ...