Read-SqlXEvent
從 XEL 檔案或即時 SQL XEvent 工作階段讀取 SQL Server XEvent。
語法
Read-SqlXEvent
[-FileName] <String>
[-ProgressAction <ActionPreference>]
[<CommonParameters>]
Read-SqlXEvent
-ConnectionString <String>
-SessionName <String>
[-ProgressAction <ActionPreference>]
[<CommonParameters>]
Description
Read-SqlXEvent 會從檔案或即時 SQL XEvent 會話讀取 SQL Server XEvent。 XEvent 會話是由 CREATE EVENT SESSION Transact-SQL API 所建立。 SQL XEvent 檔案通常具有 。XEL 或 .sqlaudit 延伸模組,並包含 XEvents 的數據流。 XEvents 的結構定義於會話組態中。 SQL 即時串流可透過 SQL TDS 通訊協定取得,而且需要針對產生它們的伺服器進行驗證。
New in v22: if you are using the -ConnectionString parameter, you may get an error like "The certificate chain was issued by an authority that is not trusted." This is because the new SQL driver changed its default to something more secure. Either make sure you configure your server properly, or install/trust the certificate; alternatively (not recommended), you can pass Encrypt=Optional or TrustServerCertificate=true in the connection string to go back to the behavior that existed in v21 of the module.
範例
範例 1:讀取和剖析 sqlaudit 檔案。 每個傳回的物件都會包含單一稽核記錄中的所有資訊。
Read-SqlXEvent -FileName C:\audits\Audit-20190529-132659.sqlaudit
# The output would look like this:
#
# Name : audit_event
# UUID : c6479a6f-f1bd-4759-9881-fcb493821aff
# Timestamp : 6/13/2019 7:49:42 AM +00:00
# Fields : {[audit_schema_version, 1], [event_time, 6/13/2019 7:49:42 AM +00:00], [sequence_number, 1], [action_id,
# 1129534785]...}
# Actions : {}
#
# Name : audit_event
# UUID : c6479a6f-f1bd-4759-9881-fcb493821aff
# Timestamp : 6/13/2019 12:42:28 PM +00:00
# Fields : {[audit_schema_version, 1], [event_time, 6/13/2019 12:42:28 PM +00:00], [sequence_number, 1], [action_id,
# 1129534785]...}
# Actions : {}
# ...
範例 2:從與 Windows 驗證連線的相同電腦上執行的 SQL Server 讀取和剖析 XEvent 的即時串流。 每個傳回的物件都會包含單一 XEvent 記錄中的所有資訊。
Read-SQLXEvent -ConnectionString "Server=.;Database=master;Trusted_Connection=True" -SessionName telemetry_xevents
# The output would look like this:
#
# Name : auto_stats
# UUID : 9237e17a-a73d-4832-8936-f319e19e219b
# Timestamp : 11/14/2022 5:31:12 AM +00:00
# Fields : {[database_id, 1], [object_id, 74], [index_id, 1], [job_id, 0]…}
# Actions : {}
#
# Name : auto_stats
# UUID : 9237e17a-a73d-4832-8936-f319e19e219b
# Timestamp : 11/14/2022 5:31:12 AM +00:00
# Fields : {[database_id, 1], [object_id, 74], [index_id, 17], [job_id, 0]…}
# Actions : {}
# ...
參數
-ConnectionString
SQL Server 連接字串。
類型: | String |
Position: | Named |
預設值: | None |
必要: | True |
接受管線輸入: | False |
接受萬用字元: | False |
-FileName
要讀取之 XEvent 檔案的檔名。
類型: | String |
Position: | 0 |
預設值: | None |
必要: | True |
接受管線輸入: | True |
接受萬用字元: | False |
-ProgressAction
決定 PowerShell 如何回應腳本、Cmdlet 或提供者所產生的進度更新,例如 Write-Progress Cmdlet 所產生的進度列。 Write-Progress Cmdlet 會建立顯示命令狀態的進度列。
類型: | ActionPreference |
別名: | proga |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-SessionName
CREATE EVENT SESSION Transact-SQL 所定義的 SQL Server XEvent 會話名稱。
類型: | String |
Position: | Named |
預設值: | None |
必要: | True |
接受管線輸入: | False |
接受萬用字元: | False |
輸入
System.String
輸出
Microsoft.SqlServer.XEvent.XELite.IXEvent