Tuesday, November 26, 2013

PowerShell ‘cmdlets’ execution sequence for Dynamics CRM

Below is the outline of how Microsoft Dynamics CRM PowerShell ‘cmdlets’ sequence. The steps\stages are explained below in detail.

Step 1 : Register Microsoft Dynamics CRM PowerShell Snap-in

CRM 2013 provides the rich feature of executing of PowerShell cmdlets from a remote machine. By default cmdlets are installed in CRM Server during installation, but while executing from remote machine these cmdlets will not be available and hence we need to explicitly register it.

Below is the syntax to register Microsoft.Crm.PowerShell.dll using installutil.exe

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe "C:\Program Files\Microsoft Dynamics CRM\Tools\Microsoft.Crm.PowerShell.dll"

Step 2 : Add 'Microsoft.Crm.PowerShell' Snap-in

Once Microsoft.Crm.PowerShell.dll is registered, we need to add PowerShell Snap-in to the current session. After the snap-in are added, you can use the cmdlets and providers that the snap-in support in the current session.

Below is the syntax to add "Microsoft.Crm.PowerShell" Snap-in to the current session. 

Add-PSSnapin "Microsoft.Crm.PowerShell"

Step 3 : Execute Cmdlets

By adding the snap-in to the current session we are ready to execute our cmdlets and providers that the snap-in support. By default 26 cmdlets are provided in "Microsoft.Crm.PowerShell" Snap-in which can be executed out-of-box.

Below is the syntax for executing an sample CRM cmdlets (Get-CRMServer).

Get-CrmServer -Name "MachineName"

Step 4 : Remove 'Microsoft.Crm.PowerShell' Snap-in

The Remove-PSSnapin cmdlet removes a Windows PowerShell snap-in from the current session. You can use it to remove snap-ins that you have added to Windows PowerShell, but you cannot use it to remove the snap-ins that are installed with Windows PowerShell.
After a snap-in is removed from the current session, it is still loaded, but the cmdlets and providers in the snap-in are no longer available in the session.
Below is the syntax to remove "Microsoft.Crm.PowerShell" Snap-in to the current session. 
Remove-PSSnapin "Microsoft.Crm.PowerShell"

Step 5 : Unregister Microsoft Dynamics CRM PowerShell Snap-in

We can unregister the installed CRM snap-in once after cmdlets are executed and span-ins are removed. 

Below is the syntax to unregister Microsoft.Crm.PowerShell.dll using installutil.exe

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /U "C:\Program Files\Microsoft Dynamics CRM\Tools\Microsoft.Crm.PowerShell.dll"

No comments:

Post a Comment