Last active
October 29, 2020 19:23
-
-
Save mavericksevmont/3b02879737778dc23ba4c5c3c7a8ee57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# PowerShell Script to convert dbf file to csv (or almost anything else, really) without Excel. | |
Requires dBASE.NET.dll assembly: https://github.com/henck/dBASE.NET | |
This is a draft | |
#> | |
$Source = "$PSScriptRoot\da_md_wpa.dbf" # dbf file | |
$dll = "$PSScriptRoot\dBASE.NET.dll" # Assembly | |
$BaseName = (Get-Item $Source).BaseName | |
$Count = $null | |
$Assembly = [Reflection.Assembly]::LoadFile("$dll") # Load Assembly | |
$dbf = New-Object dBASE.NET.Dbf # Load class | |
$dbf.Read($Source) # Read dbf file's content | |
$Headers = $dbf.Fields.Name | |
$Records = $dbf.Records | |
$Data = $Records.Data | |
$ColNum = $Headers.Count | |
foreach ($Row in $Records) { | |
$Count++ | |
Write-Progress -Status "Completed $Count out of $($Records.Count)" -Activity "Converting $Source to CSV" ` | |
-PercentComplete ($Count/$Records.count*100) | |
$obj = New-Object PSOBject | |
for ($i=0;$i -lt $ColNum;$i++){ | |
$obj | Add-Member -MemberType NoteProperty -Name $Headers[$i] -Value $Row[$i] } | |
$Results = [array]$Results + $obj | |
$obj = $null | |
} | |
$Results | Export-Csv "$PSScriptRoot\$BaseName.csv" -NoTypeInformation -Force -Verbose |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment