Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


Robert Freeland
2022-12-13T19:14:23Z
How would I go about adding AD users via c# type application and assign a VisualCron Group to these users? I suppose I would first need to see if the user exists and if not, then add. Anyone done anything like this and has examples they would care to share?

Basically I want to See if the user exists in VisualCron and if not then add them. After that I want to assign a VisualCron Group or more based on the user's current Group Memberships in AD. Any assistance would be greatly appreciated.
Sponsor
Forum information
Thomas Schmied
2022-12-30T20:44:46Z
Hi,

here is a example in powershell.


### SamAccountName of ADUser you want to add ###
$adUserName = "ADUSERNAME" 

$VCClient = New-Object VisualCronAPI.Client
$vcConn = New-Object VisualCronAPI.Connection

### SERVER HOSTNAME ###
$vcConn.Address = "SERVERNAME"

### VC Username + Pwd
$vcConn.UserName = "VCUSER"
$vcConn.PassWord = "VCPASSWORD"

$vcConn.UseADLogon = $false
$vcConn.ConnectionType = "Remote"

### CONNECT VCSERVER ###
$vcServer = $VCClient.Connect($vcConn)

### TEST IF USER ALREADY EXISTS ###
[bool]$userExists = ($vcServer.Permissions.GetAllUsers() | ? {$vcServer.Decrypt($_.UserName) -eq $adUserName}) -ne $null

### GET Default Admin UserGroup (ID always 1df408ab-c2e3-41b6-ba0e-9b17b3b6743a) ###
$adminUserGroup = $vcServer.Permissions.GetAllUserGroups() | Where-Object {$_.Id -eq "1df408ab-c2e3-41b6-ba0e-9b17b3b6743a"}

if($userExists) {
    Write-Host "USer $adUserName already exists" -ForegroundColor Green   
} else {
    $newUser = [VisualCron.SecUserClass]::new()
    $newUser.IsADUser = $true
    $newUser.ADHostName = $vcServer.Settings.ADServer
    $newUser.ADDC = $vcServer.Settings.ADServer.Split(".")[0]
    $newUser.IsADGroup = $false
    $newUser.Groups.Add($adminUserGroup.Id) ### PERMISSION USERGROUPS
    $newUser.Name = $vcServer.Encrypt( $adUserName)
    $newUser.UserName = $vcServer.Encrypt( $adUserName)
    $newUser.InheritGroup = $false

    ### CREATE NEW USER ###
    $vcServer.Permissions.AddUser($newUser,[ref]$null)
}
Victoria Smart
2023-04-28T10:10:05Z
using VisualCronAPI;

// Create a new instance of the VisualCron client
VisualCron vc = new VisualCron();
vc.Connect("localhost", "Username", "Password");

// Specify the username and password for the new AD user
string username = "newuser";
string password = "password123";

// Create a new user object and set the necessary properties
VCUser newUser = vc.Users.Create();
newUser.Username = username;
newUser.Password = password;
newUser.ActiveDirectory = true;

// Add the user to VisualCron
vc.Users.AddUser(newUser);

// Disconnect from VisualCron
vc.Disconnect();

Note that you'll need to replace localhost, Username, and Password with the appropriate values for your VisualCron server. You'll also need to ensure that the user running this code has the necessary permissions to add new users to VisualCron.
Victoria Smart
2023-05-02T05:04:14Z
Connect to the VisualCron API using a programming language of your choice, such as C#, Java, or Python. Create a new instance of the "User" class. Set the properties of the User object to the desired values. For example, you can set the "UserName" property to the username of the AD user, and the "Password" property to the user's password. Call the "Add" method of the VisualCron API's "Users" object, passing in the User object as a parameter.

using VisualCronAPI; MyBalanceNow 


// Connect to VisualCron API
ServerConnection conn = new ServerConnection();
conn.Connect("localhost", 16444, "admin", "admin");

// Create new User object
User user = new User();
user.UserName = "newuser";
user.Password = "password123";

// Add user to VisualCron
Users users = new Users(conn);
users.Add(user);
Similar Topics
Users browsing this topic
Scroll to Top