-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathD365BCAppSourceUpdatesNotifications.ps1
More file actions
58 lines (55 loc) · 2.21 KB
/
D365BCAppSourceUpdatesNotifications.ps1
File metadata and controls
58 lines (55 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
##########################################################################################
# Checks for available updates for AppSource apps installed on a given tenant
##########################################################################################
$clientid = "YOUR_CLIENT_ID"
$clientsecret = "YOUR_CLIENT_SECRET"
$scope = "https://api.businesscentral.dynamics.com/.default"
$tenant = "YOUR_TENANT_ID"
$environment = "YOUR_ENVIRONMENT_NAME"
# Get access token
$token = Get-MsalToken `
-ClientId $clientid `
-TenantId $tenant `
-Scopes $scope `
-ClientSecret (ConvertTo-SecureString -String $clientsecret -AsPlainText -Force)
$accessToken = ConvertTo-SecureString -String $token.AccessToken -AsPlainText -Force
# Get available updates
$response= Invoke-WebRequest `
-Method Get `
-Uri "https://api.businesscentral.dynamics.com/admin/v2.1/applications/businesscentral/environments/$environment/apps/availableUpdates" `
-Authentication OAuth `
-Token $accessToken
if ((ConvertFrom-Json $response.Content).value.length -gt 0) {
$jsonresponse = ConvertFrom-Json $response.Content
$mailBody = "<b><u>APP UPDATES AVAILABLE:</u></b> <br>"
foreach($app in $jsonresponse.value)
{
$mailBody += "<b>App ID:</b> " + $app.id + " <b>Name:</b> " + $app.name + " <b>Publisher:</b> " + $app.publisher + " <b>Version:</b> " + $app.version + "<br>"
}
}
else {
Write-Output "NO APP UPDATES FOUND."
$mailBody = "";
}
if ($mailBody.Length -gt 0)
{
#Sending a notification email
$UserName = "YOUR_SMTP_USERNAME"
$Password = "YOUR_SMTP_PASSWORD"
$from = "YOUR_SENDING_EMAIL_ADDRESS";
$to = "YOUR_RECEIVING_EMAIL_ADDRESS";
$SecurePassword = ConvertTo-SecureString -string $password -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential -argumentlist $UserName, $SecurePassword
$EmailParams = @{
From = $from
To = $to
Subject = "APP UPDATES AVAILABLE FOR TENANT " + $tenant
Body = $mailBody
SmtpServer = "smtp.office365.com"
Port = 587
UseSsl = $true
Credential = $Cred
BodyAsHtml = $true
}
Send-MailMessage @EmailParams
}