Add AD User to VisualCron via API - VisualCron - Forum

Community forum

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)
}
Similar Topics
Users browsing this topic
Scroll to Top