From 77b9c83e92cf8d4e9353198ce25d2d49db593369 Mon Sep 17 00:00:00 2001 From: Chad Simmons Date: Fri, 11 Mar 2022 09:12:37 -0600 Subject: [PATCH] Validate FileName/ImportPath Update logic to validate that the FileName and ImportPath variables are valid --- DeviceConfiguration/DeviceConfiguration_Import_FromJSON.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/DeviceConfiguration/DeviceConfiguration_Import_FromJSON.ps1 b/DeviceConfiguration/DeviceConfiguration_Import_FromJSON.ps1 index e0c508c..0015058 100644 --- a/DeviceConfiguration/DeviceConfiguration_Import_FromJSON.ps1 +++ b/DeviceConfiguration/DeviceConfiguration_Import_FromJSON.ps1 @@ -311,11 +311,15 @@ $global:authToken = Get-AuthToken -User $User #################################################### -If (Test-Path -Path $FileName -Type Leaf) { +If ($(try { [bool]([System.IO.FileInfo]$FileName) } catch { $false })) { $ImportPath = $FileName } Else { $ImportPath = Read-Host -Prompt "Please specify a path to a JSON file to import data from e.g. C:\IntuneOutput\Policies\policy.json" } +If (-not($(try { [bool]([System.IO.FileInfo]$ImportPath) } catch { }))) { + Write-Error -Exception "[$ImportPath] is not a valid file name" + exit 123 #123 (0x7B) ERROR_INVALID_NAME The filename, directory name, or volume label syntax is incorrect. +} # Replacing quotes for Test-Path $ImportPath = $ImportPath.replace('"','')