web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / FT Dynamics AX blog / A Power shell script for up...

A Power shell script for updating admin user SID and other details

dolee Profile Picture dolee 11,279
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.
                
$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
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.

This posting is provided "AS IS" with no warranties, and confers no rights.

This was originally posted here.

Comments

*This post is locked for comments