.NET Framework - 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?
CSV
(1)
MSFTNGP
(1)
TK
(1)
ElrwIJgZHHA
(1)
UDyLbZeZHHA
(1)
ScriptBut
(1)
FileName
(1)
UPN
(1)
  Brandon Shell replied...
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
  james replied...
14-Mar-07 01:28 AM
your are genius  of script
  james replied...
14-Mar-07 01:30 AM
But how to add user use powershell? How could I find what else powershell
would do Thx.
  Brandon Shell replied...
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
--------------------------------------
  Lee Holmes [MSFT] replied...
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.
Create New Account
help
powershell. So, what's the shortest way to do a search / replace on, say, a csv file. Just to keep it simple, let's say that the file is in the d think. Thanks - - Christopher D. Walborn Technical Support Agnoli, Barber & Brundage Powershell Discussions BrundageReferences (1) MSFTNGP (1) MSFT (1) PS (1) TK (1) KeithRe (1) BrundagePS (1) BrundageRe (1) Woops. That should read: The replacement pattern is
CommonDialog .NET Framework bonjours a tous. Pour rechercher mes fichiers CSV par exemple je faisais le code suivant sous VB6 With CommonDialog1 .Filter = "csv (*.csv) | *.csv" .Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer .ShowOpen If .FileName = "" Then Exit Sub im = .FileName End With Close y a le contrôle openfiledialog With OpenFileDialog1 .Title = "mon titre" .InitialDirectory = MonDossier .FileName = monfichier .Filter = "csv (*.csv) | *.csv" If .ShowDialog(Me) = Windows.Forms.DialogResult.OK Then . . . . . . . . . . . End If End With Jo impecable c ce que je cherchai merci keywords: CommonDialog description: bonjours a tous. Pour rechercher mes fichiers CSV par exemple je faisais le code suivant sous VB6 With CommonDialog1 .Filter = csv (*.csv) | *.cs
converting CSV comma to csv semi-column .NET Framework HI ! I am trying to convert a csv file with comma to a csv file with semi-column. I tried import-csv, export-csv, convert from. . . It did not work. I do not understand. I am an idiot ! What 1) PowerShell (1) Replace (1) You can only do this with PowerShell v2: PS> import-csv input.csv | export-csv -delim ";" output.csv PowerShell v1 does not support the -Delimiter parameter. Marco thank
Import-Csv and doesn't count single row? .NET Framework I have the following csv file, contains three rows. When importing the file with Import-Csv it works fine and returns 3 for the count. If there's only one row in the csv file the count property returns nothing. server, folder srv1, folder1 srv2, folder2 srv3, folder3 PS C: \ Scripts> (Import-Csv test.csv).count PS C: \ Scripts> 3 server, folder srv1, folder1 PS C: \ Scripts> (Import-Csv test.csv).count PS C: \ Scripts> Shay http: / / www.scriptolog.blogspot.com Powershell Discussions MyArray.count (1