I am looking for way to use this simple command to read a list of computers from a text file or a CSV then get the OU of each computer in my txt file. then write the computer name and OU to a excel file. This does not seem like it should be difficult. I do not need the Read-host portion to work rather I need this to get-content "C:\temp\ps3\computernames.txt"
this works well for one computer name:
$cn = Read-Host "Enter the ComputerName"
$cnObj = Get-ADComputer $cn
$ou = $cnObj.distinguishedname
$ou
I want something more like this
$cn = get-content "C:\temp\ps3\computernames.txt"
$cnObj = Get-ADComputer $cn
$ou = $cnObj.distinguishedname
$ou | Export-csv "C:\temp\ps3\computernamesandOU.csv"
Also there is a PS1 I have used that gives a real nice format however it does not list a way to refference a filename this is the name of the script which can be found online
GetComputerOU.ps1