Skip to main content

Mass Delete of Native User Accounts

Comments

3 comments

  • Jason

    This would be extremely helpful. I have hundreds of old, disabled accounts that I'd like to purge.

    0
  • Dana Anderson
    Product Support

    Hi, Jason.

    I understand that the ability to do mass deletes of native user accounts would be helpful for you, especially if you have hundreds of old, disabled accounts that you would like to purge. While we currently do not have this feature available, there is a workaround that you could do. 

    You have to export all your users to CSV, then delete the existing users' settings file and restart the Cerberus service. This creates a new, empty users settings file. Next, remove the users you don't want from the CSV and save it. Finally, you upload that CSV to import all the users you want.

    If you would like further assistance with this, please reach out to the support team. 

     

     

    0
  • hristo

    I wrote a powershell script to mass delete users from a CSV file.

     

    # ------------------------------------------------------------------------------

    # script : Using PowerShell to MASS Delete Cerberus users

    # ------------------------------------------------------------------------------




    Param(

        # The URL to Cerberus.wsdl (Cerberus SOAP API Web Service Definition)

        [Parameter (Mandatory = $false,

                    HelpMessage = "Enter the location of the Cerberus.wsdl file. May be a URL or a filesystem path."

        )]

        [String] $WSDLUrl = "https://localhost:8443/wsdl/Cerberus.wsdl"

    ,

        # The Cerberus Primary Administrator Account credentials

        [Parameter (Mandatory = $false)]

        [PSCredential] $CerberusCredentials

    ,

        # The SOAP Service endpoint. This value overrides the default service endpoint found in Cerberus.wsdl 

        [Parameter (Mandatory = $false)]

        [String] $CerberusServiceUrl

    ,

        # Enable if SOAP service uses HTTPS

        [Parameter (Mandatory=$false)]

        [switch] $EnableTls12

    ,

        # Enable if Cerberus FTP Server is using a self-signed certificate

        [Parameter (Mandatory=$false)]

        [switch] $DisableCertValidation

    )










    # ------------------------------------------------------------------------------

    # Setup SOAP Connection

    # ------------------------------------------------------------------------------




    # Collect credentials if not provided in parameters

    if (-not $PSBoundParameters.containsKey('CerberusCredentials')) {

        $CerberusCredentials = Get-Credential -Message "Provide master admin credentials for Cerberus FTP Server"






    if ($EnableTls12) {

        [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 

    }




    if ($DisableCertValidation) {

        if (-not("dummy" -as [type])) {

            add-type -TypeDefinition @"

        using System;

        using System.Net;

        using System.Net.Security;

        using System.Security.Cryptography.X509Certificates;




        public static class Dummy {

            public static bool ReturnTrue(object sender,

                X509Certificate certificate,

                X509Chain chain,

                SslPolicyErrors sslPolicyErrors) { return true; }




            public static RemoteCertificateValidationCallback GetDelegate() {

                return new RemoteCertificateValidationCallback(Dummy.ReturnTrue);

            }

        }

    "@

        }

        [System.Net.ServicePointManager]::ServerCertificateValidationCallback = [dummy]::GetDelegate()

    }




    # Create Web Service Proxy object and CerberusFtp data-types

    $CerberusSvc = New-WebServiceProxy -Uri $WSDLUrl -Class CerberusFtp -Namespace CerberusFtp




    # Override default SOAP endpoint if provided in parameters

    if ($PSBoundParameters.ContainsKey($CerberusServiceUrl)){

        $CerberusSvc.Url = $CerberusServiceUrl

    }




    # ------------------------------------------------------------------------------

    # Delete a User

    # ------------------------------------------------------------------------------

    # Specify the path to your CSV file containing the list of users

    $csvFilePath = "userlist.txt"




    # Import the CSV file

    $userList = Import-Csv -Path $csvFilePath




    # Specify the path for the output log file

    $outputLogFilePath = "output.log"




    # Iterate through each user in the CSV file

    foreach ($user in $userList) {

        # Create a new DeleteUserRequest object

        [CerberusFtp.DeleteUserRequest] $deleteUserRequest = New-Object -TypeName CerberusFtp.DeleteUserRequest




        # Populate request object with Cerberus Admin credentials

        $deleteUserRequest.credentials = New-Object CerberusFtp.Credentials

        $deleteUserRequest.credentials.user = $CerberusCredentials.UserName

        $deleteUserRequest.credentials.password = $CerberusCredentials.GetNetworkCredential().Password




        # Populate request object with username to be deleted from the CSV file

        $deleteUserRequest.name = $user.UserName # The CSV should have a column named "UserName"




        # Issue the DeleteUser request

        [CerberusFtp.DeleteUserResponse] $deleteUserResponse = $CerberusSvc.DeleteUser($deleteUserRequest)




    # Get current timestamp for the log file

    $currentDateTime = Get-Date -Format "yyyy-MM-dd HH:mm:ss"




        # Check response for success or failure

        if (-not $deleteUserResponse.result){

            Write-Error "$currentDateTime : Failed to delete user $($user.UserName) : User does not exist"

    echo "$currentDateTime : Failed to delete user $($user.UserName) : User does not exist" >> $outputLogFilePath

        } else {

            Write-Host "$currentDateTime : Successfully deleted $($user.UserName)"

    echo "$currentDateTime : Successfully deleted $($user.UserName)" >> $outputLogFilePath

        }

    }

    0

Please sign in to leave a comment.