![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | how to read input file of DN's and perform operations on them? I'm a complete scripting newbie, so bear with me. I'm trying to read in a file of users semi-distinguishedName's and use them to get certain values for their properties, then output that to a CSV file (for example output a csv file with distinguishedName and legacyExchangeDN for each user). I've been reading MoW's excelelnt blog series on Powershell and Active Directory, which has gotten me this far. I've already bound to the domain ($dom = New-Object System.DirectoryServices.DirectoryEntry) and been able to use that to search ($dom.get_children().find(value)). I've also figured out how to read the file with the DN's (minus the DC=domain,DC=com part) into an array and then plug that into the find (($dom.get_children().find($testDN[0] and [1] and [2]), but I can't figure out how to script it so that each array value gets written to the csv file via export-csv. I've tried: PS C:\temp\work> $testDN = (get-content test1-import.txt) PS C:\temp\work> foreach ($testDN in $testDN) { >>$dom.get_children().find($testDN) | export-csv -NoTypeInformation test3.csv >>} but I only end up with the last DN listed in the input file in the csv. I've also tried other things but I keep running into errors or a csv file with only one entry in it. is there a simple way to do this or am I looking at a complex script to get this csv file? |
My System Specs![]() |
| | #2 (permalink) |
| | RE: how to read input file of DN's and perform operations on them? Glad to hear my AD series did help, about your problem, You write a new CSV file for every record, # export-csv inside the loop so file overwritten in every pass foreach ($testDN in $testDN) { $dom.get_children().find($testDN) | export-csv -NoTypeInformation test3.csv } # export-csv out of the loop $testDN | foreach { $dom.get_children().find($_) } | export-csv -NoTypeInformation test3.csv Note that you also use the collection variable also for the loop variable ($testDN in $testDN) Also in the series, in this post I cover exporting to CSV in more detail : http://mow001.blogspot.com/2006/08/p...ry-part-5.html Greetings /\/\o\/\/ "sbq" wrote: > I'm a complete scripting newbie, so bear with me. I'm trying to read in a > file of users semi-distinguishedName's and use them to get certain values for > their properties, then output that to a CSV file (for example output a csv > file with distinguishedName and legacyExchangeDN for each user). I've been > reading MoW's excelelnt blog series on Powershell and Active Directory, which > has gotten me this far. > > I've already bound to the domain ($dom = New-Object > System.DirectoryServices.DirectoryEntry) and been able to use that to search > ($dom.get_children().find(value)). I've also figured out how to read the > file with the DN's (minus the DC=domain,DC=com part) into an array and then > plug that into the find (($dom.get_children().find($testDN[0] and [1] and > [2]), but I can't figure out how to script it so that each array value gets > written to the csv file via export-csv. I've tried: > > PS C:\temp\work> $testDN = (get-content test1-import.txt) > PS C:\temp\work> foreach ($testDN in $testDN) { > >>$dom.get_children().find($testDN) | export-csv -NoTypeInformation test3.csv > >>} > > but I only end up with the last DN listed in the input file in the csv. > I've also tried other things but I keep running into errors or a csv file > with only one entry in it. is there a simple way to do this or am I looking > at a complex script to get this csv file? |
My System Specs![]() |
| | #3 (permalink) |
| | RE: how to read input file of DN's and perform operations on them? That did it exactly! thanks. "/\/\o\/\/" wrote: > Glad to hear my AD series did help, > > about your problem, You write a new CSV file for every record, > > # export-csv inside the loop so file overwritten in every pass > > foreach ($testDN in $testDN) { > $dom.get_children().find($testDN) | export-csv -NoTypeInformation test3.csv > } > > # export-csv out of the loop > > $testDN | foreach { > $dom.get_children().find($_) > } | export-csv -NoTypeInformation test3.csv > > Note that you also use the collection variable also for the loop variable > ($testDN in $testDN) > > Also in the series, in this post I cover exporting to CSV in more detail : > > http://mow001.blogspot.com/2006/08/p...ry-part-5.html > > Greetings /\/\o\/\/ [snip] |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| file copy operations using source file input and script? | PowerShell | |||
| How to read CSV to another command's input? | PowerShell | |||
| File operations | Vista General | |||
| Slow file operations and cannot use ViceVersa | Vista file management | |||
| Slow file operations and cannot use ViceVersa | Vista file management | |||