Implicit Remoting Issues with the Remote Desktop Services Module

Welcome Forums General PowerShell Q&A Implicit Remoting Issues with the Remote Desktop Services Module

This topic contains 6 replies, has 3 voices, and was last updated by

 
Participant
3 years, 11 months ago.

  • Author
    Posts
  • #21647

    Participant
    Points: 1
    Rank: Member

    Okay so this is what I did:

    $RemSession = New-PSSession -ComputerName 'MyServer'
    
    Enter-PSSession -Session $RemSession
    
    Invoke-Command { Import-Module RemoteDesktop } -Session $RemSession
    
    Export-PSSession -Session $RemSession -CommandName *-RD* -OutputModule PSRDS -AllowClobber -Force
    
    Remove-PSSession -Session $RemSession
    
    Import-Module -Name PSRDS -Prefix PSRem

    And all that looked good with no errors.

    Then I ran the following command:

    Get-PSRemRDUserSession -ConnectionBroker 'MyServer' 

    And I received the following error:

    The term 'Get-RDUserSession' 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.
    + CategoryInfo : ObjectNotFound: (Get-RDUserSession:String) [], C
    ommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
    + PSComputerName : MyServer

    Can someone please help me out here and explain why I cannot use Implicit Remoting and run this command?

    Thanks everyone, I appreciate your help.

  • #21648

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    You removed the session. You can't do that. The session is needed to run all of the commands on the remote computer. The module you created locally only contains shortcuts to the remote computer, which rely on the original session object. That's why it's called "Remoting."

  • #21651

    Participant
    Points: 1
    Rank: Member

    I was following your instructions here: http://technet.microsoft.com/en-us/magazine/ff720181.aspx

    So were you mistaken here in this article back in 2010, or am I just not reading this correctly?

    I thought I could remove the session as long as I imported the remote system's cmdlets into my PowerShell profile on my local system and then import that module?

    Thanks Don

  • #21652

    Participant
    Points: 1
    Rank: Member

    By the way, I commented out the "Remove-PSSession -Session $RemSession" and it still produced the same following error:

    The term 'Get-RDUserSession' 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.
    + CategoryInfo : ObjectNotFound: (Get-RDUserSession:String) [], C
    ommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
    + PSComputerName : MyServer

    Thanks again for your help, much appreciated.

  • #21660

    Member
    Points: 0
    Rank: Member

    You've got an extra step in there that isn't mentioned in the article you referenced; Enter-PSSession is unnecessary, and will probably screw with your results.

  • #21672

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    The article is going about it slightly differently. In a perfect world, disconnecting the session and then attempting to use the module *should* re-connect the session implicitly. However, keep in mind that the article is four years old, and was written for an older version of PowerShell than you're likely using. The article uses PowerShell v2; things work slightly differently in v3+.

    Today, it would be more sensible to use the shorter version:

    $session = New-PSSession -ComputerName REMOTE1
    Import-Module -PSSession $session -Name RemoteDesktop -Prefix PSRem
    

    I unfortunately can't go back an update articles to bring them up-to-speed with newer versions of PowerShell. This example will work with v3+.

    Hope that helps.

  • #21687

    Participant
    Points: 1
    Rank: Member

    Thanks Dave and Don, you guys are great man.

    Yeah I am using version 4 now. Dave, I don't know how I missed not seeing that enter-pssession thanks for pointing that out.

    Don, I did what you said and now the script works great just using those two lines.

    Thanks again.

The topic ‘Implicit Remoting Issues with the Remote Desktop Services Module’ is closed to new replies.