powershell-intune-samples icon indicating copy to clipboard operation
powershell-intune-samples copied to clipboard

DeviceConfiguration_Import_FromJSON.ps1

Open davenish opened this issue 1 year ago • 6 comments

DeviceConfiguration_Import_FromJSON.ps1 is no longer working

davenish avatar May 20 '24 07:05 davenish

Not OP but when I run DeviceConfiguration_Import_FromJSON.ps1

Please specify your user principal name for Azure Authentication: [email protected]

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

  • [System.Reflection.Assembly]::LoadFrom($adal) | Out-Null
  •   + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : FileNotFoundException
    
    

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

  • [System.Reflection.Assembly]::LoadFrom($adalforms) | Out-Null
  •   + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : FileNotFoundException
    
    

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

charliedontsurf avatar Jun 14 '24 12:06 charliedontsurf

@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

andreea1987 avatar Sep 09 '24 10:09 andreea1987

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 avatar Oct 15 '24 10:10 humphreysl

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.

humphreysl avatar Oct 18 '24 11:10 humphreysl

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.

I applied this suggested fix but it didn't change anything I still encounter an error

MethodInvocationException: C:\Users\user\OneDrive\Terraform\AVD Intune\DeviceConfiguration_Import_FromJSON.ps1:89 Line | 89 | [System.Reflection.Assembly]::LoadFrom($adal) | Out-Null | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'C:\Program Files\WindowsPowerShell\Modules\AzureADPreview\2.0.2.183\Microsoft.IdentityModel.Clients.ActiveDirectory.dll'. The | system cannot find the file specified." MethodInvocationException: C:\Users\user\OneDrive\AVD Intune\DeviceConfiguration_Import_FromJSON.ps1:91 Line | 91 | [System.Reflection.Assembly]::LoadFrom($adalforms) | Out-Null | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'C:\Program | Files\WindowsPowerShell\Modules\AzureADPreview\2.0.2.183\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll'. The system cannot find the file specified." Cannot find type [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext]: verify that the assembly containing this type is loaded.

image

dcw77 avatar Nov 25 '24 12:11 dcw77

https://github.com/microsoftgraph/powershell-intune-samples/issues/255

dcw77 avatar Nov 25 '24 12:11 dcw77