CRM 2011 and PowerShell

by Bill Owens 8. July 2011 00:40

CRM 2011 on premise versions now have a new tool to help with configuration and deployments.

I know that in my company we have many pages of documentation that shows step by step clicks and adding into CRM Deployment manager on creating Organizations, adding Administrative users, how to get license information, setting up IFD, etc.  Now with PowerShell intergration with CRM 2011 we can script these functions.

So what is PowerShell?

Wikipedia defines it as:


Windows PowerShell is Microsoft's task automation framework, consisting of a command-line shell and associated scripting language built on top of, and integrated with the .NET Framework. PowerShell provides full access to COM and WMI, enabling administrators to perform administrative tasks on both local and remote Windows systems.
In PowerShell, administrative tasks are generally performed by cmdlets (pronounced command-lets), specialized .NET classes implementing a particular operation. Sets of cmdlets may be combined together in scripts, executable (which are standalone applications), or by instantiating regular .NET classes (or WMI/COM Objects).[3][4] These work by accessing data in different data stores, like the filesystem or registry, which are made available to the PowerShell runtime via Windows PowerShell providers


I define it more like Windows Batch files on steroids. Many of us have created batch files in Windows and found it very limiting. With PowerShell you have programming logic capabilities that can access system functions as well as operations against system functions. Way too cool.

How do I get it?
First PowerShell comes with Windows Server 2008 which is advantageous because that is where we install the CRM

Server.

As part of the CRM Server install you can install the Deployment Tools role. After this role is installed you are able to add the Dynamics CRM PowerShell-Snap-In to your PowerShell session.
To use the cmdlets you have to enter following command into a PowerShell console, which adds the PowerShell-Snap-In to your active session.

Add-PSSnapin Microsoft.Crm.PowerShell


If you want to see all of the commands available you can type in

Get-Command -Module Microsoft.Crm.PowerShell 

As of 7/7/2011 here is the current lis

tPowershellcrm2011commands

If you search within the SDK you will find this list:

 

Supported PowerShell cmdlets

The following table lists the cmdlets available for use with Windows PowerShell.

Cmdlet

Description

Disable-CrmServer

Disables the specified Microsoft Dynamics CRM server.

Disable-CrmOrganization

Disables the specified Microsoft Dynamics CRM organization.

Edit-CrmOrganization

Edits properties of the specified Microsoft Dynamics CRM organization.

Enable-CrmServer

Enables the specified Microsoft Dynamics CRM server.

Enable-CrmOrganization

Enables the specified Microsoft Dynamics CRM organization.

Get-CrmOrganization

Retrieves one or all of the organizations in the deployment of Microsoft Dynamics CRM.

Get-CrmOperationStatus

Retrieves the status on asynchronous operations sitting in the deferred operation queue for Microsoft Dynamics CRM.

Get-CrmSetting

Retrieves a Microsoft Dynamics CRM deployment setting object. For a list of the settings objects, see Use Deployment Entities and Deployment Configuration Settings.

Get-CrmServer

Retrieves a server object for one or all Microsoft Dynamics CRM servers in a deployment.

Get-CrmLicenseProperty

Retrieves the license properties object for Microsoft Dynamics CRM.

Get-CrmAdvancedSetting

Gets an advanced setting value for Microsoft Dynamics CRM. The metadata specify that the setting is readable in order to retrieve the specified value.

Get-CrmAccessLicense

Retrieves the server licensing and CAL licensing information for the deployment of Microsoft Dynamics CRM.

Get-CrmDeploymentAdministrator

Retrieves the deployment administrators for the Microsoft Dynamics CRM deployment.

Get-CrmCertificate

Retrieves the certificate information for Microsoft Dynamics CRM. The certificate object contains the public key of the service bus signing certificate.

Import-CrmOrganization

Initiates the process to import a Microsoft Dynamics CRM organization database into the deployment.

New-CrmOrganization

Initiates the process to create a new organization in the Microsoft Dynamics CRM deployment.

New-CrmDeploymentAdministrator

Creates a new deployment administrator for the Microsoft Dynamics CRM deployment.

Remove-CrmOrganization

Deletes the specified organization from the Microsoft Dynamics CRM deployment.

Remove-CrmServer

Deletes the specified server from the Microsoft Dynamics CRM deployment.

