Functions/New-IntuneWin32App.ps1


function New-IntuneWin32App {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)] [string] $FolderPath,
        [Parameter()] [string] $IncludePath
    )

    if (!(Test-Path $FolderPath)) {
        New-Item $FolderPath -Force -ItemType Directory | Out-Null
    }
    $FolderPath = Resolve-Path $FolderPath
    Write-Verbose $FolderPath

    $SourceFolder = Join-Path $FolderPath "source"
    if (!(Test-Path $SourceFolder)) {
        New-Item -Path $SourceFolder -ItemType Directory -Force | Out-Null
    }



    $Files = @(
        [PSCustomObject]@{
            FileName = "source\install.cmd"
        }
        [PSCustomObject]@{
            FileName = "source\uninstall.cmd"
        }
        [PSCustomObject]@{
            FileName = "source\install.ps1"
        }
        [PSCustomObject]@{
            FileName = "source\uninstall.ps1"
        }
        [PSCustomObject]@{
            FileName = "logo.png"
        }
        [PSCustomObject]@{
            FileName = "IntuneVariables.ps1"
        }
    )


    # Intune Variables
    $JSON = @"
{
"returnCodes": [
    {
      "returnCode": 0,
      "type": "success"
    },
    {
      "returnCode": 1707,
      "type": "success"
    },
    {
      "returnCode": 3010,
      "type": "softReboot"
    },
    {
      "returnCode": 1641,
      "type": "hardReboot"
    },
    {
      "returnCode": 1618,
      "type": "retry"
    }
  ]
}
"@

    $Returncodes = $JSON | ConvertFrom-Json

    $JSON = @"
{
    "detectionRules": [
        {
            "fileOrFolderName": "msrdcw.exe",
            "detectionValue": "1.2.2223.0",
            "check32BitOn64System": true,
            "path": "C:\\Program Files\\Remote Desktop",
            "operator": "greaterThanOrEqual",
            "detectionType": "version",
            "@odata.type": "#microsoft.graph.win32LobAppFileSystemDetection"
        }
    ]
}
"@

    $DetectionRulesJSON = $JSON | ConvertFrom-Json




    $Files | ForEach-Object {
        $OutFilePath = Join-Path $FolderPath $_.FileName
        New-Item (Split-Path $OutFilePath) -Type Directory -Force | Out-Null
        $SourceFile = "$($PSScriptRoot)\..\Resources\Win32AppTemplate\$($_.FileName)"
        Copy-Item $SourceFile $OutFilePath -Force
    }

    Get-ChildItem $FolderPath -Recurse | Format-Table

}