/
ImportSettingsCatalogsFromJson.ps1
46 lines (40 loc) · 1.98 KB
/
ImportSettingsCatalogsFromJson.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
Write-Host -ForegroundColor DarkYellow "Checking for log directory C:\temp for transcript"
$LogPath = "C:\Temp"
$LogPathExists = Test-Path $LogPath
If ($LogPathExists -ne $True) {
New-Item -Path "C:\" -Name Temp -ItemType Directory
}
Start-Transcript -Path $LogPath\SettingsCatalogImport.log -Force
Write-Host -ForegroundColor DarkYellow "Installing Required Modules"
if (Get-Module -ListAvailable -Name "Microsoft.Graph.Authentication") {
Write-Host -ForegroundColor Yellow "Microsoft.Graph.Authentication Module is already installed"
}
else {
Write-Host -ForegroundColor Yellow "Installing the Microsoft.Graph.Authentication Module for Current User"
Install-Module -Name Microsoft.Graph.Authentication -Scope CurrentUser -Force
Write-Host "Installed Microsoft.Graph.Authentication Module"
}
if (Get-Module -ListAvailable -Name Microsoft.Graph.Beta.DeviceManagement) {
Write-Host -ForegroundColor Yellow "Microsoft.Graph.Beta.DeviceManagement Module is already installed"
}
else {
Write-Host -ForegroundColor Yellow "Installing the Microsoft.Graph.Beta.DeviceManagement Module for Current User"
Install-Module -Name Microsoft.Graph.Beta.DeviceManagement -Scope CurrentUser -Force
Write-Host "Installed Microsoft.Graph.Beta.DeviceManagement Module"
}
$scopes = "DeviceManagementConfiguration.ReadWrite.All"
Connect-MgGraph -Scopes $Scopes
$profiles = Get-ChildItem .\ -Filter '*.json'
Try {
ForEach ($profile in $profiles) {
$json = Get-Content $profile | ConvertFrom-Json | Select-Object -Property Name,Description,Platforms,roleScopeTagIds,settings,technologies -ErrorAction Continue
$JsonConverted = ConvertTo-Json $json -Depth 20 -ErrorAction Continue
New-MgBetaDeviceManagementConfigurationPolicy -BodyParameter $jsonconverted -ErrorAction Continue
}
}
Catch {
Write-Host -ForegroundColor Red "Error while importing one or more setting profiles"
Write-Host -ForegroundColor Red $_
}
Disconnect-MgGraph
Stop-Transcript