Implicit Remoting Issues with the Remote Desktop Services Module

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:

[blockquote]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 [/blockquote]

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.

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.”

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

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

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

[blockquote]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[/blockquote]

Thanks again for your help, much appreciated.

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.

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.

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.