CSV
(1)
MSFTNGP
(1)
TK
(1)
ElrwIJgZHHA
(1)
UDyLbZeZHHA
(1)
ScriptBut
(1)
FileName
(1)
UPN
(1)

How to read CSV to another command's input?

Asked By james
13-Mar-07 10:10 PM
for /f "eol=; tokens=1,2,3,4,5,6 delims=," %a in (test1.csv) do dsadd user "
cn=%a,ou=test,dc=kevinliprc,dc=msft" -fn %b -ln %c -display %d -upn %e -pwd
%f - disabled no

like that command line before back to time of dos csv can be read, but is
there a smarter way to do it by powershell Import-Csv?

How to read CSV to another command's input?

Asked By Brandon Shell
13-Mar-07 10:59 PM
Import-CSV will work great if you have headers:
CN,FN,LN,Display,UPN,PWD

PS> $list = Import-Csv FileName
PS> $list[0]
You will have an object with properties of
CN      : cn1
FN      : fn1
LN      : ls1
Display : display1
UPN     : upn1
PWD     : pwd1

so you can do this
foreach($entry in $list)
{
$cmd = "dsadd.exe user `"cn=$($entry.cn),ou=test,dc=kevinliprc,dc=msft`" -fn
$($entry.fn),-ln $($entry.ln),display $($entry.Display),-upn
$($entry.upn),-pwd  $($entry.pwd), -disabled no"
}

This should do it, but I can't say its much better save the flexability.

p.s. You can do the ADD with powershell... you dont need dsadd.exe

How to read CSV to another command's input?

Asked By james
14-Mar-07 01:28 AM
your are genius  of script

But how to add user use powershell?

Asked By james
14-Mar-07 01:30 AM
But how to add user use powershell? How could I find what else powershell
would do Thx.
How to read CSV to another command's input?
Asked By Brandon Shell
14-Mar-07 09:12 AM
There are variety of ways to do it. Try a search here
http://bsonposh.com/modules/wordpress/?page_id=13

/\/\0\/\/ has good series on AD starting here (disregard the RC2. Its
literally the same)
http://mow001.blogspot.com/2006/06/powershel-and-active-directory-part-1.html
http://mow001.blogspot.com/2006/06/powershell-and-active-directory-part-2.html

To be up front this will be a good bit of work up front, but its a good
experience with Powershell and very useful in the long run.

--
Brandon Shell
---------------
Stop by my blog some time :)
Blog: http://www.bsonposh.com/
PSH Scripts Project:  www.codeplex.com/psobject
--------------------------------------
As an alternative to all of the inline variables, you might consider the
Asked By Lee Holmes [MSFT]
23-Mar-07 04:41 PM
As an alternative to all of the inline variables, you might consider the
format (-f) operator (as described about halfway down here:
http://groups.google.com/group/microsoft.public.windows.powershell/browse_thread/thread/3207f8f5a27ff1ad/0852708ffe0f7c6e?lnk=st&q=powershell+amiga&rnum=2#0852708ffe0f7c6e)

--
Lee Holmes [MSFT]
Windows PowerShell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
Post Question To EggHeadCafe