VRK
VRK

Reputation: 1366

powershell script to extract specific column from csv file and store in array

My csv file looks like this

Product_Name    Component           SvnDirectory
ABC             export-service      export
ABC             import-service      import
ABC             service-service     service

My script should read this file and extract SvnDirectory column and store its values(export, import,service)in an array. I will later be using this to checkout from svn.

The script is

$svnDirectory= Import-Csv C:\temp\checkoutdirs.csv | % {$_.SvnDirectory}
Write-host $svnDirectory

The problem with this is, it stores values in such a way that I am not able to use it to checkout from svn.

Output
@Write-host $svnDirectory
export    import    service

So when I try to checkout using this

ForEach ($i in $svnDirectory) {
    $checkoutUrl = "$svnRepositoryBase/$svnDirectory/trunk"
    Write-host "SVN url to be checked out is $checkoutUrl"
    java -classpath $env:CLASSPATH org.tmatesoft.svn.cli.SVN co $checkoutUrl --username $username --password $securePassword --non-interactive
}

The svn url it takes is

SVN url to be checked out is 
http://subversion.abc.com/dev/prj/export  import  service/trunk

Upvotes: 0

Views: 24048

Answers (1)

VRK
VRK

Reputation: 1366

Alright i tried this and it worked

 $projectName = import-csv  ABC_Projects.csv | % {$_.SvnDirectory}
 Write-host $projectName

Upvotes: 3

Related Questions