Skip to content
Permalink
Browse files

More PsRemoting coverage (-UseSSL & -IncludePortInSPN) (#5960)

* New PsRemoting configurations

Add new configurations to use with PsRemoting (Invoke-Command2)

* Make use of new PsRemoting settings

-UseSSL
-IncludePortInSPN

* Support improvements on Invoke-DbaAdvancedInstall & Reset-DbaAdmin

* Fixing splatting

Used $ when should be @
  • Loading branch information...
ClaudioESSilva authored and potatoqualitee committed Aug 14, 2019
1 parent 066c211 commit b3f62361320d7bbeca56aaf39349cafb9d63d9a5
@@ -198,6 +198,7 @@ function Invoke-DbaAdvancedInstall {
$connectionParams = @{
ComputerName = $ComputerName
ErrorAction = "Stop"
UseSSL = (Get-DbatoolsConfigValue -FullName 'PSRemoting.PsSession.UseSSL' -Fallback $false)
}
if ($Credential) { $connectionParams.Credential = $Credential }
# need to figure out where to store the config file
@@ -222,7 +222,12 @@ function Reset-DbaAdmin {
# Setup remote session if server is not local
if (-not $instance.IsLocalHost) {
try {
$session = New-PSSession -ComputerName $hostname -ErrorAction Stop
$connectionParams = @{
ComputerName = $hostname
ErrorAction = "Stop"
UseSSL = (Get-DbatoolsConfigValue -FullName 'PSRemoting.PsSession.UseSSL' -Fallback $false)
}
$session = New-PSSession @connectionParams
} catch {
Stop-Function -Continue -ErrorRecord $_ -Message "Can't access $hostname using PSSession. Check your firewall settings and ensure Remoting is enabled or run the script locally."
}
@@ -2,4 +2,10 @@
Set-DbatoolsConfig -FullName 'PSRemoting.Sessions.ExpirationTimeout' -Value (New-TimeSpan -Minutes 5) -Initialize -Validation timespan -Handler { [Sqlcollaborative.Dbatools.Connection.ConnectionHost]::PSSessionTimeout = $args[0] } -Description 'The timeout interval for PowerShell remote sessions. Dbatools will kill sessions that have been idle for this amount of time.'

# Disables session caching
Set-DbatoolsConfig -FullName 'PSRemoting.Sessions.Enable' -Value $true -Initialize -Validation bool -Handler { [Sqlcollaborative.Dbatools.Connection.ConnectionHost]::PSSessionCacheEnabled = $args[0] } -Description 'Globally enables session caching for PowerShell remoting'
Set-DbatoolsConfig -FullName 'PSRemoting.Sessions.Enable' -Value $true -Initialize -Validation bool -Handler { [Sqlcollaborative.Dbatools.Connection.ConnectionHost]::PSSessionCacheEnabled = $args[0] } -Description 'Globally enables session caching for PowerShell remoting'

# New-PSSessionOption
Set-DbatoolsConfig -FullName 'PSRemoting.PsSessionOption.IncludePortInSPN' -Value $false -Initialize -Validation bool -Description 'Changes the value of -IncludePortInSPN parameter used by New-PsSessionOption which is used for dbatools internally when working with PSRemoting.'

# New-PSSession
Set-DbatoolsConfig -FullName 'PSRemoting.PsSession.UseSSL' -Value $false -Initialize -Validation bool -Description 'Changes the value of -UseSSL parameter used by New-PsSession which is used for dbatools internally when working with PSRemoting.'
@@ -88,10 +88,15 @@ function Invoke-Command2 {
Authentication = $Authentication
Name = $sessionName
ErrorAction = 'Stop'
UseSSL = (Get-DbatoolsConfigValue -FullName 'PSRemoting.PsSession.UseSSL' -Fallback $false)
}
if (Test-Windows -NoWarn) {
$timeout = New-PSSessionOption -IdleTimeout (New-TimeSpan -Minutes 10).TotalMilliSeconds
$psSessionSplat += @{ SessionOption = $timeout }
$psSessionOptionsSplat = @{
IdleTimeout = (New-TimeSpan -Minutes 10).TotalMilliSeconds
IncludePortInSPN = (Get-DbatoolsConfigValue -FullName 'PSRemoting.PsSessionOption.IncludePortInSPN' -Fallback $false)
}
$sessionOption = New-PSSessionOption @psSessionOptionsSplat
$psSessionSplat += @{ SessionOption = $sessionOption }
}
if ($Credential) {
$psSessionSplat += @{ Credential = $Credential }
@@ -134,4 +139,4 @@ function Invoke-Command2 {
$currentSession | Remove-PSSession
}
}
}
}

0 comments on commit b3f6236

Please sign in to comment.
You can’t perform that action at this time.