A Power shell script for updating admin user SID and other details
Views (1817)
Often I will load up the AX demo database under a different domain. I have write the following PowerShell script to help modify the admin user SID, login info, etc in AX. It uses Invoke-Sqlcmd SQL Server cmdlet to update the USERINFO table.
Since I am using this on an all in one DEV box, the Invoke-Sqlcmd command-let is readily available. If Invoke-SqlCmd is not recognized in the machine you want to run the script, try the tips from this link.
$networkDomain = "[domain]" # e.g. yourDomain.com
$networkAlias = "[user alias]"
$name = "[user name]"
$dbname = "[your AX DB Name]"
$sqlServer = "localhost"
$targetUserId = "admin" # Change this to update other existing AX users
$objUser = New-Object System.Security.Principal.NTAccount("$networkDomain","$networkAlias")
$sid = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
$sqlstmt = "UPDATE {5}.dbo.USERINFO SET SID = '{0}', NETWORKDOMAIN = '{1}', NETWORKALIAS = '{2}', Name = '{3}' " +
"WHERE ID = '{4}'"
$sqlstmt = [string]::Format($sqlstmt,$sid, $networkDomain, $networkAlias, $name, $targetUserId, $dbname)
Invoke-Sqlcmd -Query $sqlstmt -ServerInstance $sqlServer
This posting is provided "AS IS" with no warranties, and confers no rights.
This was originally posted here.
*This post is locked for comments