Remove-CrmCertificate

Removes the specified certificate from Microsoft Dynamics CRM.

Remove-CrmDeploymentAdministrator

Removes the specified deployment administrator from the Microsoft Dynamics CRM deployment.

Set-CrmProductKey

Sets the product key for the Microsoft Dynamics CRM deployment.

Set-CrmSetting

Sets the specified Microsoft Dynamics CRM deployment wide settings. For a list of the settings objects, see Use Deployment Entities and Deployment Configuration Settings.

Set-CrmAdvancedSetting

Sets an advanced setting value for Microsoft Dynamics CRM. The metadata specify that the setting is writable in order to set the specified value.

Set-CrmCertificate

Creates a certificate record or sets the properties of an existing certificate record in the Microsoft Dynamics CRM configuration database.

Update-CrmOrganization

Updates the specified Microsoft Dynamics CRM organization with the latest patches or upgrades the organization from Microsoft Dynamics CRM 4.0 to Microsoft Dynamics CRM 2011.

So what can you do?

How about getting the licensed users on the CRM server

Get-CrmAccessLicense -LicenseName "Dynamics CRM 2011 Full CAL" -Period 0

 

userlist

 

You can deploy settings, configure IFD, claims forms, add administrative users, you pick.

the SDK offers this example

 

Example

The following shows how to use Windows PowerShell to enable tracing. This pattern can be used for all settings. For a list of the settings objects, see Use Deployment Entities and Deployment Configuration Settings.

Windows PowerShell

PS C:\Users\Administrator> Add-PSSnapin Microsoft.Crm.PowerShell

Windows PowerShell

PS C:\Users\Administrator> Get-CrmSetting TraceSettings

CallStack     : True
Categories    : *:Error
Directory     : c:\crmdrop\logs
Enabled       : False
FileSize      : 10
ExtensionData : System.Runtime.Serialization.ExtensionDataObject

Windows PowerShell 

PS C:\Users\Administrator> $setting = Get-CrmSetting TraceSettings

Windows PowerShell

PS C:\Users\Administrator> $setting.Enabled="True"

Windows PowerShell

PS C:\Users\Administrator> Set-CrmSetting $setting

Windows PowerShell

PS C:\Users\Administrator> Get-CrmSetting TraceSettings

CallStack     : True
Categories    : *:Error
Directory     : c:\crmdrop\logs
Enabled       : True
FileSize      : 10
ExtensionData : System.Runtime.Serialization.ExtensionDataObject

 

Within the SDK examples are PowerShell examples as well. Look under SDK\SampleCode\ps

 sdkexamples

How do I find out how to use these commands

You can ask for a descriptive help on each command within PowerShell. Example. I want to find out what I can do with the get-CRMSetting cmdlet.

get-help Get-CrmSetting -detailed
helpexample

 

You can also search within the SDK for PowerShell to find out more information. BTW the page “Use Deployment Entities and Deployment Configuration Settings” is a good page for the above command as well.

One Last Item

I recommend if you are using PowerShell to download PowerGUI from powergui.org

powergui

 

This has a nice editor as well as way to issue PowerShell commands as you want to see them.

Here is an Example where I added to the PowerGui the CRM PowerShell commands to show me the CRM license and All users

powerguiexample1

and here is a snapshot of the Script Editor in action

powerguiscripteditor

 

I hope that this is useful to you, I know that I have learned a lot just putting this together.

Tags: , ,

CRM 2011

Page List

About the author

I work for a consulting firm in Dublin Ohio called Affiliated Resource Group. For the last five years I have been spearheading our Microsoft Dynamics CRM practice. I have a deep appreciation for the Microsoft CRM platform and I am very excited about it. You might even describe me as a Microsoft CRM Advocate. I have many battle scars from my experience with the product and I’m constantly being asked questions about CRM and how-to-do something in it. Hence, this BLOG is to help disseminate that knowledge and information to everyone. As of last year I was posting links to many other blogs to help spread the knowledge, but now with the community.dynamics.com doing that for me, I will be following that practice unless a really juicy article catches my eye. Many people have asked where my post are for the first half of 2010, my company had me posting to another blog and maintain two was near impossible. I am now down to just this blog. So good luck and I hope that this blog may help in some way. If you have suggestions or questions, please email me them.

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2012 BillOnCRM