- Create a new PowerShell script in the c:Temp folder called SolutionMonitor.ps1.
- Copy the following code to your script:
param (
[string]$solutionShortName = "Packt",
[string]$versionFileName = "C: empversion.txt",
[string]$username = "@.onmicrosoft.com",
[string]$password = "",
[string]$exportLocation = "C: emp",
[string]$instance = "https://.crm.dynamics.com",
[string]$organisation = ""
)
Import-Module Microsoft.Xrm.Data.Powershell
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential ($username, $securePassword)
$connection = Get-CrmConnection -Credential $credentials -ServerUrl $instance -OrganizationName $organisation
$solution = Get-CrmRecords -EntityLogicalName solution -FilterAttribute uniquename -FilterOperator "eq" -FilterValue $solutionShortName -Fields friendlyname,version -conn $connection
If ($solution.Count -ne 1) {
Write-Error "The number of retuned solutions is not correct. Expected 1, returned $($solution.Count)"
exit 1
}
$latestVersion = $solution.CrmRecords[0].version
$oldVersion = Get-Content $versionFileName
if($latestVersion -eq $oldVersion){
Write-Host "Latest version matched previous version. Terminating script."
exit 0
}
Export-CrmSolution $solutionShortName $exportLocation -conn $connection
$latestVersion > $versionFileName
- Launch Windows Task Scheduler.
- Right-click on Task Scheduler (Local) and click on Create Task... with the following details:
- Under the General tab: Name as Dynamics 365 Packt Solution Export
- Under the Trigger tab: Click on New
- Under Settings, select Daily.
- In Advanced settings, tick Repeat task every and select 1 hour.
- Under the Actions tab, click on New
- In Action, select Start a program
- In Program/script, type Powershell.exe
- In Add arguments (optional), type -ExecutionPolicy Bypass C:TempSolutionManager.ps1
..................Content has been hidden....................
You can't read the all page of ebook, please click
here login for view all page.