Fairly new to PowerShell and wanting to learn how to append objects to a variable list. Below is the error message:
Method invocation failed because [System.IO.FileInfo] does not contain a method named 'op_Addition'.
At C:\Users\Username\Desktop\Sandbox\New folder\BoxProjectFiles.ps1:117 char:4
+ $MechDWGFile += $file
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
and code:
LogWrite "`n-------------Mechanical Drawing(s)------------"
foreach ($file in $MechDWGList)
{
# Where the file name contains one of these filters
foreach($filter in $MechDWGFilterList)
{
if($file.Name -like $filter)
{
$MechDWGFile += $file # this is where the error is happening, so I know it is probably something simple
LogWrite $file.FullName
}
}
}
PowerShell 5.1 and Windows 10 OS is being used.
Could someone help me understand what's wrong with my syntax?