Forum Discussion

jasm_146487's avatar
jasm_146487
Icon for Nimbostratus rankNimbostratus
Mar 09, 2015

How to create local users using iControl and Powershell

Can someone help me by providing sample code of how I can create a regular user on BIG-IP (11.5) using iControl and Powershell?

 

2 Replies

  • Try this. It works for me in 11.5.0. Understanding the API a little bit comes from here.

    region Check that SnapIn is installed
    
    try {
        Add-PSSnapIn -Name iControlSnapIn -ErrorAction Stop;
    } catch {
        Write-Host "  iControlSnapin is not installed." -ForegroundColor Red;
        Write-Host "    Download the snapin from https://devcentral.f5.com/d/microsoft-powershell-with-icontrol" -ForegroundColor Red;
    
         Exit the script
        return;
    }
    
    endregion
    
    region Credentials
    
    if ($f5Credentials -eq $null) {
        $f5Credentials  = $(Get-Credential -Message "Credentials for F5 server connection");
    }
    Write-Verbose "  Credentials: $($f5Credentials.Username)";
    
    endregion
    
    region Create the User
    
     Establish the connection to the BIG-IP server
    $iConn                          = Initialize-F5.iControl -HostName "SERVER" -Username $f5Credentials.Username -Password $f5Credentials.GetNetworkCredential().Password;
    if (!$iConn) { throw "Connection could not be established to $($connSrc.Server)."; return; }
    
     Get the iControl object
    $iCtrl                          = Get-F5.iControl;
    
     Create the UserInfo3 object
    $userInfo                       = New-Object iControl.ManagementUserManagementUserInfo3;
     User
    $userInfo.User                  = New-Object iControl.ManagementUserManagementUserID;
    $userInfo.User.name             = "USERNAME";
    $userInfo.User.full_name        = "NAME";
     Password 
    $userInfo.Password              = New-Object iControl.ManagementUserManagementPasswordInfo;
    $userInfo.Password.is_encrypted = $false;
    $userInfo.Password.password     = "PASSWORD";
     Permissions
    $perms                          = New-Object iControl.ManagementUserManagementUserPermission;
    $perms.partition                = "[All]";  Or name of single partition
    $userInfo.Permissions           = $perms;
     Login Shell
    $userInfo.login_shell           = "/bin/bash";  Bash: "/bin/bash" || TMSH only: "/bin/false";
    
     Execute the create function
    $iCtrl.ManagementUserManagement.create_user_3($userinfo)
    
    endregion
    
  • ah!

     

    You use iControl even though you specify $iCtrl = Get-F5.iControl;

     

    I was using $iCtrl to specify the objects defined later on in the script