user576510
user576510

Reputation: 5915

How to connect PowerShell with CRM online?

I am writing a PowerShell script where it needs to be connected to CRM online.

I can connect to CRM using Connect-CrmOnline where it asks for credentials using a login box. I want to automate it. Please guide on how to do it.

Is there a way to connect using connection string? Please share sample code/ script. I am new to PowerShell.

I am using Microsoft.Xrm.Data.PowerShell

Thank you.

Upvotes: 1

Views: 2699

Answers (1)

Jorg Roper
Jorg Roper

Reputation: 647

You can build a credentials object and use that in the script. For example:

$secpasswd = ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("username", $secpasswd)

You would then use it within your script with -credential $mycreds parameter

Ref: https://blogs.msdn.microsoft.com/koteshb/2010/02/12/powershell-how-to-create-a-pscredential-object/ and https://learn.microsoft.com/en-us/dynamics365/customer-engagement/developer/xrm-tooling/use-powershell-cmdlets-xrm-tooling-connect

Upvotes: 2

Related Questions