51 lines
1.7 KiB
PowerShell
51 lines
1.7 KiB
PowerShell
#Test
|
|
cls
|
|
Import-module sqlps
|
|
|
|
$SourceFile = Get-Item "P:\Skriptentwickung\development\Import-FileContent2Database\wisag_test-dateien\AVIAFAK_LFB1.DAT"
|
|
|
|
Add-Member -InputObject $SourceFile -MemberType NoteProperty -Name Content -Value (Get-Content -Path $($SourceFile.FullName) -ErrorAction Stop) -Force
|
|
Add-Member -InputObject $SourceFile -MemberType NoteProperty -Name ContentLines -Value ($SourceFile.Content | Convertfrom-csv -Delimiter “`t” -ErrorAction Stop) -Force
|
|
#-Delimiter "`t"
|
|
|
|
$test = Import-Csv -Delimiter "`t" "P:\Skriptentwickung\development\Import-FileContent2Database\wisag_test-dateien\AVIAFAK_LFB1.DAT"
|
|
|
|
exit
|
|
|
|
#Setup for SQL Server connection
|
|
#SQL Server Name
|
|
$SQLServer = "APPLIK02\SQLEXPRESS"
|
|
#Database Name
|
|
$SQLDBName = "code-test"
|
|
|
|
#Create the SQL Connection Object
|
|
$SQLConn = New-Object System.Data.SQLClient.SQLConnection
|
|
#Create the SQL Command Object, to work with the Database
|
|
$SQLCmd = New-Object System.Data.SQLClient.SQLCommand
|
|
|
|
#Set the connection string one the SQL Connection Object
|
|
$SQLConn.ConnectionString = "Server=$SQLServer;Database=$SQLDBName; Integrated Security=SSPI"
|
|
#Open the connection
|
|
$SQLConn.Open()
|
|
|
|
#Handle the query with SQLCommand Object
|
|
$SQLCmd.CommandText = $query
|
|
#Provide the open connection to the Command Object as a property
|
|
$SQLCmd.Connection = $SQLConn
|
|
|
|
#Execute
|
|
$SQLReturn=$SQLCmd.ExecuteReader()
|
|
|
|
Import-module sqlps
|
|
$tablename = "dbo."+$name
|
|
$database = 'foxdeploy'
|
|
$server = '.'
|
|
$table = 'dbo.powershell_test'
|
|
|
|
Import-CSV .\yourcsv.csv | ForEach-Object {Invoke-Sqlcmd `
|
|
-Database $database -ServerInstance $server `
|
|
-Query "insert into $table VALUES ('$($_.Column1)','$($_.Column2)')"
|
|
}
|
|
|
|
$SQLReturn.Close()
|
|
$SQLConn.Close() |