<commit_before>function Export-DbaUser {
	<#
		.SYNOPSIS
			Exports users creation and its permissions to a T-SQL file or host.

		.DESCRIPTION
			Exports users creation and its permissions to a T-SQL file or host. Export includes user, create and add to role(s), database level permissions, object level permissions.

		.PARAMETER SqlInstance
			The SQL Server instance name. SQL Server 2000 and above supported.

		.PARAMETER SqlCredential
			Allows you to login to servers using alternative credentials

			$scred = Get-Credential, then pass $scred object to the -SqlCredential parameter

			Windows Authentication will be used if SqlCredential is not specified

		.PARAMETER Database
			The database(s) to process - this list is auto-populated from the server. If unspecified, all databases will be processed.

		.PARAMETER ExcludeDatabase
			The database(s) to exclude - this list is auto-populated from the server

		.PARAMETER User
			Export only the specified database user(s). If not specified will export all users from the database(s)

		.PARAMETER DestinationVersion
			To say to which version the script should be generated. If not specified will use database compatibility level

		.PARAMETER FilePath
			The file to write to.

		.PARAMETER NoClobber
			Do not overwrite file

		.PARAMETER Append
			Append to file

		.PARAMETER WhatIf
			Shows what would happen if the command were to run. No actions are actually performed.

		.PARAMETER Confirm
			Prompts you for confirmation before executing any changing operations within the command.

		.PARAMETER EnableException
			By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
			This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
			Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

		.PARAMETER ScriptingOptions
			A Microsoft.SqlServer.Management.Smo.ScriptingOptions object with the options that you want to use to generate the t-sql script.
			You can use the NEw-DbaScriptingOption to generate it.

		.NOTES
			Tags: User, Export
			Author: <NAME> (@ClaudioESSilva)

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

		.LINK
			https://dbatools.io/Export-DbaUser

		.EXAMPLE
			Export-DbaUser -SqlInstance sql2005 -FilePath C:\temp\sql2005-users.sql

			Exports SQL for the users in server "sql2005" and writes them to the file "C:\temp\sql2005-users.sql"

		.EXAMPLE
			Export-DbaUser -SqlInstance sqlserver2014a $scred -FilePath C:\temp\users.sql -Append

			Authenticates to sqlserver2014a using SQL Authentication. Exports all users to C:\temp\users.sql, and appends to the file if it exists. If not, the file will be created.

		.EXAMPLE
			Export-DbaUser -SqlInstance sqlserver2014a -User User1, User2 -FilePath C:\temp\users.sql

			Exports ONLY users User1 and User2 fron sqlsever2014a to the file  C:\temp\users.sql

		.EXAMPLE
			Export-DbaUser -SqlInstance sqlserver2008 -User User1 -FilePath C:\temp\users.sql -DestinationVersion SQLServer2016

			Exports user User1 fron sqlsever2008 to the file C:\temp\users.sql with sintax to run on SQL Server 2016

		.EXAMPLE
			Export-DbaUser -SqlInstance sqlserver2008 -Database db1,db2 -FilePath C:\temp\users.sql

			Exports ONLY users from db1 and db2 database on sqlserver2008 server, to the C:\temp\users.sql file.

		.EXAMPLE
			$options = New-DbaScriptingOption
			$options.ScriptDrops = $false
			$options.WithDependencies = $true

			Export-DbaUser -SqlInstance sqlserver2008 -Database db1,db2 -FilePath C:\temp\users.sql -ScriptingOptionsObject $options

			Exports ONLY users from db1 and db2 database on sqlserver2008 server, to the C:\temp\users.sql file.
			It will not script drops but will script dependencies.

	#>
	[CmdletBinding(DefaultParameterSetName = "Default")]
	[OutputType([String])]
	param (
		[parameter(Mandatory = $true, ValueFromPipeline = $true)]
		[Alias("ServerInstance", "SqlServer")]
		[DbaInstanceParameter]$SqlInstance,
		[Alias("Credential")]
		[PSCredential]
		$SqlCredential,
		[Alias("Databases")]
		[object[]]$Database,
		[object[]]$ExcludeDatabase,
		[object[]]$User,
		[ValidateSet('SQLServer2000', 'SQLServer2005', 'SQLServer2008/2008R2', 'SQLServer2012', 'SQLServer2014', 'SQLServer2016')]
		[string]$DestinationVersion,
		[Alias("OutFile", "Path", "FileName")]
		[string]$FilePath,
		[Alias("NoOverwrite")]
		[switch]$NoClobber,
		[switch]$Append,
		[switch][Alias('Silent')]$EnableException,
		[Microsoft.SqlServer.Management.Smo.ScriptingOptions]$ScriptingOptionsObject = $null
	)

	begin {
		if ($FilePath) {
			if ($FilePath -notlike "*\*") { $FilePath = ".\$filepath" }
			$directory = Split-Path $FilePath
			$exists = Test-Path $directory

			if ($exists -eq $false) {
				Stop-Function -Message "Parent directory $directory does not exist"
				return
			}

			Write-Message -Level Output -Message "Attempting to connect to SQL Servers.."
		}

		$outsql = @()

		$versions = @{
			'SQLServer2000'        = 'Version80'
			'SQLServer2005'        = 'Version90'
			'SQLServer2008/2008R2' = 'Version100'
			'SQLServer2012'        = 'Version110'
			'SQLServer2014'        = 'Version120'
			'SQLServer2016'        = 'Version130'
		}

		$versionName = @{
			'Version80'  = 'SQLServer2000'
			'Version90'  = 'SQLServer2005'
			'Version100' = 'SQLServer2008/2008R2'
			'Version110' = 'SQLServer2012'
			'Version120' = 'SQLServer2014'
			'Version130' = 'SQLServer2016'
		}

	}
	process {
		if (Test-FunctionInterrupt) { return }

		try {
			Write-Message -Level Verbose -Message "Connecting to $sqlinstance"
			$server = Connect-SqlInstance -SqlInstance $SqlInstance -SqlCredential $sqlcredential
		}
		catch {
			Stop-Function -Message "Failure" -Category ConnectionError -ErrorRecord $_ -Target $instance -Continue
		}
<commit_msg>Add support for SQL Server 2017<commit_after>function Export-DbaUser {
	<#
		.SYNOPSIS
			Exports users creation and its permissions to a T-SQL file or host.

		.DESCRIPTION
			Exports users creation and its permissions to a T-SQL file or host. Export includes user, create and add to role(s), database level permissions, object level permissions.

		.PARAMETER SqlInstance
			The SQL Server instance name. SQL Server 2000 and above supported.

		.PARAMETER SqlCredential
			Allows you to login to servers using alternative credentials

			$scred = Get-Credential, then pass $scred object to the -SqlCredential parameter

			Windows Authentication will be used if SqlCredential is not specified

		.PARAMETER Database
			The database(s) to process - this list is auto-populated from the server. If unspecified, all databases will be processed.

		.PARAMETER ExcludeDatabase
			The database(s) to exclude - this list is auto-populated from the server

		.PARAMETER User
			Export only the specified database user(s). If not specified will export all users from the database(s)

		.PARAMETER DestinationVersion
			To say to which version the script should be generated. If not specified will use database compatibility level

		.PARAMETER FilePath
			The file to write to.

		.PARAMETER NoClobber
			Do not overwrite file

		.PARAMETER Append
			Append to file

		.PARAMETER WhatIf
			Shows what would happen if the command were to run. No actions are actually performed.

		.PARAMETER Confirm
			Prompts you for confirmation before executing any changing operations within the command.

		.PARAMETER EnableException
			By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
			This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
			Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

		.PARAMETER ScriptingOptions
			A Microsoft.SqlServer.Management.Smo.ScriptingOptions object with the options that you want to use to generate the t-sql script.
			You can use the NEw-DbaScriptingOption to generate it.

		.NOTES
			Tags: User, Export
			Author: <NAME> (@ClaudioESSilva)

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

		.LINK
			https://dbatools.io/Export-DbaUser

		.EXAMPLE
			Export-DbaUser -SqlInstance sql2005 -FilePath C:\temp\sql2005-users.sql

			Exports SQL for the users in server "sql2005" and writes them to the file "C:\temp\sql2005-users.sql"

		.EXAMPLE
			Export-DbaUser -SqlInstance sqlserver2014a $scred -FilePath C:\temp\users.sql -Append

			Authenticates to sqlserver2014a using SQL Authentication. Exports all users to C:\temp\users.sql, and appends to the file if it exists. If not, the file will be created.

		.EXAMPLE
			Export-DbaUser -SqlInstance sqlserver2014a -User User1, User2 -FilePath C:\temp\users.sql

			Exports ONLY users User1 and User2 fron sqlsever2014a to the file  C:\temp\users.sql

		.EXAMPLE
			Export-DbaUser -SqlInstance sqlserver2008 -User User1 -FilePath C:\temp\users.sql -DestinationVersion SQLServer2016

			Exports user User1 fron sqlsever2008 to the file C:\temp\users.sql with sintax to run on SQL Server 2016

		.EXAMPLE
			Export-DbaUser -SqlInstance sqlserver2008 -Database db1,db2 -FilePath C:\temp\users.sql

			Exports ONLY users from db1 and db2 database on sqlserver2008 server, to the C:\temp\users.sql file.

		.EXAMPLE
			$options = New-DbaScriptingOption
			$options.ScriptDrops = $false
			$options.WithDependencies = $true

			Export-DbaUser -SqlInstance sqlserver2008 -Database db1,db2 -FilePath C:\temp\users.sql -ScriptingOptionsObject $options

			Exports ONLY users from db1 and db2 database on sqlserver2008 server, to the C:\temp\users.sql file.
			It will not script drops but will script dependencies.

	#>
	[CmdletBinding(DefaultParameterSetName = "Default")]
	[OutputType([String])]
	param (
		[parameter(Mandatory = $true, ValueFromPipeline = $true)]
		[Alias("ServerInstance", "SqlServer")]
		[DbaInstanceParameter]$SqlInstance,
		[Alias("Credential")]
		[PSCredential]
		$SqlCredential,
		[Alias("Databases")]
		[object[]]$Database,
		[object[]]$ExcludeDatabase,
		[object[]]$User,
		[ValidateSet('SQLServer2000', 'SQLServer2005', 'SQLServer2008/2008R2', 'SQLServer2012', 'SQLServer2014', 'SQLServer2016', 'SQLServer2017')]
		[string]$DestinationVersion,
		[Alias("OutFile", "Path", "FileName")]
		[string]$FilePath,
		[Alias("NoOverwrite")]
		[switch]$NoClobber,
		[switch]$Append,
		[switch][Alias('Silent')]$EnableException,
		[Microsoft.SqlServer.Management.Smo.ScriptingOptions]$ScriptingOptionsObject = $null
	)

	begin {
		if ($FilePath) {
			if ($FilePath -notlike "*\*") { $FilePath = ".\$filepath" }
			$directory = Split-Path $FilePath
			$exists = Test-Path $directory

			if ($exists -eq $false) {
				Stop-Function -Message "Parent directory $directory does not exist"
				return
			}

			Write-Message -Level Output -Message "Attempting to connect to SQL Servers.."
		}

		$outsql = @()

		$versions = @{
			'SQLServer2000'        = 'Version80'
			'SQLServer2005'        = 'Version90'
			'SQLServer2008/2008R2' = 'Version100'
			'SQLServer2012'        = 'Version110'
			'SQLServer2014'        = 'Version120'
			'SQLServer2016'        = 'Version130'
			'SQLServer2017'        = 'Version140'
		}

		$versionName = @{
			'Version80'  = 'SQLServer2000'
			'Version90'  = 'SQLServer2005'
			'Version100' = 'SQLServer2008/2008R2'
			'Version110' = 'SQLServer2012'
			'Version120' = 'SQLServer2014'
			'Version130' = 'SQLServer2016'
			'Version140' = 'SQLServer2017'
		}

	}
	process {
		if (Test-FunctionInterrupt) { return }

		try {
			Write-Message -Level Verbose -Message "Connecting to $sqlinstance"
			$server = Connect-SqlInstance -SqlInstance $SqlInstance -SqlCredential $sqlcredential
		}
		catch {
			Stop-Function -Message "Failure" -Category ConnectionError -ErrorRecord $_ -Target $instance -Continue
		}

{'fraction_non_alphanumeric': 0.09026973357603839, 'fraction_numerical': 0.03557835512162833, 'mean_word_length': 3.8542168674698796, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '4638109', 'n_tokens_mistral': 4297, 'n_tokens_neox': 3541, 'n_words': 1220}