Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Looking for a way to run this script using in text file to import the names of the computers to use... then export the computer name and OU it is in to a csv.

$
0
0
 

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


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>