Blogger :
MSDN Blogs
All posts :
All posts by MSDN Blogs
Category :
SAP CRM
Blogged date : 2007 Dec 03
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 !!!