I have a PowerShell function called Get-LogData
and when I call this function like this:
Get-LogData | Format-Table -AutoSize
it outputs information in form of a table with the following columns:
Author, Revision, Msg, Path
I would want to insert this information into a new SQL database table and if the table exist, it has to be dropped first before the insert.
Here is my function:
Function Get-LogData() {
$FromRev = "170000"
$ToRev = "171000"
$Range = $FromRev + ':' + $ToRev
$YourMother = "SVNStaticTable"
#Create Table object
$table = New-Object System.Data.DataTable "$YourMother"
#Define Columns
$col1 = New-Object System.Data.DataColumn Author,([string])
$col2 = New-Object System.Data.DataColumn Revision,([string])
$col3 = New-Object System.Data.DataColumn Msg,([string])
$col4 = New-Object System.Data.DataColumn Path,([string])
#Add the Columns
$table.Columns.Add($col1)
$table.Columns.Add($col2)
$table.Columns.Add($col3)
$table.Columns.Add($col4)
$LogOutput = ([xml](svn log http://Servername/svn/xyz -v -r $Range --xml)).log.logentry
foreach ($entry in $LogOutput) {
$paths = $entry.paths.path
foreach ($path in $paths) {
if ($path.InnerText -like "*/static/*") {
#Create a row
$row = $table.NewRow()
$row.Author = $entry.author
$row.Revision = $entry.revision
#$row.Msg = $entry.msg.Replace('\D+(\d+)\D+','$1') #you call a function here
$row.Path = $path.InnerText.Replace("/xyz/", "")
#$row.Msg = $entry.msg.Replace("\w", '') #you call a function here
$row.Msg = $entry.msg.Substring(0, 7) #using the substring works
#$row.Msg = $test -replace "^.*_(\d*)$test.*$", '$1'
$table.Rows.Add($row)
}
}
}
$table
}