microsoftgraph / powershell-intune-samples

This repository of PowerShell sample scripts show how to access Intune service resources. They demonstrate this by making HTTPS RESTful API requests to the Microsoft Graph API from PowerShell.
MIT License
1.35k stars 656 forks source link

DeviceConfiguration_Import_FromJSON.ps1 #271

Open davenish opened 5 months ago

davenish commented 5 months ago

DeviceConfiguration_Import_FromJSON.ps1 is no longer working

charliedontsurf commented 4 months ago

Not OP but when I run DeviceConfiguration_Import_FromJSON.ps1

Please specify your user principal name for Azure Authentication: ga@redacted.onmicrosoft.com

Checking for AzureAD module... AzureAD PowerShell module not found, looking for AzureADPreview Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\Program Files\WindowsPowerShell\Modules\AzureADPreview\2.0.2.183\Microsoft.IdentityModel.Clients.ActiveDirectory.dll' or one of its dependencies. The system cannot find the file specified." At C:\Users\Mikey\Desktop\DeviceConfiguration\DeviceConfiguration_Import_FromJSON.ps1:87 char:1

Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\Program Files\WindowsPowerShell\Modules\AzureADPreview\2.0.2.183\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll' or one of its dependencies. The system cannot find the file specified." At C:\Users\redacted\Desktop\DeviceConfiguration\DeviceConfiguration_Import_FromJSON.ps1:89 char:1

Cannot find type [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext]: verify that the assembly containing this type is loaded.

andreea1987 commented 1 month ago

@charliedontsurf To fix that error just run Install-Module -Name AzureAD -RequiredVersion 2.0.2.140 and Install-Module -Name Microsoft.Graph Now I’m getting a different error, seems like the script is incomplete. Test-Path : Cannot bind argument to parameter 'Path' because it is an empty string. At C:\Intune\DeviceConfiguration_Import_FromJSON.ps1:317 char:21 + If (Test-Path -Path $FileName -Type Leaf) { + ~~~ + CategoryInfo : InvalidData: (:) [Test-Path], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.Test PathCommand You cannot call a method on a null-valued expression. At C:\Intune\DeviceConfiguration_Import_FromJSON.ps1:324 char:1 + $ImportPath = $ImportPath.replace('"','') + ~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Test-Path : Cannot bind argument to parameter 'Path' because it is an empty string. At C:\Intune\DeviceConfiguration_Import_FromJSON.ps1:326 char:16 + if(!(Test-Path "$ImportPath")){ + ~~~ + CategoryInfo : InvalidData: (:) [Test-Path], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.Test PathCommand Get-Content : Cannot bind argument to parameter 'Path' because it is an empty string. At C:\Intune\DeviceConfiguration_Import_FromJSON.ps1:337 char:17 + $JSON_Data = gc "$ImportPath" + ~~~ + CategoryInfo : InvalidData: (:) [Get-Content], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.GetC ontentCommand ConvertFrom-Json : Cannot bind argument to parameter 'InputObject' because it is null. At C:\Intune\DeviceConfiguration_Import_FromJSON.ps1:340 char:30 + $JSON_Convert = $JSON_Data | ConvertFrom-Json | Select-Object -Proper ... + ~~~~~~ + CategoryInfo : InvalidData: (:) [ConvertFrom-Json], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertFrom JsonCommand

humphreysl commented 1 week ago

I too am having the same issue. This is preventing me from importing the NCSC recommended baselines in to my Tenant. The DeviceConfiguration_Import_FromJSON.ps1 script no longer works, and I have no idea how to import their JSON profiles in to my Tenant: https://github.com/ukncsc/Device-Security-Guidance-Configuration-Packs#microsoft-endpoint-manager

humphreysl commented 1 week ago

I too am having the same issue. This is preventing me from importing the NCSC recommended baselines in to my Tenant. The DeviceConfiguration_Import_FromJSON.ps1 script no longer works, and I have no idea how to import their JSON profiles in to my Tenant: https://github.com/ukncsc/Device-Security-Guidance-Configuration-Packs#microsoft-endpoint-manager

FYI - Resolution

It seems the instructions are not very helpful, but if you unpick the PS Script, you will notice a comment that states to create an App Registration in Azure and provide the Client ID to the PS Script. If you use the specific AzureAD Module version listed in this thread, and then create an App Registration in Azure, set the App Registration to use the Redirect URI as per the Script, and grant the App Registration the MS Graph Permission "DeviceManagementConfiguration.ReadWrite.All" as required by the Script, you will be able to import JSON Profiles.