Export (0) Print
Expand All

Create an organization (PowerShell)

Dynamics CRM 2013

Applies To: Microsoft Dynamics CRM 2013

This sample code is for Microsoft Dynamics CRM 2013. Download the Microsoft Dynamics CRM SDK package. It can be found in the following location in the download package:

SampleCode\PS1\CreateOrg.ps1

Requirements

To set up the Microsoft Dynamics CRM PowerShell cmdlets, see Administer the deployment using Windows PowerShell.

Demonstrates

The following script will create a partner-hosted organization (IFD). You must specify the following parameters:

DisplayName

SqlServerName

SrsUrl

Example

Function createorg{
param
(
   #required params
    [string]$DisplayName ="Testorgan",
    [string]$SqlServerName = $env:COMPUTERNAME,
    [string]$SrsUrl = "http://$SqlServerName/reportserver",
    
    #optional params (can accept nulls)
    [string]$Name,
    [string]$BaseCurrencyCode,
    [string]$BaseCurrencyName,
    [string]$BaseCurrencySymbol,
    [string]$BaseCurrencyPrecision,
    [string]$BaseLanguageCode,
    [string]$SqlCollation,
    [string]$SQMOptIn,
    [string]$SysAdminName,
    [switch]$WaitForJob=$True
)

$RemoveSnapInWhenDone = $False

if (-not (Get-PSSnapin -Name Microsoft.Crm.PowerShell -ErrorAction SilentlyContinue))
{
    Add-PSSnapin Microsoft.Crm.PowerShell
    $RemoveSnapInWhenDone = $True
}


$opId = New-CrmOrganization -DisplayName $DisplayName -SqlServerName $SqlServerName -SrsUrl $SrsUrl -Name $Name -BaseCurrencyCode $BaseCurrencyCode -BaseCurrencyName $BaseCurrencyName -BaseCurrencySymbol $BaseCurrencySymbol -BaseCurrencyPrecision $BaseCurrencyPrecision -BaseLanguageCode $BaseLanguageCode -SqlCollation $SqlCollation -SQMOptIn $SQMOptIn -SysAdminName $SysAdminName
$opId


if($WaitForJob)
{
    $opstatus = Get-CrmOperationStatus -OperationId $opid
    while($opstatus.State -eq "Processing")
    {
        Write-Host [(Get-Date)] Processing...
        Start-Sleep -s 30
        $opstatus = Get-CrmOperationStatus -OperationId $opid
    }

    if($opstatus.State -eq "Failed")
    {
        Throw ($opstatus.ProcessingError.Message)
    }

    Write-Host [(Get-Date)] Create org completed successfully.
}
else
{
    Write-Host [(Get-Date)] Create org async job requested.
}

if($RemoveSnapInWhenDone)
{
    Remove-PSSnapin Microsoft.Crm.PowerShell
}
}

See Also

Send comments about this article to Microsoft.

© 2014 Microsoft Corporation. All rights reserved.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft