> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/powershell-universal/powershell-commands/new-psuauthenticationresult.md).

# New-PSUAuthenticationResult

## SYNOPSIS

Returns an authentication result for forms authentication.

## SYNTAX

```
New-PSUAuthenticationResult [-Claims <ScriptBlock>] [-Success] [-UserName <String>] [-ErrorMessage <String>]
 [<CommonParameters>]
```

## DESCRIPTION

Returns an authentication result for forms authentication. This allows you to return the user name, whether the authentication was successful, custom claims and an error message when the user attempts to login.

## EXAMPLES

### Example 1

```powershell
param($Credential)

if ($Credential.UserName -eq 'Adam')
{
    New-PSUAuthenticationResult -UserName 'Adam' -Success
}
else 
{
    New-PSUAuthenticationResult -ErrorMessage "Hey! You aren't Adam"
}
```

Returns a successful authentication result if the user name is 'Adam'. Returns a custom error message if that user is not.

## PARAMETERS

### -Claims

The claims to return from this authentication result. Claims typically are features of the current user account like the Active Directory group membership. Use the new-PSUAuthorizationClaim cmdlet to define these claims.

```yaml
Type: ScriptBlock
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ErrorMessage

The custom error message to return upon unsuccessful logins.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Success

A switch parameter that signals that this authentication attempt was successful.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -UserName

The user name to set on the identity of the user logging in.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -Verbose, -WarningAction, -WarningVariable, and -ProgressAction. For more information, see [about\_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

### None

## OUTPUTS

### System.Object

## NOTES

## RELATED LINKS

[New-PSUAuthorizationClaim](/powershell-universal/powershell-commands/new-psuauthorizationclaim.md) [Set-PSUAuthenticationMethod](/powershell-universal/powershell-commands/set-psuauthenticationmethod.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.devolutions.net/powershell-universal/powershell-commands/new-psuauthenticationresult.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
