共用方式為


Read-SqlXEvent

從 XEL 檔案或即時 SQL XEvent 工作階段讀取 SQL Server XEvent。

語法

ByFile (預設值)

Read-SqlXEvent
    [-FileName] <String>
    [<CommonParameters>]

ByLiveData

Read-SqlXEvent
    -ConnectionString <String>
    -SessionName <String>
    [<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
預設值:None
支援萬用字元:False
不要顯示:False

參數集

ByLiveData
Position:Named
必要:True
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-FileName

要讀取之 XEvent 檔案的檔名。

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False

參數集

ByFile
Position:0
必要:True
來自管線的值:True
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-SessionName

CREATE EVENT SESSION Transact-SQL 所定義的 SQL Server XEvent 會話名稱。

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False

參數集

ByLiveData
Position:Named
必要:True
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

CommonParameters

此 Cmdlet 支援一般參數:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 如需詳細資訊,請參閱 about_CommonParameters

輸入

System.String

輸出

Microsoft.SqlServer.XEvent.XELite.IXEvent