Thursday, March 9, 2017

removing crm sqlserver databases via powershell

While installing CRM server, I needed to start over. To start over, I needed to remove the two databases that CRM creates inside of SQLServer.
To do this, I used powershell to your <your org's name_MSCRM>:
import-module sqlps -DisableNameChecking;
[string]$mach = $env:COMPUTERNAME;
[string]$sql_instance = 'default';

[Microsoft.SqlServer.Management.Smo.Server]$s = get-item "sqlserver:\sql\$mach\$sql_instance";
IF ($s.Databases["CRMDEMO_MSCRM"]) {
    $s.KillDatabase("CRMDEMO_MSCRM");
}
$s.KillDatabase("MSCRM_CONFIG");
$s = $null;
I also needed to configure CRM or IFD:
# configure CRM IFD. Still need to add rules to ADFS if not already added
Add-PSSnapin Microsoft.Crm.PowerShell

$ifd = Get-CrmSetting -SettingType "IfdSettings"

$ifd.Enabled = $true
$ifd.DiscoveryWebServiceRootDomain = "dev.demo.local:444"
# must be a sub-domain so just use auth.<...>
$ifd.ExternalDomain = "auth.demo.local:444"
$ifd.OrganizationWebServiceRootDomain= "demo.local:444"
$ifd.WebApplicationRootDomain = "demo.local:444"

set-crmsetting $ifd