Reputation: 370
I've the following CSV
USER/PRIMARY_GROUP/OTHER_GROUPS X/adm/staff Y/staff/staff,users
I need the following result:
USER/PRIMARY_GROUP/OTHER_GROUPS X/adm/staff Y/staff/users
So if the group already exists in PRIMARY_GROUP column, it must be removed from OTHER_GROUPS column. In order to do so I have:
$Match = Import-Csv $UserReport4 -Delimiter ';'
foreach ($Line in $Match) {
if ($Line.Primary_Group -match $Line.Secondary_Group) {
Remove-Item $Line
}
}
And the only output I get is:
Remove-Item cannot bind argument to parameter 'path' because it is an empty string
Upvotes: 0
Views: 36
Reputation: 200493
Use a calculated property where you split the group list, remove the primary group from the resulting list, and join it back to a comma-separated string:
Import-Csv $UserReport4 -Delimiter ';' |
Select-Object USER, PRIMARY_GROUP, @{n='OTHER_GROUPS';e={
(($_.OTHER_GROUPS -split ',') -ne $_.PRIMARY_GROUP) -join ','
}}
Upvotes: 3