I wanted to bulk create a bunch of users in CRM. PowerShell and the Microsoft CRM 2011 REST/OData endpoint make it easy. Here is a function to create a SystemUser via PowerShell
FUNCTION JBMURPHY-CRM-CreateSystemUser { PARAM([string][ValidateSet("crmserver.company.com", "dev-crmserver.company.com")]$ServerName="crmserver.company.com", [string][ValidateSet("CRMOrganizationName")]$OrganizationName="CRMOrganizationName", [string]$BusinessUnitId="BusinessUnitGUID", [string]$SystemUserDomain="CRMSystemUserDomain", [string][parameter(Mandatory=$true)]$FirstName, [string][parameter(Mandatory=$true)]$LastName, [string][parameter(Mandatory=$true)]$UserName,[switch]$MyDebug ) [string]$url="http://$ServerName/$($OrganizationName)/xrmservices/2011/OrganizationData.svc/SystemUserSet" $SystemUserInfo = @{ DomainName="$($UserName)@$($SystemUserDomain)" FirstName=$FirstName LastName=$LastName BusinessUnitId=@{LogicalName="businessunit";Id=$BusinessUnitId} } $assembly = [Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions") $json=new-object System.Web.Script.Serialization.JavaScriptSerializer $SystemUserInfoData=$json.Serialize($SystemUserInfo) $http_request = New-Object -ComObject Msxml2.XMLHTTP $http_request.open('POST', $url, $false) $http_request.setRequestHeader("Accept", "application/json") $http_request.setRequestHeader("Content-Type", "application/json; charset=utf-8") $results=$http_request.send($SystemUserInfoData) if ($MyDebug){ $http_request.statusText $http_request } $SystemUserId=$($json.DeserializeObject($http_request.responseText)).d.SystemUserId return $SystemUserId }
Are you passing the business unit id GUID as a string with hyphens? How are you getting the BU GUID? does that come off the BU link properties? I presume the BU logical name is “My Business Unit”?
Is a “SystemUser” just a CRM User?
yes
Yes hyphens. I looked at the existing users in the REWST view:
http://your.servername.com/OrgName/xrmservices/2011/OrganizationData.svc/SystemUserSet?$select=BusinessUnitId
Hey jbmurphy, i am very interest in getting this working in my organization.. first, is it possble to management roles through your script? second, are all the variables pass in the command line; example
CRM-CreateSystemUser “”john”,”thompson”. is businessunitid and systemuserdomain defined within the script, or command line? Thanks!