Powershell CSV Import Issue

JAMES, Clinton 0 Reputation points
2023-05-12T06:40:34.34+00:00

Hi all,

I am tearing out what little hair I have left. I am performing an import-csv routine, filtering it down to one record, to then update one element of that record. Powershell behaves nicely when I want to view the value of the record, but when I go to set a new value, it seems to have Alzheimers and can't find the element that is obviously there. I have tried workarounds to no avail short of making a lengthy code which I need prescribe the element names again to just be in the correct order.

Is anybody able to tell me why this is happening or a viable work-around. Screenshot provided.
Thank you

User's image

Windows for business Windows Server User experience PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2023-05-12T15:31:21.2533333+00:00

    You're creating an array, not a scalar value. Arrays don't have a 'Version' property.

    $InstallerName = "Install_Edge.ps1"
    $Config_Content_Full = Import-Csv "c:\junk\Installer_versions.csv"
    $Item =    @($Config_Content_Full | Where-Object {$_.InstallerName -like    $InstallerName})
    $NotItem = @($Config_Content_Full | Where-Object {$_.InstallerName -notlike $InstallerName})
    
    $Item |
        ForEach-Object{
            $_.Version
            $_.Version = "AAAA"
        }
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.