Welcome to MSDN Blogs Sign in | Join | Help
Using Powershell and Dynamics CRM

If you want to use Dynamics CRM Web Service with Powershell and be able to Create, Update, Extract Data …

You have simply to create an assembly with wsdl utility and load it in Powershell.

Let’s try:

Make sure that you have access to Csharp compiler, for example by launching first cmd from Visual Studio command prompt menu.

Type

wsdl “http://<your servername>/MSCRMServices/2007/CrmService.asmx

This will create a file called CrmService.csc

Compile the file:

csc /target:library CrmService.csc

Launch Powershell

powershell

Load the dll

 $currentpath = pwd

 [void][System.Reflection.Assembly]::LoadFile([System.IO.Path]::Combine($currentPath,"CrmService.dll"))

Create CrmService Object

 $Crm = new-object "CrmService"

Connect to Crm Server

 $token = new-object CrmAuthenticationToken

 $tokenAuthenticationType=0

 $Token.OrganizationName = "<your business unit name>" # for example “CRMVPC” if you user RC0 VPC 4.0

 $Crm.Url = "http://<your servername>/MSCRMServices/2007/CrmService.asmx"

 $Crm.CrmAuthenticationTokenValue = $token

 $CrmCredentials = [System.Net.CredentialCache].DefaultCredentials

 For the rest just use SDK Documentation

For example:

$contact = new-object "contact"

 $contact.lastname = "Smith"

 $id = $Crm.Create($contact)

If you type $id you must get the GUID created by CRM – Check now that the contact has been created in CRM.

If you have any question contact me xcourchi@microsoft.com.

Enjoy CRM 4.0 and Powershell !!!

 

 

Posted: Monday, December 03, 2007 11:19 PM by Xavier Courchinoux
Filed under: ,

Comments

East Region Microsoft CRM said:

This is a VERY slick post by Xavier. PowerShell is a scripting language that allows you to do a bunch

# December 4, 2007 9:01 AM

Noticias externas said:

This is a VERY slick post by Xavier. PowerShell is a scripting language that allows you to do a bunch

# December 4, 2007 9:17 AM
Anonymous comments are disabled
Page view tracker