私はすべてのファイルとその属性を特定のディレクトリから再帰的に書き込むpowershellスクリプトを用意しています。これは動作しますが、ディレクトリには1,000,000個ものファイルが存在する可能性があります。私がやりたいことは、トランザクションごとに1000個の挿入をバッチすることです。ここではオリジナルのPSは以下のとおりです。ビルド・インサート文powershell to SQL
$server = ""
$Database = ""
$Path = "C:\Test"
$Connection = New-Object System.Data.SQLClient.SQLConnection
$Connection.ConnectionString = "server='$Server';database='$Database';trusted_connection=true;"
$Connection.Open()
$Command = New-Object System.Data.SQLClient.SQLCommand
$Command.Connection = $Connection
foreach($file in Get-ChildItem -Verbose -Recurse -Path $Path | Select-Object Name,Length,Mode, Directory,CreationTime, LastAccessTime, LastWriteTime) {
$fileName = $file.Name
$fileSize = ([int]$file.Length)
$fileMode = $file.Mode
$fileDirectory = $file.Directory
$fileCreationTime = [datetime]$file.CreationTime
$fileLastAccessTime = [datetime]$file.LastAccessTime
$fileLastWriteTime = [datetime]$file.LastWriteTime
$sql = "
begin
insert TestPowerShell
select '$fileName', '$fileSize', '$fileMode', '$fileDirectory', '$fileCreationTime', '$fileLastAccessTime', '$fileLastWriteTime'
end
"
$Command.CommandText = $sql
echo $sql
$Command.ExecuteNonQuery()
}
$Connection.Close()
私の考えは、ループの外にジャンプし、実行し、それが1000に到達するまでのインサートを追加しておくとしますカウンターのいくつかの並べ替えを実装することです。私はこの現在のセットアップで、1000でバッチを実行する方法を知ることができず、get-childitemループを実行してから実行します。興味がある人々のために
これは私が私を使用して終了するものに非常に近いですこれを答えとして選択します。ありがとう! – VinnyGuitara