Attempting to recursively export members of OUs and output them to CSVs in Powershell -


i've been trying hours create script outputs members within each ou , saves list of members document title of ou.

here's have far:

$cou = import-csv c:\users\hp\cou.csv foreach ($ou in $cou) {get-aduser  -filter * -searchbase "ou=$($cou.ou),ou=testou,dc=domain,dc=net"}  | foreach ($_) {export-csv "c:\users\hp\$($cou.ou).csv"} 

i keep getting errors directory cannot found, no matter formatting use when attempting info ous errors, , more when attempting export.

the csv formatted so:
ou
firstou
secondou
thirdou
...

getting list of users work without variable if type name of ou , if "write-output" variable names of ous i'm guess issue relates how insert variable string.

this first post apologies formatting errors, please let me know , can correct them.

i though instead of importing csv use following command:

get-adobject -ldapfilter "(ou=*)" -searchbase "ou=testou,dc=domain,dc=net" 

this one's simple. define foreach loop foreach($ou in $cou) within loop continue reference $cou instead of $ou. simplified more though expanding ou property when import csv, , working array of strings instead.

$cou = import-csv c:\users\hp\cou.csv | select -expand ou foreach ($ou in $cou){     get-aduser -filter * -searchbase "ou=$ou,ou=testou,dc=domain,dc=net" | export-csv "c:\users\hp\ou.csv" -notype } 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -