Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - how to read input file of DN's and perform operations on them?

Reply
 
Old 08-29-2006   #1 (permalink)
=?Utf-8?B?c2Jx?=


 
 

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 SpecsSystem Spec
Old 08-30-2006   #2 (permalink)
=?Utf-8?B?L1wvXG9cL1wv?=


 
 

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 SpecsSystem Spec
Old 08-30-2006   #3 (permalink)
=?Utf-8?B?c2Jx?=


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46