Create New records in Account entity using power shell script in dynamic 365.

 

First we need to install PowerShell Microsoft.Xrm.Data.PowerShell module for the current user blow executing below script.

Install-Module Microsoft.Xrm.Data.PowerShell -Scope CurrentUser


Next, we need to run below lines of script.

This command sets the execution policy for PowerShell scripts to RemoteSigned for the current user scope.

Set-ExecutionPolicy –ExecutionPolicy RemoteSigned –Scope CurrentUser


1.      This command sets the security protocol used by the .NET framework for network communications to TLS 1.2.

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12


To connect to connect to specific environment we need write blow lines of script with username and password and environment URL as shown below.

$Username="XXXXXXXXXX"

$Password="XXXXXXX"

$pwd = ConvertTo-SecureString $Password -AsPlainText -Force

$credentials = New-Object System.Management.Automation.PSCredential($Username, $pwd)

$conn = Connect-CrmOnline -Credential $credentials -ServerUrl "https://org18828102.crm5.dynamics.com/" -ForceOAuth


Once above script run successfully to check CRM is connected, we need run $conn.

If CRM is connect, we will get IsReady is true. Please refer below screen short.


Next to create record in CRM Account entity we need fellow below format.

Syntax:

    New-CrmRecord [-conn <CrmServiceClient>] [-EntityLogicalName] <String> [-Fields] <Hashtable> [<CommonParameters>]

 

Ex:        

$parentId = New-CrmRecord account @{"name"="parent account name"}

$parentReference = New-CrmEntityReference -EntityLogicalName account -Id $parentId

New-CrmRecord -conn $conn -EntityLogicalName account -Fields @{"name"="Test Account";"industrycode"=New-CrmOptionSetValue -Value 1;"parentaccountid"=$parentReference; "overriddencreatedon"=[datetime]"2000-01-01"}



Thank you...!








Comments

Popular posts from this blog

Create Data Package file to Import Or Export CRM records.

Receive Incoming Message in Twilio using Power Automate

How to implement approval in Teams using Adaptive Cards

Azure Function to Read Incoming Message in Twilio

Execute CRUD operations within the Power Platform using a Canvas App