Skip to content

IAdmTop2

The IAdmTop2 interface extends the IAdmTop interface with the RunScript method. This method allows you to execute a PowerShell script or an external program for any directory object that implements this interface.

Inheritance: The IAdmTop2 interface inherits from the IAdmTop interface.

Methods

Details

RunScript()

Runs the specified script for the object. The text of the script can contain value references. Before executing a script, Adaxes will replace value references with corresponding property values of the directory object on which the script is executed.

void RunScript(ADM_SCRIPTTYPE_ENUM scriptType,
               String scriptText,
               String scriptDescription,
               String username,
               String password)

Parameters

  • scriptType - Controls whether the text specified in the scriptText parameter is a text of a PowerShell script (when set to ADM_SCRIPTTYPE_POWERSHELL) or a command line that should be executed (when set to ADM_SCRIPTTYPE_PROGRAM).
  • scriptText - Contains either the text of a PowerShell script to execute, or a command line to be run, depending on the value of the scriptType parameter.
  • scriptDescription - Contains a description of the script passed by the scriptText parameter.
  • username - Specifies the username of the user whose credentials will be used to launch the script. Pass NULL to use the username of the currently logged on user.
  • password - Specifies the password to the account specified in the username parameter. Pass NULL if you want to use the credentials of the currently logged on user.

Examples

The following code sample runs a script to export specific properties of a user to a CSV file.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$admNS = New-Object("Softerra.Adaxes.Adsi.AdmNamespace")
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to the user
$userDN = "CN=John Smith,CN=Users,DC=domain,DC=com"
$user = $admService.OpenObject("Adaxes://$userDN", $NULL, $NULL, 0)

# Script for CSV export
$scriptBlock = {
    $htable = @{FirstName="%firstname%";LastName="%lastname%";Department="%department%";}
    $userObj = New-Object PSObject -Property $htable

    $userObj | Export-Csv "C:\New users\%username%.csv" -NoTypeInformation
}

# Run the script for the user
$user.RunScript("ADM_SCRIPTTYPE_POWERSHELL", $scriptBlock.ToString(), "Export to CSV", $NULL, $NULL)
using System;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;

class Program
{
    static void Main(string[] args)
    {
    // Connect to the Adaxes service
    AdmNamespace adsNS = new AdmNamespace();
    IAdmService admService = adsNS.GetServiceDirectly("localhost");

    // Bind to the user
    const String userPath = "Adaxes://CN=John Smith,CN=Users,DC=domain,DC=com";
    IAdmTop2 user = (IAdmTop2)admService.OpenObject(userPath, null, null, 0);

    // Script for CSV export
    const String scriptBlock = @"
    $htable = @{FirstName=""%firstname%"";LastName=""%lastname%"";Department=""%department%"";}
    $userObj = New-Object PSObject -Property $htable

    $userObj | Export-Csv ""C:\New users\%username%.csv"" -NoTypeInformation";

    // Run the script for the user
    user.RunScript(ADM_SCRIPTTYPE_ENUM.ADM_SCRIPTTYPE_POWERSHELL, scriptBlock, "Export to CSV", null, null);
    }
}

Requirements

Minimum required version: 2010.2

See also