Wednesday, June 20, 2018

Powershell script to import AX Users with roles (Without CSV file)

Import-AXModule "AxUtilLib" $false $true
Import-AXModule "AxUtilLib.PowerShell" $true $false
Import-AXModule "Microsoft.Dynamics.Administration" $false $false
Import-AXModule "Microsoft.Dynamics.AX.Framework.Management" $false $false

$AXUsers = Get-AXUser | where {$_.AXUserId -and $_.UserName}
$AXUserId = $null
$Users = "eshant.k","Manikanta.m"

foreach($user in $users)
{


    if ($user.length -gt 8)
    {
        $AXUserId = ($user.SubString(0,7) + $user.substring($user.length -1))
        Write-Verbose "Altered AXUserId from $($user) to $AXUserId in order to fit length requirements."
     
    }

    else
    {
        $AXUserId = $user
     
    }

    New-AXUser -AccountType WindowsUser -AXUserId $AXUserId -username $user -UserDomain diplit.local
    Add-AXSecurityRoleMember -AxUserID $AXUserId -AOTName "-SYSADMIN-"

 
}

No comments:

Post a Comment

How to enable the dimension fields based on the Item selected on the form.

[Form] public class KMTShipFromWarehouses extends FormRun {     InventDimCtrl_Frm_EditDimensions        inventDimFormSetup;     /// &l...