MSEndpointMgr / IntuneAppFactory

Intune App Factory automates Win32 application packaging in Intune.
https://msendpointmgr.com/intune-app-factory
MIT License
32 stars 12 forks source link

Custom Requirement Rules Script Files not processed during Prepare-AppPackageFolder #13

Open PZan opened 9 months ago

PZan commented 9 months ago

I realize the documentation states that the section "CustomRequirementRule" will be further documented in the future, but I went ahead and defined the required variables in a app.json file as this was desired in my particular case for Dell Command | Update. (My custom requrement rule variables and values where based off of the expected variables in the switch statement starting on line 350 of New-Win32App.ps1)

When New-Win32App.ps1 is running and has app.json has custom requirement rule script files defined, the pipeline will fail because the script file is missing in the Scripts folder. After investigating this my conclusion is that the Prepare-AppPackageFolder.ps1 should process each custom requirement rule with script files while processing "app.json" (line 110) in the switch statement.

Adding the following to line 110 in Prepare-AppPackageFolder.ps1 did the trick for me:

# Copy custom requirement rule script files to script destination folder
foreach ( $CustomRequirementRuleScript in $($AppFileContent.CustomRequirementRule | Where-Object {$_.Type -eq "Script" } ) ) {
    # Create the Scripts folder in the app package folder in the publish root folder
    $AppPublishScriptsFolderPath = Join-Path -Path $AppPublishFolderPath -ChildPath "Scripts"

    $ScriptFileSource = Join-Path $AppPackageFolderPath -ChildPath $CustomRequirementRuleScript.ScriptFile
    $ScriptFileDestination = Join-Path -Path $AppPublishScriptsFolderPath -ChildPath $CustomRequirementRuleScript.ScriptFile

    if (-not(Test-Path -Path $AppPublishScriptsFolderPath)) {
        try {
            $null = New-Item -Path $AppPublishScriptsFolderPath -ItemType "Directory" -Force -Confirm:$false   
        }
        catch [System.Exception] {
            Write-Warning "Failed to create folder [$AppPublishFolderPath] with message: [$($_.Exception.Message)]"
        }
    }

    try {
        Write-Output "Copying custom requirement rule script file from: [$ScriptFileSource] to: [$ScriptFileDestination]"
        $null = Copy-Item -Path $ScriptFileSource -Destination $ScriptFileDestination -Force -ErrorAction Stop
    }
    catch [System.Exception] {
        Write-Warning "Failed to copy custom requirement rule script with message: [$($_.Exception.Message)]"
    }
}
NickolajA commented 2 weeks ago

Makes total sense. It's been on the to do list to complete this part, so thanks for sharing your code! Will add it to 1.2.0 👍