Access $Credentials from login Authentication -or import Microsoft.Exchange PSSession


I’m trying to import a PSSession for Microsoft.Exchange. I need to pass the $Credentials from the New-UDAthenticationMethod.

I’ve been unable to access them from the page just via $Credentials variable.
Here’s the authentication setup:

    Function Test-Credential {
        Param (
                Mandatory = $true,
                ValueFromPipeLine = $true,
                ValueFromPipelineByPropertyName = $true
            $Domain = $Credential.GetNetworkCredential().Domain
        Begin {
            [System.Reflection.Assembly]::LoadWithPartialName("System.DirectoryServices.AccountManagement") |
            $principalContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext(
                [System.DirectoryServices.AccountManagement.ContextType]::Domain, $Domain
        Process {
            foreach ($item in $Credential) {
                $networkCredential = $Credential.GetNetworkCredential()
                Write-Output -InputObject $(
                        $networkCredential.UserName, $networkCredential.Password
        End {
    $adgroupname = 'FileServer_Admin'
    if ((Test-Credential -Credential $Credentials)) {
        if(Get-ADGroupMember -Identity $adgroupname | Where-Object{$_.Name -eq $Credentials.UserName}){
            New-UDAuthenticationResult -Success -UserName $Credentials.UserName
$Session:Creds = $Credentials
        } else { New-UDAuthenticationResult -ErrorMessage "Only members of $adgroupname have access."}
    New-UDAuthenticationResult -ErrorMessage "Invalid Credentials, please try again."
} #end FormLogin


I’ve also headed down the path of defining my PS exchange import as a function:

function Connect-Exchange 
    $Creds = New-Object System.Management.Automation.PSCredential -ArgumentList $Session:Creds.UserName, $Session:Creds.Password
    $ExSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $Creds
    Import-PSSession $ExSession

And then New-UDEndpointInitialization:

$InitExchange = New-UDEndpointInitialization -Function Connect-Exchange -Debug
$MyDashboard= New-UDDashboard -Title "New User Provisioning" -EndpointInitialization $InitExchange .....

Still no luck getting the Exchange commands to load.


Stupid question… You are actually calling the function somewhere, right?

Tim Curwick


We have the support with the enterprise license. Via email, Adam was able to determine my

$Session:Creds = $Credentials 

wasn’t being saved to the session variable array.
2.4.0 has a fix inline for it.

I’ll be posting this entire mess up to the marketplace as a free sample in a few more days.