PowerShell export data to file
This example PowerShell script exports data from SQL table into files and then zip them together.
Clear-Host function ExportDataToFile { param( [string]$instancename, [string]$dbname, [string]$flowname, [string]$clientname, [string]$filepath ) $guid = @() $guid_replace = @() if ([string]::IsNullOrEmpty($filepath)) { throw "filepath is rquired but not specified!" } if ($filepath -match "\\$") { $filepath = $filepath.Substring(0,$filepath.Length-1) } #connection to SQL $SqlConnection = New-Object System.Data.SqlClient.SqlConnection $SqlConnection.ConnectionString = "Server=" + $instancename + ";Database=" + $dbname + ";Integrated Security=True" $SqlCmd = New-Object System.
Posted by John Liu Saturday, July 1, 2023