-
Notifications
You must be signed in to change notification settings - Fork 2
/
Install-CompanyPortal.ps1
74 lines (52 loc) · 3.2 KB
/
Install-CompanyPortal.ps1
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<#
.SYNOPSIS
Automatically installs the Company Portal app
Most of this code is is by Oliver Kieselbach from his excellent blog post
https://oliverkieselbach.com/2020/04/22/how-to-completely-change-windows-10-language-with-intune/
.NOTES
Author: Andrew Cooper
Twitter: @adotcoop
.LINK
https://github.com/adotcoop/Intune
.DESCRIPTION
This script provides a way to automatically install the Company Portal app.
The inspiration for this script came after watching the Greg Shields' Pluralsight course on Intune where
it appears that the only current mechanism to autodeploy the Company Portal is through Microsoft Store for
Business. MSfB appears to have been deprecated (https://twitter.com/concentratdgreg/status/1246133337200062464).
Oliver Kieselbach details how to use the MDM Bridge WMI Provider to force a store app install in his blog post
https://oliverkieselbach.com/2020/04/22/how-to-completely-change-windows-10-language-with-intune/
The MDM Bridge provider appears to allow any store app to be installed automatically provided you know the
applicationID. The applicationID can be found at the end of the store URL. For example, here is the Company
Portal URL
https://www.microsoft.com/en-gb/p/company-portal/9wzdncrfj3pz
I can't improve on Oliver's code, so the credit for this method of store app deployment should go to him.
#>
$applicationId = "9wzdncrfj3pz"
$skuId = 0016
$webpage = Invoke-WebRequest -UseBasicParsing -Uri "https://bspmts.mp.microsoft.com/v1/public/catalog/Retail/Products/$applicationId/applockerdata"
$packageFamilyName = ($webpage | ConvertFrom-JSON).packageFamilyName
# you can specify the packageFamilyName if already known
#$packageFamilyName = 'Microsoft.CompanyPortal_8wekyb3d8bbwe'
# All of the below code is by Oliver Kieselbach
$namespaceName = "root\cimv2\mdm\dmmap"
$session = New-CimSession
$omaUri = "./Vendor/MSFT/EnterpriseModernAppManagement/AppInstallation"
$newInstance = New-Object Microsoft.Management.Infrastructure.CimInstance "MDM_EnterpriseModernAppManagement_AppInstallation01_01", $namespaceName
$property = [Microsoft.Management.Infrastructure.CimProperty]::Create("ParentID", $omaUri, "string", "Key")
$newInstance.CimInstanceProperties.Add($property)
$property = [Microsoft.Management.Infrastructure.CimProperty]::Create("InstanceID", $packageFamilyName, "String", "Key")
$newInstance.CimInstanceProperties.Add($property)
$flags = 0
$paramValue = [Security.SecurityElement]::Escape($('<Application id="{0}" flags="{1}" skuid="{2}"/>' -f $applicationId, $flags, $skuId))
$params = New-Object Microsoft.Management.Infrastructure.CimMethodParametersCollection
$param = [Microsoft.Management.Infrastructure.CimMethodParameter]::Create("param", $paramValue, "String", "In")
$params.Add($param)
try {
# we create the MDM instance and trigger the StoreInstallMethod
$instance = $session.CreateInstance($namespaceName, $newInstance)
$result = $session.InvokeMethod($namespaceName, $instance, "StoreInstallMethod", $params)
}
catch [Exception] {
write-host $_ | out-string
}
Remove-CimSession -CimSession $session