8000 Create the default PSSession configuration, not tied to a specific PowerShell version. by kalgiz · Pull Request #6519 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Create the default PSSession configuration, not tied to a specific PowerShell version. #6519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 44 commits into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
2945dcd
[Feature] Create the default PSSession configuration, not tied to a s…
kalgiz Mar 27, 2018
f63fa87
[Feature] Tests for Enable-PSRemoting
kalgiz Mar 28, 2018
1cc6d32
[Feature] Enable-PSRemoiting command fix.
kalgiz Mar 28, 2018
b200048
[Feature] Enable-PSRemoting, dealing with corner case added.
kalgiz Mar 28, 2018
969f611
[Feature] Remoting tests correction
kalgiz Mar 28, 2018
0701ed2
[Feature] Install-PowerShellRemoting script adds the configuration na…
kalgiz Mar 28, 2018
e73c156
Merge branch 'master' of https://github.com/kalgiz/PowerShell into re…
kalgiz Mar 28, 2018
d545c92
[Feature]
kalgiz Mar 28, 2018
f280922
[Feature] Correcting tests for non Windows platforms.
kalgiz Mar 28, 2018
6beafc0
commit
kalgiz Mar 28, 2018
0f375d2
Merge branch 'master' of https://github.com/PowerShell/PowerShell int…
kalgiz Mar 28, 2018
67a8772
[Feature] Not overwriting existing session by command Enable-PSRemoting.
kalgiz Mar 29, 2018
a30542d
[Feature] Enable-PSRemoting command correction.
kalgiz Mar 29, 2018
a9da476
Merge branch 'master' of https://github.com/kalgiz/PowerShell into re…
kalgiz Mar 29, 2018
cb19b50
Merge branch 'master' of https://github.com/PowerShell/PowerShell
kalgiz Mar 29, 2018
3c0fa49
Merge branch 'master' of https://github.com/kalgiz/PowerShell
kalgiz Mar 30, 2018
3fcb173
Merge branch 'master' of https://github.com/kalgiz/PowerShell into re…
kalgiz Mar 30, 2018
d9782a3
[Feature] Comments for endpoints' name clarifications added.
kalgiz Mar 30, 2018
4a8b4c5
Merge branch 'master' of https://github.com/PowerShell/PowerShell
kalgiz Apr 2, 2018
9d81797
Merge branch 'master' of https://github.com/kalgiz/PowerShell
kalgiz Apr 2, 2018
9dfa552
Merge branch 'master' of https://github.com/PowerShell/PowerShell
kalgiz Apr 3, 2018
95474a0
Merge branch 'master' of https://github.com/kalgiz/PowerShell into re…
kalgiz Apr 3, 2018
1836dca
Code fixes.
kalgiz Apr 4, 2018
7b2af9f
Set-StrictoMode Latest added to the psremoting scripts.
kalgiz Apr 4, 2018
4247332
Merge branch 'master' of https://github.com/PowerShell/PowerShell
kalgiz Apr 4, 2018
412ca3a
Merge branch 'master' of https://github.com/kalgiz/PowerShell
kalgiz Apr 4, 2018
f4a9ade
and ShouldProcess in Intall-PowerShellRemoting script.
kalgiz Apr 4, 2018
dd00e2c
Enable-PSRemoting corrections after running SA.
kalgiz Apr 4, 2018
ba55e12
-ErrorAction Stop in Install-PowerShellRemoting module.
kalgiz Apr 4, 2018
7c4560b
-ErrorAction Stop used for commands in Enable-PSRemoting definition.
kalgiz Apr 4, 2018
21fd7ae
check for administrator rights moved to the beginning of the script.
kalgiz Apr 4, 2018
5f3a58a
Merge branch 'master' of https://github.com/PowerShell/PowerShell
kalgiz Apr 5, 2018
701e6ff
Merge branch 'master' of https://github.com/kalgiz/PowerShell into re…
kalgiz Apr 5, 2018
40f98ff
Merge branch 'master' of https://github.com/PowerShell/PowerShell
kalgiz Apr 6, 2018
1d6e199
Merge branch 'master' of https://github.com/kalgiz/PowerShell into re…
kalgiz Apr 6, 2018
b8517e7
[Feature] Write-Error if Install-PowerShellRemoting is called without…
kalgiz Apr 6, 2018
e0f15c4
Merge branch 'master' of https://github.com/kalgiz/PowerShell into re…
kalgiz Apr 6, 2018
26046c5
Merge branch 'remoting-conf-name' of https://github.com/kalgiz/PowerS…
kalgiz Apr 9, 2018
f7b0127
Correcting erorr appearing because of the Strict Mode
kalgiz Apr 9, 2018
479a2dc
[Feature] Write-Error with -Category and -ErrorId parameters.
kalgiz Apr 9, 2018
0c74b16
[Feature] Remove check of the value of non assigned variable.
kalgiz Apr 9, 2018
9aa27fb
Merge branch 'master' of https://github.com/PowerShell/PowerShell
kalgiz Apr 9, 2018
aede937
Merge branch 'master' of https://github.com/kalgiz/PowerShell
kalgiz Apr 9, 2018
f01b4ca
Merge branch 'master' of https://github.com/kalgiz/PowerShell into re…
kalgiz Apr 9, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,13 @@ function Register-PSSessionConfiguration
}}
}}
if (([System.Management.Automation.Runspaces.PSSessionConfigurationAccessMode]::Local.Equals($accessMode) -or
([System.Management.Automation.Runspaces.PSSessionConfigurationAccessMode]::Remote.Equals($accessMode)-and $disableNetworkExists)) -and
!$haveDisableACE)
([System.Management.Automation.Runspaces.PSSessionConfigurationAccessMode]::Remote.Equals($accessMode))) -and !$haveDisableACE)
{{
# Add network deny ACE for local access or remote access with PSRemoting disabled ($disableNetworkExists)
# Add network deny ACE for local access or remote access with PSRemoting disabled.
$sd.DiscretionaryAcl.AddAccess("&qu 8000 ot;deny"", $networkSID, 268435456, ""None"", ""None"")
$newSDDL = $sd.GetSddlForm(""all"")
}}
if ([System.Management.Automation.Runspaces.PSSessionConfigurationAccessMode]::Remote.Equals($accessMode) -and -not $disableNetworkExists -and $haveDisableACE)
if ([System.Management.Automation.Runspaces.PSSessionConfigurationAccessMode]::Remote.Equals($accessMode) -and $haveDisableACE)
{{
# Remove the specific ACE
$sd.discretionaryacl.RemoveAccessSpecific('Deny', $securityIdentifierToPurge, 268435456, 'none', 'none')
Expand Down Expand Up @@ -4796,16 +4795,119 @@ public sealed class EnablePSRemotingCommand : PSCmdlet

//TODO: CLR4: Remove the logic for setting the MaxMemoryPerShellMB to 200 MB once IPMO->Get-Command->Get-Help memory usage issue is fixed.
private const string enableRemotingSbFormat = @"
function Generate-PluginConfigFile
Set-StrictMode -Version Latest

function New-PluginConfigFile
{{
[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact=""Medium"")]
param(
[Parameter()] [string] $pluginInstallPath
)
$pluginConfigFile = Join-Path $pluginInstallPath ""RemotePowerShellConfig.txt""

# This always overwrites the file with a new version of it (if it already exists)
Set-Content -Path $pluginConfigFile -Value ""PSHOMEDIR=$PSHOME""
Add-Content -Path $pluginConfigFile -Value ""CORECLRDIR=$PSHOME""
Set-Content -Path $pluginConfigFile -Value ""PSHOMEDIR=$PSHOME"" -ErrorAction Stop
Add-Content -Path $pluginConfigFile -Value ""CORECLRDIR=$PSHOME"" -ErrorAction Stop
}}

function Copy-PluginToEndpoint
{{
param(
[Parameter()] [string] $endpointDir
)
$resolvedPluginInstallPath = """"
$pluginInstallPath = Join-Path ([System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::Windows) + ""\System32\PowerShell"") $endpointDir
if (!(Test-Path $pluginInstallPath))
{{
$resolvedPluginInstallPath = New-Item -Type Directory -Path $pluginInstallPath
}}
else
{{
$resolvedPluginInstallPath = Resolve-Path $pluginInstallPath
}}
if (!(Test-Path $resolvedPluginInstallPath\{5}))
{{
Copy-Item -Path $PSHOME\{5} -Destination $resolvedPluginInstallPath -Force -ErrorAction Stop
if (!(Test-Path $resolvedPlu 8000 ginInstallPath\{5}))
{{
Write-Error ($errorMsgUnableToInstallPlugin -f ""{5}"", $resolvedPluginInstallPath)
return $null
}}
}}
return $resolvedPluginInstallPath
}}

function Register-Endpoint
{{
param(
[Parameter()] [string] $configurationName
)
#
# Section 1:
# Move pwrshplugin.dll from $PSHOME to the endpoint directory
#
# The plugin directory pattern for endpoint configuration is:
# '$env:WINDIR\System32\PowerShell\' + powershell_version,
# so we call Copy-PluginToEndpoint function only with the PowerShell version argument.

$pwshVersion = $configurationName.Replace(""PowerShell."", """")
$resolvedPluginInstallPath = Copy-PluginToEndpoint $pwshVersion
if (!$resolvedPluginInstallPath) {{
return
}}

#
# Section 2:
# Generate the Plugin Configuration File
#
New-PluginConfigFile $resolvedPluginInstallPath

#
# Section 3:
# Register the endpoint
#
$null = Register-PSSessionConfiguration -Name $configurationName -force -ErrorAction Stop

set-item -WarningAction SilentlyContinue wsman:\localhost\plugin\$configurationName\Quotas\MaxShellsPerUser -value ""25"" -confirm:$false
set-item -WarningAction SilentlyContinue wsman:\localhost\plugin\$configurationName\Quotas\MaxIdleTimeoutms -value {4} -confirm:$false
restart-service winrm -confirm:$false
}}

function Register-EndpointIfNotPresent
{{
[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact=""Medium"")]
param(
[Parameter()] [string] $Name,
[Parameter()] [bool] $Force,
[Parameter()] [string] $queryForRegisterDefault,
[Parameter()] [string] $captionForRegisterDefault
)
#
# This cmdlet will make sure default powershell end points exist upon successful completion.
#
# Windows PowerShell:
# Microsoft.PowerShell
# Microsoft.PowerShell32 (wow64)
#
# PowerShell Core:
# PowerShell.<version ID>
#
$errorCount = $error.Count
$endPoint = Get-PSSessionConfiguration $Name -Force:$Force -ErrorAction silentlycontinue 2>&1
$newErrorCount = $error.Count

# remove the 'No Session Configuration matches criteria' errors
for ($index = 0; $index -lt ($newErrorCount - $errorCount); $index ++)
{{
$error.RemoveAt(0)
}}

$qMessage = $queryForRegisterDefault -f ""$Name"",""Register-PSSessionConfiguration {0} -force""
if ((!$endpoint) -and
($force -or $pscmdlet.ShouldProcess($qMessage, $captionForRegisterDefault)))
{{
Register-Endpoint $Name
}}
}}

function Enable-PSRemoting
Expand Down Expand Up @@ -4836,70 +4938,16 @@ function Enable-PSRemoting
# first try to enable all the sessions
Enable-PSSessionConfiguration @PSBoundParameters

#
# This cmdlet will make sure default powershell end points exist upon successful completion.
#
# Windows PowerShell:
# Microsoft.PowerShell
# Microsoft.PowerShell32 (wow64)
#
# PowerShell Core:
# PowerShell.<version ID>
#
$errorCount = $error.Count
$endPoint = Get-PSSessionConfiguration {0} -Force:$Force -ErrorAction silentlycontinue 2>&1
$newErrorCount = $error.Count

# remove the 'No Session Configuration matches criteria' errors
for ($index = 0; $index -lt ($newErrorCount - $errorCount); $index ++)
{{
$error.RemoveAt(0)
}}

$qMessage = $queryForRegisterDefault -f ""{0}"",""Register-PSSessionConfiguration {0} -force""
if ((!$endpoint) -and
($force -or $pscmdlet.ShouldProcess($qMessage, $captionForRegisterDefault)))
{{
$resolvedPluginInstallPath = """"
#
# Section 1:
# Move pwrshplugin.dll from $PSHOME to the endpoint directory
#
$pluginInstallPath = Join-Path ""$env:WINDIR\System32\PowerShell"" $psversiontable.GitCommitId
if (!(Test-Path $pluginInstallPath))
{{
$resolvedPluginInstallPath = New-Item -Type Directory -Path $pluginInstallPath
}}
else
{{
$resolvedPluginInstallPath = Resolve-Path $pluginInstallPath
}}
if (!(Test-Path $resolvedPluginInstallPath\{5}))
{{
Copy-Item $PSHOME\{5} $resolvedPluginInstallPath -Force
if (!(Test-Path $resolvedPluginInstallPath\{5}))
{{
Write-Error ($errorMsgUnableToInstallPlugin -f ""{5}"", $resolvedPluginInstallPath)
return
}}
}}
Register-EndpointIfNotPresent -Name {0} $Force $queryForRegisterDefault $captionForRegisterDefault

#
# Section 2:
# Generate the Plugin Configuration File
#
Generate-PluginConfigFile $resolvedPluginInstallPath

#
# Section 3:
# Register the endpoint
#
$null = Register-PSSessionConfiguration -Name {0} -force

set-item -WarningAction SilentlyContinue wsman:\localhost\plugin\{0}\Quotas\MaxShellsPerUser -value ""25"" -confirm:$false
set-item -WarningAction SilentlyContinue wsman:\localhost\plugin\{0}\Quotas\MaxIdleTimeoutms -value {4} -confirm:$false
restart-service winrm -confirm:$false
# Create the default PSSession configuration, not tied to specific PowerShell version
# e. g. 'PowerShell.6'.
$powershellVersionMajor = $PSVersionTable.PSVersion.ToString()
$dotPos = $powershellVersionMajor.IndexOf(""."")
if ($dotPos -ne -1) {{
$powershellVersionMajor = $powershellVersionMajor.Substring(0, $dotPos)
}}
Register-EndpointIfNotPresent -Name (""PowerShell."" + $powershellVersionMajor) $Force $queryForRegisterDefault $captionForRegisterDefault

# PowerShell Workflow and WOW are not supported for PowerShell Core
if (![System.Management.Automation.Platform]::IsCoreCLR)
Expand Down
Loading
0