Active Directory User Attributes as Variables

On a number of occasions over the years I have found myself needing to gain access to Active Directory attributes; maybe in login scripts or even in AppSense Environment Manager and in later releases Application Manager as well. Whether this be for establishing conditions and therefore providing granular configuration or maybe even to just use in an action of some kind.

Anyway, this is a quick post to show that this can be achieved quite easily. The script below has the ability to take the specified attributes and either set them as Environment Variables or AppSense Environment Manager Session Variables. The name of the variable created will be the same as the attribute it relates to.

This means that the script, with its default settings will create two Environment Variables called name and mail. You can then retrieve these in any manner that you would normally access an Environment Variable.

If you were to change the $UseEnvironmentVariables variable to $false then the script will create the attributes as Environment Manager Session Variables. You can then access them using the $() notation in the configuration as per the following screenshot.

ad_attributes_as_variables_1

Without further ado, the script is hosted as a gist on Github and is embedded here for completeness.