Skip to main content

Notifications

Customer Service forum

how to connect powershell with CRM online ?

Posted on by 235

I m writing a powershall script where it need to be connected to CRM online.

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

is there a way to connect using connection string ? please share sample code/ script i m new to powershell.

I m using Microsfot.Xrm.Data.PowerShell

thank you.


Categories:
  • bigjig Profile Picture
    bigjig 135 on at
    RE: how to connect powershell with CRM online ?

    You can also use the below if you have MFA enabled or the best way is to register an app and use the client secret to connect via OAuth

    $cred = Get-Credential

    $serverhost ="xxxxxxxx.dynamics.com"

    $conn = Connect-CrmOnline -Credential $cred -ServerUrl $serverhost -ForceOAuth

  • RE: how to connect powershell with CRM online ?

    I currently have this ps script

    $user = "user@domain.com"

    $passwordConverted = ConvertTo-SecureString "password" -AsPlainText -Force

    $cred = New-Object System.Management.Automation.PSCredential ($user, $passwordConverted)

    $serverhost = "yourcustomername.crm.dynamics.com"

    $connection = Connect-CrmOnline -Credential $cred -ServerUrl $serverhost

    Write-Host "Connection info $connection"

    $connection | Get-Member

    I hope it will be useful for you!

  • umma Profile Picture
    umma 235 on at
    RE: how to connect powershell with CRM online ?

    For online these links suggest $Cred variable, it only works if user has already loged in. For running a script it will not work becasue it uses a UI to login and i m looking to automate.

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: how to connect powershell with CRM online ?

    Hi,

    Refer this article. - docs.microsoft.com/.../use-powershell-cmdlets-xrm-tooling-connect

    Some more details - docs.microsoft.com/.../overview

    Hope this helps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,900 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,297 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans