When I run my code, it gives me the following error.
What I am having the code do is taking the csv then filtering the name column to only be administrators, then I am having the caption column filter all of the operating systems that I have provided. The if statement is saying that If the column Type0 equals domain then put in the "Unique Account Name" column the Domain0 following the Account0. Else it will put it in Netbios name and then Account0. Below will be the excel sheet. and the desired output of each.

Import-Csv 'U:\Local Group Members.csv' | where-Object {($_.Name0 -eq "administrators") -and ($_.caption0 -match "Microsoft Windows 10 Enterprise|Microsoft Windows 7 Enterprise|Microsoft Windows 7 Professional|Microsoft Windows 8 Enterprise|Microsoft Windows 8 Pro|Microsoft Windows 8.1 Enterprise|Microsoft Windows 8.1 Pro")} |
Select-Object "Netbios_name0", "Name0", "Account0","category0","Domain0","Unique Account Name","Type0","caption0", "Excluded" |
ForEach-Object
If ($_.Type0 -eq 'Domain') {
$_.UniqueAccountName = "$($_.Domain0) - $($_.Account0)"
} Else {
$_.UniqueAccountName = "$($_.Netbios_name0) - $($_.Account0)"
}
Export-Csv -notypeinformation U:\LGMbestone.csv
I am a powershell Novice, and I am stuck, and how do I can I get this code to run?