locked
Powershell New-PSSession and Import-PSSession - Deserialized.System.Management... error RRS feed

  • Question

  • I'm using the following code to try and setup a remote powershell session to a domain controller from a domain workstation so I can use the AD commands without having to install anything onto my machine.  I do currently have the AD related cmdlets on my machine, but other colleagues will not.

    $PShellSession = ""
    $LiveCred = Get-Credential
    $PShellsession = New-PSSession -ConfigurationName Microsoft.Powershell -computername DC1 -Credential $LiveCred
    Import-PSSession $PShellsession -DisableNameChecking -NoClobber
    

    I get the following error:

    Cannot bind parameter 'Session'. Cannot convert the "[PSSession]Session1" value of type "Deserialized.System.Management.Automation.Runspaces.PSSession" to type
    "System.Management.Automation.Runspaces.PSSession".
        + CategoryInfo          : InvalidArgument: (:) [Import-PSSession], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ImportPSSessionCommand
        + PSComputerName        : DC1

    If anyone can help me with this error it would be greatly appreciated.

    The end result will be a powershell form which makes a PSSession connection to Exchange (this currently works for me), to a DC to get AD cmdlets and allow service desk staff to add groups to shared mailboxes to enable send as.  Everything else is working except this one bit.

    Thanks in advance.

    Pete.

    Monday, January 22, 2018 4:25 PM

Answers

  • Hi Pete,

    Based on my research, we may need to add -Module parameter for Import-PSSession cmdlet so that we can use Active Directory cmdlets. The following script for your reference, hope it is helpful to you:
    $session = New-PSSession -ComputerName DC -Credential (Get-Credential)
    Import-PSSession -Session $session -Module ActiveDirectory

    Also, for connectting to Exchange Server, you may have a try with the following script, please replace the Uri to your actual Mailbox Role Uri :
    $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://mbx16.contoso.com/PowerShell/ -Authentication Kerberos -Credential (Get-Credential)
    Import-PSSession $session

    If you need further help, please feel free to let us know.

    Best Regards,
    Albert

    Please remember to mark the replies as an answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, January 23, 2018 5:03 AM

All replies

  • $LiveCred = Get-Credential
    $PShellsession
    = New-PSSession -computername DC1 -Credential$LiveCred
    Import-PSSession$PShellsession -DisableNameChecking

    \_(ツ)_/

    Monday, January 22, 2018 8:07 PM
  • Hi Pete,

    Based on my research, we may need to add -Module parameter for Import-PSSession cmdlet so that we can use Active Directory cmdlets. The following script for your reference, hope it is helpful to you:
    $session = New-PSSession -ComputerName DC -Credential (Get-Credential)
    Import-PSSession -Session $session -Module ActiveDirectory

    Also, for connectting to Exchange Server, you may have a try with the following script, please replace the Uri to your actual Mailbox Role Uri :
    $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://mbx16.contoso.com/PowerShell/ -Authentication Kerberos -Credential (Get-Credential)
    Import-PSSession $session

    If you need further help, please feel free to let us know.

    Best Regards,
    Albert

    Please remember to mark the replies as an answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, January 23, 2018 5:03 AM
  • Hi Albert, this worked perfectly, thanks for the response.  I'd lost a couple of hours over this :-(

    Thanks again.

    Pete.

    Tuesday, January 23, 2018 11:46 AM