Active Directory

/Active Directory

Powershell how to read a csv file

Here is how we can get information in a csv file format using Export-CSV command.

Get-ADComputer -Filter { name -like “*searchString*”} | select Name | Export-CSV c:\temp\filename.csv

Once we have the csv file the best command to read eventually this information is not Get-Content but Import-CSV.  Import-CSV reads the individual entries in CSV file and keeps it as an object. So we have to use the format object.atribute to read the value, e.g. as the column header of my csv file is Name, I can read the csv file using that attribute.

ForEach ($Computer In $Computers){Write-Host $Computer.Name}

By |2018-09-19T12:50:03+00:00September 19th, 2018|Active Directory, Powershell|0 Comments