Skip to content
Merged
Changes from all commits
Commits
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
54 changes: 17 additions & 37 deletions src/powershell-native/Install-PowerShellRemoting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@
#
# Registers the WinRM endpoint for this instance of PowerShell.
#
# If the parameters '-PowerShellHome' were specified, it means that the script will be registering
# an instance of PowerShell from another instance of PowerShell.
#
# If no parameter is specified, it means that this instance of PowerShell is registering itself.
#
# Assumptions:
# 1. This script is run from within the PowerShell that it will register as a WinRM endpoint.
# 2. The CoreCLR and the the PowerShell assemblies are side-by-side in $PSHOME
# 3. Plugins are registered by version number. Only one plugin can be automatically registered
# 1. The CoreCLR and the the PowerShell assemblies are side-by-side in $PSHOME
# 2. Plugins are registered by version number. Only one plugin can be automatically registered
# per PowerShell version. However, multiple endpoints may be manually registered for a given
# plugin.
#
#####################################################################################################
[CmdletBinding(DefaultParameterSetName = "NotByPath")]
param
(
[parameter(ParameterSetName = "ByPath")]
[ValidateNotNullOrEmpty()]
[parameter(Mandatory = $true, ParameterSetName = "ByPath")]
[string]
$PowerShellHome,

[parameter(ParameterSetName = "ByPath")]
[ValidateNotNullOrEmpty()]
[string]
$PowerShellVersion = "6.0.0-alpha.8"
$PowerShellHome
)

function Register-WinRmPlugin
Expand All @@ -37,7 +36,7 @@ function Register-WinRmPlugin
$pluginAbsolutePath,

#
# Expected Example: microsoft.powershell-core.6.0
# Expected Example: powershell.6.0.0-beta.3
#
[string]
[parameter(Mandatory=$true)]
Expand Down Expand Up @@ -76,7 +75,7 @@ function Register-WinRmPlugin
reg.exe import .\$fileName

# Clean up
# Remove-Item .\$fileName
Remove-Item .\$fileName
}

function Generate-PluginConfigFile
Expand Down Expand Up @@ -114,39 +113,20 @@ if (! ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity
Break
}

#
# If the parameters were specified, it means that the script will be registering
# an instance of PowerShell from another instance of PowerShell.
#
# If no parameters are specified, it means that this instance of PowerShell is
# registering itself.
#
if ($PsCmdlet.ParameterSetName -eq "ByPath")
{
$targetPsHome = $PowerShellHome
$targetPsVersion = $PowershellVersion
$targetPsVersion = & "$targetPsHome\powershell" -NoProfile -Command '$PSVersionTable.PSVersion.ToString()'
}
else
{
## Get the PSHome and PSVersion using the current powershell instance
$targetPsHome = $PSHOME

# Parse the version string from the version file so that users do not have
# to enter it manually.
$targetPsVersionFilePath = Join-Path $targetPsHome "Powershell.Version"
$versionString = (Get-Content $targetPsVersionFilePath).Trim()
if($versionString.StartsWith("v"))
{
$versionString = $versionString.substring(1)
}
$index = $versionString.LastIndexOf(".")
$version = $versionString.Substring(0,$index)
$revision = $versionString.Substring($index).split("-")
$version= $version + $revision[0]
$targetPsVersion = $version

Write-Verbose "Using PowerShell Version: $targetPsVersion" -Verbose
$targetPsVersion = $PSVersionTable.PSVersion.ToString()
}

Write-Verbose "Using PowerShell Version: $targetPsVersion" -Verbose

$pluginBasePath = Join-Path "$env:WINDIR\System32\PowerShell" $targetPsVersion

$resolvedPluginAbsolutePath = ""
Expand Down