I have a CSV file for the backup report in which I have multiple columns. I want to get only those clients who have never been successful with a particular save set.
Sample Input file is
Client Name,Save Set Name,Group,Status
a,All,Group1,Failed
a,SQL,Group2,succeeded
b,SQL,Group1,Failed
c,FS,Group1,Failed
d,DBA,Group1,Failed
e,RDM,Group1,Failed
a,ALL,Group2,succeeded
b,SQL,Group3,succeeded
c,SQL,Group4, Failed
Output
Client Name Save Set Name Status Group
a All Failed Group1
b SQL Failed Group1
c FS Failed Group1
d DBA Failed Group1
e RDM Failed Group1
c SQL Failed Group4
Expected Output
Client Name,Save Set Name,Group,Status
c,FS,Group1,Failed
d,DBA,Group1,Failed
e,RDM,Group1,Failed
c,SQL,Group4, Failed
In my command below, the problem I am facing is that I am getting clients as Failed who gets successful in some other group whereas I want only those clients with save sets who got failed and don't have any success value in status.
Get-Content E:\Report\Daily_Failed.csv |
ConvertFrom-Csv |
Select-Object -Unique * |
Group-Object -Property 'Client Name', 'Save Set Name', 'Group' |
Where-Object { 0 -eq ($_.Group | Where-Object Status -eq 'succeeded').Count } |
Select-Object -Expand Group |
Select-Object "Client Name", "Save Set Name", "status", "Group" |
Export-Csv -NoTypeInformation E:\Report\Failed_$CurrentDate.csv
Example 2.
Client Name,Save Set Name,Group,Status
gsiecwt2020.web.local,pseudo_saveset,D_CWT_File_System_1,failed
gsiecwt2020.web.local,J:\System,D_CWT_File_System_2,succeeded
gsiecwt2020.web.local,K:\System,D_CWT_File_System_1,succeeded
gsiecwt2020.web.local,K:\System,D_CWT_File_System_3,failed
Desired Output
gsiecwt2020.web.local,pseudo_saveset,D_CWT_File_System_1,failed
It should be matching Client Name, Save Set Name and Status.
If the client with same Save Set Name gets succeeded in any other group, then it should be marked as a success, but if the client with particular Save Set Name is failed then it should be marked as Failed.