Export SQL Query to Excel

I have audits running on SQL Server 2012. Its auditing various database and server level features. usually am retrieving data using below query. 

SELECT * FROM sys.fn_get_audit_file ('H:\test-audit\sqldbahub_49D408A8-A8BF-425D-97E9-A662FF47F749_0_132690921762220000.sqlaudit',default,default)        

To avoid manual intervention and retrieve data remotely using PowerShell. And even you can export data to CSV file.

You could easily export that out to a file with a single PowerShell command as well: 

Invoke-sqlcmd -Query "SELECT * FROM sys.fn_get_audit_file ('H:\test-audit\banu_49D408A8-A8BF-425D-97E9-A662FF47F749_0_132690921762220000.sqlaudit',default,default)" | export-csv "H:\test-audit\HIPPAAudit.csv"

No comments:

Post a Comment

Popular Posts