1

First what I am trying to do is Filter out and delete all of the data except the administrators in the Name0 column but I want to leave everything that is in the row of them administrators.Here is the image of how the data looks.

Import-Csv 'U:\Local Group Members.csv' | Sort-Object -Property Name0 | Export-Csv -notypeinformation U:\newcsv.csv

How do I filter out everything except the administrators which is in the Name0 column?

1

1 Answer 1

2

You could filter with the Where-Object cmdlet

Import-Csv 'U:\Local Group Members.csv' |
    Where-Object {$_.Name0 -eq "administrators"} |
    Export-Csv -notypeinformation U:\newcsv.csv
Sign up to request clarification or add additional context in comments.

8 Comments

Thank you, that worked great! What if I needed to add something in with the administrators? Would it go like this?
Import-Csv 'U:\Local Group Members.csv' | Where-Object {$_.Name0 -eq "administrators","Users"} | Export-Csv -notypeinformation U:\newcsv.csv
@user7938223 You could use the -or statement to add another conditional. eg. {$_.Name0 -eq "administrators" -or $_.Name0 -eq "Users"}. Otherwise you could use -match which uses regex and | e.g. {$_.Name0 -match "administrators|Users"} Also if an answer worked for you, it's best practice to vote on or accept it.
Lastly, say I wanted to add another field with the follow. Where-Object {$_.caption0 -eq "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"}|
<grammarian nitpick>"principles", not "principals"</grammarian nitpick>
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.