PSSession Issue

Welcome Forums General PowerShell Q&A PSSession Issue

This topic contains 1 reply, has 2 voices, and was last updated by

1 year, 7 months ago.

  • Author
  • #74817

    Points: 0
    Rank: Member

    I have a Powershell GUI program I am writing but having issues with PSSessions for some reason. When the program opens, the function getCredentials fires off.

    function getCredentials
    		$global:rrCredential = Get-Credential -Credential "domain.local\"
    		$global:rrSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchange.domain.local/PowerShell/ -Authentication Kerberos -Credential $rrCredential -ErrorAction SilentlyContinue

    Then later off when we go to create the new user in AD and import the PSSsession with the following but get errors

    function createUser
    .... lots of other code....
    Import-PSSession $rrSession -AllowClobber -DisableNameChecking 

    Below is the errors I get

    Import-PSSession : Cannot bind parameter 'Session'. Cannot convert the "" value of type "System.String" to type "System.Management.Automation.Runspaces.PSSession".
    At Z:\End User Support\Scripts\guiToolkit\eusgToolKitbeta.ps1:557 char:24
    +             Import-PSSession $rrSession -AllowClobber -Di ...
    +                              ~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Import-PSSession], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ImportPSSessionCommand

    This error I don't believe is a result of the one above but just copying just in case.....

    Couldn't find the Enterprise Organization container.
    At Z:\End User Support\Scripts\guiToolkit\eusgToolKitbeta.ps1:1282 char:6
    +     if (!(Get-Recipient $emailAddress -ResultSize Unlimited -ErrorAct ...
    +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], OrgContainerNotFoundException
        + FullyQualifiedErrorId : 38824D84
  • #74832

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Ah, global variables.

    My guess is that your variable is going out of scope somehow. Or getting overwritten. This is one of the many fun reasons that global variables are a dangerous idea. Especially in a GUI – it's really impossible, from this end, to track what might be happening.

    Try setting a breakpoint on that variable and running it. See if you can see where it's being touched.

The topic ‘PSSession Issue’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort