Last active
January 30, 2017 16:14
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
#一定時間間隔で起動 | |
while(1){ | |
#終了時は、[Ctrl + C] を押す | |
Write-Host "End to [Ctrl + C]" | |
#Connect to the SQL database | |
$SQLserver = "0.0.0.0" -- SQL server name | |
$Icatalog = "TEST" -- Database name | |
$UID = "UID" | |
$PASSWORD = "PASSWORD" | |
$conn = New-Object System.Data.SqlClient.SqlConnection | |
$conn.ConnectionString = "Server = $SQLserver; Database = $Icatalog; User ID = $UID; Password= $PASSWORD;" | |
$Conn.Open() | |
$Command = New-Object System.Data.SQLClient.SQLCommand | |
$Command.Connection = $Conn | |
#FTPで受信するフォルダPathの設定 | |
$filepath = "C:\inetpub\ftproot\test" | |
#フォルダ内の全てのXMLファイルをリスト化 | |
$filelist = Get-ChildItem -name $filepath\*.xml | |
#リストの上から順番にLoad | |
foreach ($filename in $filelist){ | |
$fileinput = Get-Content $filepath\$filename | |
echo "Loading $filename" | |
$output | foreach { | |
$Command.CommandText = "INSERT INTO dbo.Logxml(logxml,filename,creation_date) SELECT CONVERT(XML, BulkColumn) AS BulkColumn,'$filename',getdate() FROM OPENROWSET(BULK '$filepath\$filename', SINGLE_BLOB) AS X" | |
$Command.ExecuteNonQuery() | out-null | |
} | |
#アーカイブフォルダーへファイルの移動 | |
Move-Item $filepath\$filename $filepath\archive | |
} | |
$Conn.Close() | |
#60秒待機 | |
Start-Sleep -Seconds 60 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment