Page 1 of 1 1
Topic Options
#144030 - 2005-07-21 12:58 PM Populating CSV Columns
otf Offline
Getting the hang of it

Registered: 2003-11-21
Posts: 53
Loc: Scotland
hi,

I want my output of AD users to populate specified columns in a CSV instead of listing all output under the 1st column.

my code:

BREAK ON
$domain = GetObject("LDAP://ou=blah,dc=blah,dc=blah,dc=blah") ;Connect to AD
IF NOT $domain = 0 ;Confirm connection
$nul=RedirectOutput("c:\export.csv",0) ;Output to CSV
"Department,Name,Surname,First Name,Email Address, Description" ;6 Columns set in CSV
For Each $user in $domain
? $user.department ? $user.givenname ? $user.sn ? $user.name ? $user.mail ? $user.description
;end of script

I've tried a few things but nothing to give me the result i require. I know there must be a simple way of doing this but i'm starting to go round in circles here
thanks

Top
#144031 - 2005-07-21 01:10 PM Re: Populating CSV Columns
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
it's called a csv for a reason - comma separated values, so give this a shot

$line = $user.department + "," + $user.givenname + "," + $user.sn + "," + $user.name + "," + $user.mail + "," + $user.description
? $line

Top
#144032 - 2005-07-21 01:15 PM Re: Populating CSV Columns
otf Offline
Getting the hang of it

Registered: 2003-11-21
Posts: 53
Loc: Scotland
thanks for your reply maciep, works great
i had tried comma's but i'd forgotten the +","+
i was only putting ","
doh
thank you kindly

Top
#144033 - 2005-07-21 01:16 PM Re: Populating CSV Columns
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
no problem, o
Top
#144034 - 2005-07-21 05:41 PM Re: Populating CSV Columns
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Need to be careful though as it is possible for some values to maybe have a comma in them arleady.
 
Then the delimiter would not work well.
 

Top
#144035 - 2005-07-22 05:19 AM Re: Populating CSV Columns
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Strings should be quote-delimited, thus
Code:

? '"'+$user.department+'","'+$user.givenname+'","'+$user.sn+'","'+$user.name+'","'+$user.mail+'","'+$user.description+'"'


Fixed code.


Edited by sealeopard (2005-07-23 03:59 PM)
_________________________
There are two types of vessels, submarines and targets.

Top
#144036 - 2005-07-22 03:17 PM Re: Populating CSV Columns
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
missing the last double quote at the end...
_________________________
!

download KiXnet

Top
#144037 - 2005-07-23 03:59 PM Re: Populating CSV Columns
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Better?
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1607 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.064 seconds in which 0.029 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org