Windows Authentication will be used if SqlCredential is not specified. SQL Server does not accept Windows credentials being passed as credentials.

To connect as a different Windows user, run PowerShell as that user.

.PARAMETER Spid
Specifies one or more spids to be killed. Options for this parameter are auto-populated from the server.

.PARAMETER Login
Specifies one or more login names whose processes will be killed. Options for this parameter are auto-populated from the server and only login names that have active processes are offered.

.PARAMETER Hostname
Specifies one or more client hostnames whose processes will be killed. Options for this parameter are auto-populated from the server and only hostnames that have active processes are offered.

.PARAMETER Program
Specifies one or more client programs whose processes will be killed. Options for this parameter are auto-populated from the server and only programs that have active processes are offered.

.PARAMETER Database
Specifies one or more databases whose processes will be killed. Options for this parameter are auto-populated from the server and only databases that have active processes are offered.

This parameter is auto-populated from -SqlInstance and allows only database names that have active processes. You can specify one or more Databases whose processes will be killed.

.PARAMETER ExcludeSpid
Specifies one or more spids which will not be killed. Options for this parameter are auto-populated from the server.

Exclude is the last filter to run, so even if a spid matches (for example) Hosts, if it's listed in Exclude it wil be excluded.

.PARAMETER ProcessCollection
This is the process object passed by Get-DbaProcess if using a pipeline.

.PARAMETER WhatIf
If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.

.PARAMETER Confirm
If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.

.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.

#>[CmdletBinding(DefaultParameterSetName="Default",SupportsShouldProcess)]Param([parameter(Mandatory,ParameterSetName="Server")][Alias("ServerInstance","SqlServer")][DbaInstanceParameter]$SqlInstance,[Alias("Credential")][PSCredential]$SqlCredential,[int[]]$Spid,[int[]]$ExcludeSpid,[string[]]$Database,[string[]]$Login,[string[]]$Hostname,[string[]]$Program,[parameter(ValueFromPipeline=$true,Mandatory=$true,ParameterSetName="Process")][object[]]$ProcessCollection,[switch][Alias('Silent')]$EnableException)process{if(Test-FunctionInterrupt){return}if(!$ProcessCollection){$ProcessCollection=Get-DbaProcess@PSBoundParameters}foreach($sessionin$ProcessCollection){$sourceserver=$session.Parentif(!$sourceserver){Stop-Function-Message"Only process objects can be passed through the pipeline."-CategoryInvalidData-Target$sessionreturn}$currentspid=$session.spidif($sourceserver.ConnectionContext.ProcessID-eq$currentspid){Write-Message-LevelWarning-Message"Skipping spid $currentspid because you cannot use KILL to kill your own process."-Target$sessionContinue}if($Pscmdlet.ShouldProcess($sourceserver,"Killing spid $currentspid")){try{$sourceserver.KillProcess($currentspid)[pscustomobject]@{SqlInstance=$sourceserver.nameSpid=$session.SpidLogin=$session.LoginHost=$session.HostDatabase=$session.DatabaseProgram=$session.ProgramStatus='Killed'}}catch{Stop-Function-Message"Couldn't kill spid $currentspid."-Target$session-ErrorRecord$_-Continue}}}}}