> For the complete documentation index, see [llms.txt](https://docs.lithnet.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lithnet.io/ams/v2.0/help-and-support/advanced-help-topics/authorization-scripts.md).

# Script-based authorization

![](https://2384577883-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGiL0iwWnyPOkaGqdhRTp%2Fuploads%2Fgit-blob-777b39409f48f271de2f52ccc6f33e3248829f95%2Fbadge-enterprise-edition-rocket.svg?alt=media) Script-based authorization is an [Enterprise edition feature](/ams/v2.0/access-manager-editions.md)

If you'd like to make dynamic authorization decisions, outside the static ACL model, you can utilize a PowerShell script to do this.

Access Manager can call a script that contains a function called `Get-AuthorizationResponse` that takes a user, computer, and logger as input parameters. From there you can make a decision on what the user should be allowed or denied access to, or choose to not make an authorization decision at all.

Access Manager uses the response you provide to create a dynamic ACL for the user, and includes it in the access evaluation of all applicable targets.

## Example script

```
function Get-AuthorizationResponse{
	param(
	$user,
	$computer
)
	Write-Information  "We're in PowerShell!"
	Write-Information "Checking if $($user.MsDsPrincipalName) is allowed access to $($computer.MsDsPrincipalName)"

	# Create an object to hold our authorization decisions
	# Set IsAllowed to true to allow access, or set IsDenied to explicitly deny access, or leave both as false if no decision was made. This will allow other rules to be evaluated.
	$response = [PSCustomObject]@{
		IsLocalAdminPasswordAllowed = $false
		IsLocalAdminPasswordDenied = $false
		IsLocalAdminPasswordHistoryAllowed = $false
		IsLocalAdminPasswordHistoryDenied = $false
		IsJitAllowed = $false
		IsJitDenied = $false
		IsBitLockerAllowed = $false
		IsBitLockerDenied = $false
	}

	# Return the authorization response to Access Manager to process
	Write-Output $response;
}
```

## Logging information

You can use the Write-Information, Write-Warning, Write-Verbose cmdlets to write to the AMS log file and document your authorization decisions. Note that if you use Write-Error, or if an exception is thrown and not handled, the authorization evaluation for the entire access request will fail.

## Performance

Be aware of performance when writing external authorization scripts. From the user's perspective, they will be waiting in the browser while the access evaluation takes place. If you have a slow script, or lots of scripts, this wait time may seem excessive.

Scripts that take longer than 30 seconds to complete will be terminated by Access Manager, and the user's authorization request will fail.

### `$user` object

The user object has the following properties you can access

#### MsDsPrincipalName

The NT4-style name of the user (e.g. `DOMAIN\user`)

#### Sid

The Security Identifier of the user (e.g. `S-1-5-x`)

#### SamAccountName

The samAccountName of the user (e.g. `user`)

#### DisplayName

The display name of the user

#### UserPrincipalName

The user's UPN (e.g. `user@domain.local`)

#### Description

The value of the description field in active directory, if present

#### EmailAddress

The user's email address (e.g. `user@domain.com`)

#### GivenName

The user's given name

#### Surname

The user's surname

### `$computer` object

The computer object has the following properties you can access

#### MsDsPrincipalName

The NT4-style name of the computer (e.g. `DOMAIN\PC1$`)

#### Sid

The Security Identifier of the computer (e.g. `S-1-5-x`)

#### SamAccountName

The samAccountName of the computer (e.g. `PC1`)

#### DisplayName

The display name of the computer

#### Description

The value of the description field in active directory, if present


---

# 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.lithnet.io/ams/v2.0/help-and-support/advanced-help-topics/authorization-scripts.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.
