Advertisement
Guest User

Untitled

a guest
May 24th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. Import-module "sqlps" -DisableNameChecking
  2. $serverInstance = "xxx,1433"
  3. $database = "xxx"
  4. $username = "xxx"
  5. $password = "xxx"
  6. $outputPathFormat = "C:\path_to_store_output\{0}.csv"
  7. $tableNamespaceFormat = "xxx.xxx.{0}"
  8.  
  9. $tableNames = Invoke-Sqlcmd -ServerInstance $serverInstance -Username $username -Password $password -Database $database -Query "SELECT name FROM sys.tables" | Select-Object -ExpandProperty "Name"
  10.  
  11. for ($i=0; $i -lt $tableNames.length; $i++) {
  12.  
  13. $tableName = $tableNames[$i]
  14. $fullTableNamespace =[string]::Format($tableNamespaceFormat,$tableName)
  15. $query = [string]::Format("SELECT * FROM {0}", $fullTableNamespace)
  16. write-host $query
  17. Invoke-SqlCmd -ServerInstance $serverInstance -Username $username -Password $password -Database $database -Query $query | Export-Csv ([string]::Format($outputPathFormat, $fullTableNamespace)) -NoTypeInformation
  18. }
  19.  
  20. Write-Host "Export job completed"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement