In this post, we will see how to use PowerShell to change some values for Microsoft Dynamics 365.
First, add the PowerShell snap-in for the CRM module: https://msdn.microsoft.com/en-us/library/gg197664(v=crm.6).aspx
1
Add-PSSnapin Microsoft.Crm.PowerShell
If you would like to learn more about how to work with SSRS PowerShell so we can remap SSRS or SQL Server Reporting Server Database to an existing DB, and also how to restore SSRS encryption key, have a look at the this post.
Get the current CRM Server information: https://docs.microsoft.com/en-us/powershell/module/microsoft.crm.powershell/get-crmserver?view=dynamics365ce-ps
1
Get-CrmServer
The information of the current CRM Server will be displayed.
By default, this will connect to the current CRM server URL. So it looks at the address in the Deployment manager address for (Deployment Web Service) as shown in the image below (Dynamics 365 Deployment Manager). If you want to pass the CRM address, you need to provide it as a parameter (-DwsServerUrl) for that command.
1
Get-CrmServer -DwsServerUrl "http://localhost" -Credential "mradwan"
Remember, because I use -DwsServerUrl, I have to provide the credential parameter as well. If I put only the username, it will prompt for the password:
Get-CrmServer-DwsServerUrl-Credential
Get-CrmServer -DwsServerUrl -Credential prompt for password
If you want to send the credential without prompting for the password, you need to declare a variable to hold the credential object and use a secure string:
1
2
3
4
5
6
7
8
9
$username = 'localdomain\mradwan'
$password = ConvertTo-SecureString "mypassword" -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $password
```powershell
$username = 'localdomain\mradwan'
$password = ConvertTo-SecureString "my password" -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -ArgumentList $username, $password
Now call the same command but instead of send the user name for credential parameter to send the credential object
1
Get-CrmServer -DwsServerUrl "http://localhost" -Credential $cred
This is how it looks like when I display what is inside the credential object:
- We can also Disable or Enable CRM Organization
1
2
3
Disable-CrmOrganization "OrgnizationName"
Enable-CrmOrganization "OrgnizationName"
You can see this videoif you would like to find more information about an introduction and overview of a series of videos about Microsoft Dynamics development. This includes an overview of the Microsoft Dynamics CRM itself, installing Microsoft Dynamics 2016 on Azure VM and how to upgrade to Dynamics 365, how to develop Dynamics CRM plugins, how to debug Microsoft Dynamics CRM projects, create and run unit tests using FakeXRMEasy and Microsoft Fakes, JavaScript and front-end unit tests as well as code quality using JSHint, and how to create and run UI tests. It also covers how to integrate all the practices as part of CI/CD (Continuous Integration and Continuous Delivery).
- Get the current CRM Server settings here
1
Get-CrmSetting
It will ask me which settings I want.
If I pass “WebAddressSettings”, it will show me all the addresses in the Deployment Manager address.
Tip: If you would like to learn more about how to create a new Dynamics 365 CRM environment locally with Windows Server 2016 Standard Edition, then prepare this machine to be ready to upload to the cloud (Azure), upload the machine to Azure, and create an image of that machine. After that, we will start using this image for creating a new virtual machine with Dynamics 365 and reconfigure the machine to fix all the problems caused by changing the hard disk and the machine name, which will cause problems for SSRS (SQL Server Reporting Server). All IIS application pools crashed, the SQL Server name crashed, and of course, Dynamics 365 CRM doesn’t work. I will show exactly how to solve all those problems so we can have a new copy of an existing Dynamics CRM machine and make it work fine. Have a look at this post.
Remember, if I don’t provide an address to any of those PowerShell commands, it will use the one in the Deployment Manager address for (Deployment Web Service).
More Info: If, after adding a new user to Dynamics 365, you get the following error: You do not have permissions to see this view. Contact a system administrator crm, have a look at this post.
Import CRM organization
https://technet.microsoft.com/en-us/library/dn833059 we can use Import-CrmOrganization to import a Microsoft Dynamics 365 organization database into the deployment.
1
2
3
4
5
6
7
$OrganisationName = "TestOrg"
$DatabaseName = "$($OrganisationName)_MSCRM"
$SrsUrl = "http://$env:computername/ReportServer
$SqlServerName = $env:computername
$DwsServerUrl = "http://$env:computername.ad.devopsvisions.com"
$UserMappingMethod1 = "ByAccount"
$UserMappingMethod2 ="ByMappingXmlFile"
So we can see that we have different ways ! For user mapping which map the users in the imported organization to the users in the current deployment. ByAccount, which means the same accounts on both directions
1
2
Import-CrmOrganization -SqlServerName $SqlServerName -DatabaseName $DatabaseName -SrsUrl $SrsUrl -DisplayName
$DisplayName -Name $Name -UserMappingMethod $UserMappingMethod -Credential $cred -DwsServerUrl $DwsServerUrl
-� ByMappingXmlFile. which means we will have XML file that mapp each account to another account and domain to other domain if needed.
1
2
Import-CrmOrganization -SqlServerName $SqlServerName -DatabaseName $DatabaseName -SrsUrl $SrsUrl
-DisplayName $DisplayName -Name $Name -UserMappingMethod $UserMappingMethod -UserMappingXmlFile $pathToFile -Credential $cred -DwsServerUrl $DwsServerUrl