Compartilhar via


Create an organization (PowerShell)

 

Applies To: 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

Administer the deployment using Windows PowerShell
Examples of Windows PowerShell commands
Get and set deployment configuration settings
Add a deployment administrator (PowerShell)
Configure web address settings (PowerShell)
Configure IFD settings (PowerShell)
Configure claims settings (PowerShell)
Delete a deployment administrator

© 2016 Microsoft Corporation. All rights reserved. Copyright