<commit_before>function Get-DbaXEventsSession {
 <#
	.SYNOPSIS
	Get a list of Extended Events Sessions

	.DESCRIPTION
	Retrieves a list of Extended Events Sessions

	.PARAMETER SqlInstance
	The SQL Instances that you're connecting to.

	.PARAMETER SqlCredential
	Credential object used to connect to the SQL Server as a different user

	.PARAMETER Session
	Only return specific sessions. This parameter is auto-populated.
		
	.PARAMETER Silent
	If this switch is enabled, the internal messaging functions will be silenced.

	.NOTES
	Tags: Memory
	Author: <NAME> ( @PowerDBAKlaas )
	Website: https://dbatools.io
	Copyright: (C) <NAME>, <EMAIL>
	License: GNU GPL v3 https://opensource.org/licenses/GPL-3.0

	.LINK
	https://dbatools.io/Get-DbaXEventsSession

	.EXAMPLE
	Get-DbaXEventsSession -SqlInstance ServerA\sql987

	Returns a custom object with ComputerName, SQLInstance, Session, StartTime, Status and other properties.

	.EXAMPLE
	Get-DbaXEventsSession -SqlInstance ServerA\sql987 | Format-Table ComputerName, SqlInstance, Session, Status -AutoSize

	Returns a formatted table displaying ComputerName, SqlInstance, Session, and Status.

	.EXAMPLE
	'ServerA\sql987','ServerB' | Get-DbaXEventsSession

	Returns a custom object with ComputerName, SqlInstance, Session, StartTime, Status and other properties, from multiple SQL Instances.

#>
	[CmdletBinding()]
	param (
		[parameter(Mandatory = $true, ValueFromPipeline = $true)]
		[Alias("ServerInstance", "SqlServer")]
		[DbaInstanceParameter[]]$SqlInstance,
		[PSCredential]$SqlCredential,
		[Alias("Sessions")]
		[object[]]$Session,
		[switch]$Silent
	)
	
	begin {
		if ([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Management.XEvent") -eq $null) {
			Stop-Function -Message "SMO version is too old. To collect Extended Events, you must have SQL Server Management Studio 2012 or higher installed."
		}
	}
	
	process {
		if (Test-FunctionInterrupt) { return }
		
		foreach ($instance in $SqlInstance) {
			try {
				Write-Message -Level Verbose -Message "Connecting to $instance"
				$server = Connect-SqlInstance -SqlInstance $instance -SqlCredential $SqlCredential -MinimumVersion 11
			}
			catch {
				Stop-Function -Message "Failure" -Category ConnectionError -ErrorRecord $_ -Target $instance -Continue
			}
			
			$SqlConn = $server.ConnectionContext.SqlConnectionObject
			$SqlStoreConnection = New-Object Microsoft.SqlServer.Management.Sdk.Sfc.SqlStoreConnection $SqlConn
			$XEStore = New-Object  Microsoft.SqlServer.Management.XEvent.XEStore $SqlStoreConnection
			Write-Message -Level Verbose -Message "Getting XEvents Sessions on $instance."
			
			$xesessions = $XEStore.sessions
			
			if ($Session) {
				$xesessions = $xesessions | Where-Object { $_.Name -in $Session }
			}
			
			foreach ($x in $xesessions) {
				$status = switch ($x.IsRunning) { $true { "Running" } $false { "Stopped" } }
				$files = $x.Targets.TargetFields | Where-Object Name -eq Filename | select -ExpandProperty Value
				Add-Member -Force -InputObject $x -MemberType NoteProperty -Name ComputerName -Value $server.NetName
				Add-Member -Force -InputObject $x -MemberType NoteProperty -Name InstanceName -Value $server.ServiceName
				Add-Member -Force -InputObject $x -MemberType NoteProperty -Name SqlInstance -Value $server.DomainInstanceName
				Add-Member -Force -InputObject $x -MemberType NoteProperty -Name Status -Value $status
				Add-Member -Force -InputObject $x -MemberType NoteProperty -Name Session -Value $x.Name
				Add-Member -Force -InputObject $x -MemberType NoteProperty -Name TargetFiles -Value $files
				
				Select-DefaultView -InputObject $x -Property ComputerName, InstanceName, SqlInstance, Name, Status, StartTime, AutoStart, State, Targets, TargetFiles, Events, MaxMemory, MaxEventSize
			}
		}
	}
}<commit_msg>updating command to support remote files<commit_after>function Get-DbaXEventsSession {
 <#
	.SYNOPSIS
	Get a list of Extended Events Sessions

	.DESCRIPTION
	Retrieves a list of Extended Events Sessions

	.PARAMETER SqlInstance
	The SQL Instances that you're connecting to.

	.PARAMETER SqlCredential
	Credential object used to connect to the SQL Server as a different user

	.PARAMETER Session
	Only return specific sessions. This parameter is auto-populated.
		
	.PARAMETER Silent
	If this switch is enabled, the internal messaging functions will be silenced.

	.NOTES
	Tags: Memory
	Author: <NAME> ( @PowerDBAKlaas )
	Website: https://dbatools.io
	Copyright: (C) <NAME>, <EMAIL>
	License: GNU GPL v3 https://opensource.org/licenses/GPL-3.0

	.LINK
	https://dbatools.io/Get-DbaXEventsSession

	.EXAMPLE
	Get-DbaXEventsSession -SqlInstance ServerA\sql987

	Returns a custom object with ComputerName, SQLInstance, Session, StartTime, Status and other properties.

	.EXAMPLE
	Get-DbaXEventsSession -SqlInstance ServerA\sql987 | Format-Table ComputerName, SqlInstance, Session, Status -AutoSize

	Returns a formatted table displaying ComputerName, SqlInstance, Session, and Status.

	.EXAMPLE
	'ServerA\sql987','ServerB' | Get-DbaXEventsSession

	Returns a custom object with ComputerName, SqlInstance, Session, StartTime, Status and other properties, from multiple SQL Instances.

#>
	[CmdletBinding()]
	param (
		[parameter(Mandatory = $true, ValueFromPipeline = $true)]
		[Alias("ServerInstance", "SqlServer")]
		[DbaInstanceParameter[]]$SqlInstance,
		[PSCredential]$SqlCredential,
		[Alias("Sessions")]
		[object[]]$Session,
		[switch]$Silent
	)
	
	begin {
		if ([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Management.XEvent") -eq $null) {
			Stop-Function -Message "SMO version is too old. To collect Extended Events, you must have SQL Server Management Studio 2012 or higher installed."
		}
	}
	
	process {
		if (Test-FunctionInterrupt) { return }
		
		foreach ($instance in $SqlInstance) {
			try {
				Write-Message -Level Verbose -Message "Connecting to $instance"
				$server = Connect-SqlInstance -SqlInstance $instance -SqlCredential $SqlCredential -MinimumVersion 11
			}
			catch {
				Stop-Function -Message "Failure" -Category ConnectionError -ErrorRecord $_ -Target $instance -Continue
			}
			
			$SqlConn = $server.ConnectionContext.SqlConnectionObject
			$SqlStoreConnection = New-Object Microsoft.SqlServer.Management.Sdk.Sfc.SqlStoreConnection $SqlConn
			$XEStore = New-Object  Microsoft.SqlServer.Management.XEvent.XEStore $SqlStoreConnection
			Write-Message -Level Verbose -Message "Getting XEvents Sessions on $instance."
			
			$xesessions = $XEStore.sessions
			
			if ($Session) {
				$xesessions = $xesessions | Where-Object { $_.Name -in $Session }
			}
			
			foreach ($x in $xesessions) {
				$status = switch ($x.IsRunning) { $true { "Running" } $false { "Stopped" } }
				$file = $x.Targets.TargetFields | Where-Object Name -eq Filename | Select-Object -ExpandProperty Value
				$remotefile = Join-AdminUnc -servername $server.netName -filepath $file
				
				<#
				$remotefiles = @()
				foreach ($file in $files) {
					$tempfile = Join-AdminUnc -servername $server.netName -filepath $file
					$remotefiles += $tempfile
				}
				#>
				
				Add-Member -Force -InputObject $x -MemberType NoteProperty -Name ComputerName -Value $server.NetName
				Add-Member -Force -InputObject $x -MemberType NoteProperty -Name InstanceName -Value $server.ServiceName
				Add-Member -Force -InputObject $x -MemberType NoteProperty -Name SqlInstance -Value $server.DomainInstanceName
				Add-Member -Force -InputObject $x -MemberType NoteProperty -Name Status -Value $status
				Add-Member -Force -InputObject $x -MemberType NoteProperty -Name Session -Value $x.Name
				Add-Member -Force -InputObject $x -MemberType NoteProperty -Name TargetFile -Value $file
				Add-Member -Force -InputObject $x -MemberType NoteProperty -Name RemoteTargetFile -Value $remotefile
				
				Select-DefaultView -InputObject $x -Property ComputerName, InstanceName, SqlInstance, Name, Status, StartTime, AutoStart, State, Targets, TargetFile, Events, MaxMemory, MaxEventSize
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.0968384366442619, 'fraction_numerical': 0.004480955937266617, 'mean_word_length': 4.127632418634333, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2119179', 'n_tokens_mistral': 2665, 'n_tokens_neox': 2348, 'n_words': 718}