Skip to content

Install-PowerShellRemoting.ps1 fails when run without specifying -PowerShellHome in PowerShell 6.1 GA #7787

Closed

Description

Steps to reproduce

In PowerShell 6.0, Install-PowerShellRemoting.ps1 could be run successfully without any parameters:

PS C:\Program Files\PowerShell\6.0.0> .\Install-PowerShellRemoting.ps1
VERBOSE: Using PowerShell Version: 6.0.0
VERBOSE: Performing the operation "Copy File" on target "Item: C:\Program Files\PowerShell\6.0.0\pwrshplugin.dll Destination: C:\WINDOWS\System32\PowerShell\6.0.0\pwrshplugin.dll".
VERBOSE: Created Plugin Config File: C:\WINDOWS\System32\PowerShell\6.0.0\RemotePowerShellConfig.txt

Get-PSSessionConfiguration powershell.6.0.0


Name          : powershell.6.0.0
PSVersion     : 6.0
StartupScript :
RunAsUser     :
Permission    : BUILTIN\Administrators AccessAllowed

Restarting WinRM to ensure that the plugin configuration change takes effect.
This is required for WinRM running on Windows SKUs prior to Windows 10.

In PowerShell 6.1 GA, the same command fails:

PS C:\Program Files\PowerShell\6> .\Install-PowerShellRemoting.ps1
& : The term '\pwsh' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Program Files\PowerShell\6\Install-PowerShellRemoting.ps1:130 char:30
+         $targetPsVersion = & "$targetPsHome\pwsh" -NoProfile -Command ...
+                              ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (\pwsh:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

VERBOSE: PowerShellHome:
VERBOSE: Using PowerShell Version:
Copy-Item : Cannot find path 'C:\pwrshplugin.dll' because it does not exist.
At C:\Program Files\PowerShell\6\Install-PowerShellRemoting.ps1:192 char:5
+     Copy-Item $targetPsHome\pwrshplugin.dll $resolvedPluginAbsolutePa ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (C:\pwrshplugin.dll:String) [Copy-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand

However, if -PowerShellHome is specified, it works as expected:

PS C:\Program Files\PowerShell\6> .\Install-PowerShellRemoting.ps1 -PowerShellHome $PSHOME
VERBOSE: PowerShellHome: C:\Program Files\PowerShell\6
VERBOSE: Using PowerShell Version: 6.1.0
VERBOSE: Performing the operation "Copy File" on target "Item: C:\Program Files\PowerShell\6\pwrshplugin.dll Destination: C:\WINDOWS\System32\PowerShell\6.1.0\pwrshplugin.dll".
VERBOSE: Created Plugin Config File: C:\WINDOWS\System32\PowerShell\6.1.0\RemotePowerShellConfig.txt

Get-PSSessionConfiguration PowerShell.6.1.0


Name          : PowerShell.6.1.0
PSVersion     : 6.0
StartupScript :
RunAsUser     :
Permission    : BUILTIN\Administrators AccessAllowed

VERBOSE: PowerShellHome: C:\Program Files\PowerShell\6
VERBOSE: Using PowerShell Version: 6
VERBOSE: Performing the operation "Copy File" on target "Item: C:\Program Files\PowerShell\6\pwrshplugin.dll Destination: C:\WINDOWS\System32\PowerShell\6\pwrshplugin.dll".
VERBOSE: Created Plugin Config File: C:\WINDOWS\System32\PowerShell\6\RemotePowerShellConfig.txt

Get-PSSessionConfiguration PowerShell.6
Name          : PowerShell.6
PSVersion     : 6.0
StartupScript :
RunAsUser     :
Permission    : BUILTIN\Administrators AccessAllowed

Restarting WinRM to ensure that the plugin configuration change takes effect.
This is required for WinRM running on Windows SKUs prior to Windows 10.

Expected behavior

PS C:\Program Files\PowerShell\6.0.0> .\Install-PowerShellRemoting.ps1
VERBOSE: Using PowerShell Version: 6.0.0
VERBOSE: Performing the operation "Copy File" on target "Item: C:\Program Files\PowerShell\6.0.0\pwrshplugin.dll Destination: C:\WINDOWS\System32\PowerShell\6.0.0\pwrshplugin.dll".
VERBOSE: Created Plugin Config File: C:\WINDOWS\System32\PowerShell\6.0.0\RemotePowerShellConfig.txt

Get-PSSessionConfiguration powershell.6.0.0


Name          : powershell.6.0.0
PSVersion     : 6.0
StartupScript :
RunAsUser     :
Permission    : BUILTIN\Administrators AccessAllowed

Restarting WinRM to ensure that the plugin configuration change takes effect.
This is required for WinRM running on Windows SKUs prior to Windows 10.

Actual behavior

PS C:\Program Files\PowerShell\6> .\Install-PowerShellRemoting.ps1
& : The term '\pwsh' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.1.0
PSEdition                      Core
GitCommitId                    6.1.0
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. iSazonov commented on Sep 17, 2018

    @iSazonov
    Collaborator

    Seem $PowerShellHome is assigned in global in your session.

  2. added
    Issue-Question
    on Sep 17, 2018
  3. janegilring commented on Sep 21, 2018

    @janegilring
    Author

    From a fresh pwsh 6.1 session:
    PS C:> $PowerShellHome

    PS C:> $PSHome
    C:\Program Files\PowerShell\6

    PS C:>

  4. MaximoTrinidad commented on Sep 21, 2018

    @MaximoTrinidad

    Just wondering... Is this script still needed?? Or, is this scripts runs during the PowerShell Core installation when you checked on the "Enable remoting" option?

    Just want to be clear on it!

    Thanks
    :)

  5. Orca88 commented on Sep 12, 2019

    @Orca88
    Contributor

    There is a simple fix to this issue, replace
    if ($PowerShellHome -ne $null)
    with
    if (-not [String]::IsNullOrEmpty($PowerShellHome))

    and the script will work without specifying -PowerShellHome.

  6. iSazonov commented on Sep 13, 2019

    @iSazonov
    Collaborator

    Orca88 Could you pull PR with the fix?

    /cc Travis Plunk (@TravisEz13)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-QuestionResolution-Fixed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions