Microsoft Dynamics CRM 2011 – PowerShell scripts to enable and disable Tracing


Windows PowerShell enables you to easily run deployment commands without writing code using the Deployment Web service. To execute commands, you must first configure Microsoft Dynamics CRM 2011 with Windows PowerShell.

My blog describes scripts to enable and disable tracing for Microsoft Dynamics CRM 2011.

The script is verified on the following Windows platforms:

  • Windows Server 2008 R2
  • Windows Server 2008

These are PowerShell scripts. You can copy the script into a text editor and save the file as a PowerShell file. PowerShell file has an extension of ps1.

I have saved these scripts as ‘EnableTracing.ps1’ and ‘DisableTracing.ps1’. To enable tracing run the script “EnableTracing.ps1”. To disable tracing run the script “DisableTracing.ps1”.

You can save these PowerShell scripts (files) to your server. Microsoft Dynamics CRM administrators and professionals can quickly enable or disable tracing by simply running these files.

The Script (File ‘EnableTracing.ps1’)

# —————————————-
# Script Definition: Script Definition: This script will enable the trace for Microsoft Dynamics CRM 2011.
# —————————————-
add-pssnapin Microsoft.CRM.Powershell
Get-CrmSetting TraceSettings
$setting = Get-CrmSetting TraceSettings
$setting.Enabled=”True”
Set-CrmSetting $setting
Get-CrmSetting TraceSettings
read-host ‘The trace is now enabled. Press enter key to close this window. . .’

The Script (File ‘DisableTracing.ps1’)

# —————————————-
# Script Definition: This script will disable the trace for Microsoft Dynamics CRM 2011.
# —————————————-
add-pssnapin Microsoft.CRM.Powershell
Get-CrmSetting TraceSettings
$setting = Get-CrmSetting TraceSettings
$setting.Enabled=””
Set-CrmSetting $setting
Get-CrmSetting TraceSettings
read-host ‘The trace is now disabled. Press enter key to close this window. . .’

Note: Sometimes when you run a PowerShell file, for first time, it might open in Notepad. In order to open a PowerShell file with a PowerShell application, associate the file (with extension ps1) with C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

I hope this blog about ‘Microsoft Dynamics CRM 2011 – PowerShell scripts to enable and disable Tracing’ was informative. Please feel free to leave your comments.

Advertisements
Post a comment or leave a trackback: Trackback URL.

Comments

  • johnthepro  On June 30, 2012 at 2:15 AM

    Hey just curious, but what do you suggest I do if after adding the CRM plugin to PowerShell, when I run ANY command it errors and says “Could not establish trust relationship for the SSL secure channel”

    What gives?

    • Ashish Mahajan  On June 30, 2012 at 11:00 AM

      Is your Microsoft Dynamics CRM instance running on HTTPS?

      • johnthepro  On July 1, 2012 at 4:07 PM

        Yes definitely. Its an IFD only deployment. Even when ran on the server it happens.

  • johnthepro  On December 5, 2012 at 5:40 AM

    Just wanted to update this post for you. When you’re in an IFD environment, IF your SSL name does not match your internal server/domain name, you’ll get this error.

    You can run a command in PowerShell to force it to ignore the mismatch during that session. Great workaround when using a split-DNS configuration.

    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

    ^ Running that command in PowerShell BEFORE interacting with your CRM deployment should work!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: