Home > Software engineering >  Need PowerShell script to filtering the excel data
Need PowerShell script to filtering the excel data

Time:06-24

I am trying to filter the data contains in excel. but it showing error.

Import-Csv -Path "D:\Excel\Data\List.csv" -Header "EventID", "TimeCreated", "Computer", "TargetUserName", "SubjectUserName", "HOSTName", "Filename" | 
        Where-Object {[INT]$_.TargetUserName -eq 122388} | 
        Select-Object "EventID", "TimeCreated", "Computer", "TargetUserName", "SubjectUserName", "HOSTName", "Filename" | 
        Export-Csv "D:\Excel\test.csv" -NoTypeInformation

Excel Input data

Error while executing

CodePudding user response:

It's likely getting read in as a string instead of an integer. Do an equality test against a string instead.

Try replace Where-Object {[INT]$_.TargetUserName -eq 122388} with Where-Object {$_.TargetUserName -eq "122388"}

  • Related