I have employee details in employee.csv, which I have compiled each row in PS objects.
Now there will be -NotePropertyName "EmployeeTotal_LeaveCount" and the --NotePropertyValue should be the total occurrence of "YES" in the final object-
Single PSObject
@{EmployeeID=MACL22656; EmployeeRole=Accountant; EmployeeDepartment=Accounts; EmployeeLeave_Monday=YES; EmployeeLeave_Tuesday=YES; EmployeeLeave_Thursday=YES}
Expected Final Object:
@{EmployeeID=MACL22656; EmployeeRole=Accountant; EmployeeDepartment=Accounts; EmployeeLeave_Monday=YES; EmployeeLeave_Tuesday=YES; EmployeeLeave_Thursday=YES; EmployeeTotal_LeaveCount=3}
So far I tried
$employee|Add-Member -NotePropertyName "EmployeeTotal_LeaveCount" -NotePropertyValue ($employee|Select-String -CaseSensitive -Pattern 'YES' | Measure-Object).count
But it returns - 1 instead of 3 [as 'YES' occurred 3 times in Object]
Please help to achieve the expected result.