locked
Issue in Import-PSSession RRS feed

  • Question

  • Hi everyone,

    I try to figure a very weird result coming from a cmdlet. This is what i got :

    If I do that :

    Import-PSSession -Session $SessionCommand -AllowClobber -DisableNameChecking -CommandName New-MoveRequest,Get-MoveRequestStatistics,Remove-MoveRequest,Set-MsolUser


    It works. But if I do that :

    Import-PSSession -Session $SessionCommand -AllowClobber -DisableNameChecking -CommandName Get-MsolUser


    It fails with this error :

    +   Import-PSSession -Session $SessionCommand -AllowClobber -DisableNam ...
    +   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidResult : (:) [Import-PSSession], Argument 
       Exception
        + FullyQualifiedErrorId : ErrorNoResultsFromRemoteEnd,Microsoft.PowerShell 
       .Commands.ImportPSSessionCommand


    I don't understand why it fails because if I do that :

      Import-PSSession -Session $SessionCommand -AllowClobber -DisableNameChecking -CommandName Get-MsolUser,New-MoveRequest

    It works, but that :

      Import-PSSession -Session $SessionCommand -AllowClobber -DisableNameChecking -CommandName Get-MsolUser,Get-MsolUserRole

    It doesn't work.

     

    Do you have any idea ?

    Thank you.


    The key of learning is practice.

    Tuesday, November 27, 2018 3:14 PM

Answers

  • Okay, I got it. In fact, the get-msoluser is not an exchange online cmdlet but a cmdlet from the MSOnline module. Then, apparently, if I only import non-existing cmdlet from a module it gives me error but if I import at least one good cmdlet from the module, the others cmdlet won't give me errors.

    - Import-pssession ... Get-MsolUser is a MSOnline => alone it fails

    - Import-pssession ... Get-MsolUser,Get-Mailbox => Get-Mailbox comes from exchange online module so it works well, even if the firsts cmdlet is not imported by this way

    Thanks for your time.


    The key of learning is practice.

    • Marked as answer by arnaud.helin Tuesday, November 27, 2018 5:09 PM
    Tuesday, November 27, 2018 5:05 PM

All replies

  • You need to install the MSOL support locally.

    Find-Module msonline
    Install-Module msonline

    The module is not designed to be imported.


    \_(ツ)_/

    Tuesday, November 27, 2018 3:26 PM
  • "The module is not designed to be imported." => How do you know that ? Or where I can find this information ?

    By the way I don't have the explanation about this behavior. It doesn't sound weird for you apparently so I suppose you know why, isn't it ?


    The key of learning is practice.

    Tuesday, November 27, 2018 3:41 PM
  • The module requires installation on the system.  Importing commands does not install the prerequisites.  There is no element of the documentation that doesn't begin with "first install the msonline module". I all cases I am aware of, modules that can be imported for Azure/O365 will describe how to remote then import the module.

    If you think this is wrong then keep experimenting. Who knows? You may discover something that is not documented.


    \_(ツ)_/

    Tuesday, November 27, 2018 3:46 PM
  • Thank you for your time. I will try to know why it doesn't work as expected.

    The key of learning is practice.

    Tuesday, November 27, 2018 4:11 PM
  • Okay, I got it. In fact, the get-msoluser is not an exchange online cmdlet but a cmdlet from the MSOnline module. Then, apparently, if I only import non-existing cmdlet from a module it gives me error but if I import at least one good cmdlet from the module, the others cmdlet won't give me errors.

    - Import-pssession ... Get-MsolUser is a MSOnline => alone it fails

    - Import-pssession ... Get-MsolUser,Get-Mailbox => Get-Mailbox comes from exchange online module so it works well, even if the firsts cmdlet is not imported by this way

    Thanks for your time.


    The key of learning is practice.

    • Marked as answer by arnaud.helin Tuesday, November 27, 2018 5:09 PM
    Tuesday, November 27, 2018 5:05 PM
  • That still does not provide you with an imported copy of the local CmdLet and really makes no technical sense.

    The CmdLet is being added to the online session but that does not mean CmdLets imported this way will work.  If you try to run Get-MsoUser it will fail.


    \_(ツ)_/

    Tuesday, November 27, 2018 5:17 PM
  • Get-MsoUser => I agree it will fail if I do not install msonline module followed by the Connect-MsolService cmdlet.

    In fact I thought that Get-MsolUser was an exchange online cmdlet. But it is not. So, yes I have to install the Msonline module.



    The key of learning is practice.

    Tuesday, November 27, 2018 6:16 PM