4

I'm running into an issue where simple commands (Get-Module, for example) are not present when remoting into an Exchange 2016 server.

The command I'm running is:

Invoke-Command -ConfigurationName Microsoft.Exchange -ConnectionUri http://SERVERNAME/powershell -Authentication Kerberos -Credential $cred -ScriptBlock { Get-Module }

The result is:

The term 'Get-Module' 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-Module:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
    + PSComputerName        : SERVERNAME

Other core commands, like Get-Command, work as expected - including Exchange commands (Get-Mailbox, etc).

The only change I've made is changing PSLanguageMode within IIS for the Powershell site to be 'FullLanguage'. Reversing this change (and restarting applicable pools and sites) does not affect the result.

I don't regularly deal with Exchange or PowerShell, so any advice is appreciated.

TravisR
  • 41
  • 3

1 Answers1

1

Exchange servers were designed to be constrained endpoints. The session configuration Microsoft.Exchange is a bare bones configuration schema with limited exposed methods. As Exchange servers are exposed to the outside world the designers are obsessed with security. The command you're trying to use is trivial in your existing context as you specified the environment you wanted with your instantiation.

It is strongly recommended that you work within the existing session configuration (for remote) or run code locally for access to all methods. However, if your risk tolerance affords it you can create a custom session configuration schema using information you find here.

Colyn1337
  • 2,387
  • 2
  • 22
  • 38
  • I'm using the Exchange profile due to the larger script using Exchange commands. With missing core commands some operations as part of the script become difficult. `Get-Module` is just one of the known failing commands. I'll test the solution given above. It looks like it's not the greatest for security, however it looks like it would solve the issue at hand. I'll mark this as the accepted answer provided it works. Thanks :D – TravisR Oct 10 '16 at 09:30
  • Still encountering the same issue. Things like Where-Object and the like are also missing from the command set. – TravisR Oct 11 '16 at 14:50
  • You missed the point. Perhaps this will help clarify: https://blogs.msdn.microsoft.com/dvespa/2011/07/20/where-or-where-has-my-where-object-gone/ – Colyn1337 Oct 11 '16 at 15:10
  • It looks like my edit didn't make it through. I later revised my previous comment to say that I'll have to update my scripts to work around the limitations. Much like the article you've linked. – TravisR Oct 13 '16 at 04:34