Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config.env
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ Winget Intune app packager

This tool auto create Intune app package from Winget app repository using https://github.com/Romanitho/Winget-Install

## Prerequisites

Before using the tool, you must create an app registion in Entra:

1. Open the **Microsoft Entra admin center**
1. In Microsoft Entra admin center, click **App registrations**.
1. In App registations, click **New registration**.
1. In Register an application, enter a **Name**, e.g., *WingetIntunepackager*. Leve **Supported account types** on **Single tenant only**. Under **Redirect URI (optional)**, select **Public client/native (mobile & desktop)** and enter **https://login.microsoftonline.com/common/oauth2/nativeclient**. Click **Register**

On the **Overview** page, you will find the necessary information for the configuration file (see below).

## Configuration file
You can place an configuration file with the name config.env in the same folder as the executable. The configuration file should be in the following format:
```
Expand Down
88 changes: 65 additions & 23 deletions sources/WingetIntunePackager.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ Package Winget App to Intune with Winget-Install
https://github.com/Romanitho/Winget-Intune-Packager
#>

#Requires -PSEdition Desktop

### APP INFO ###

#Winget Intune Packager version
$Script:WingetIntunePackager = "1.2.2"
$Script:WingetIntunePackager = "1.2.3"
Comment on lines 11 to +14
#Winget-Install Github Link
$Script:WIGithubLink = "https://github.com/Romanitho/Winget-Install/archive/refs/tags/v1.11.3.zip"
#Winget Intune Packager Icon Base64
Expand Down Expand Up @@ -210,6 +212,18 @@ function Start-InstallGUI {

$ConnectButtonAction = {
Start-PopUp "Connecting..."
if (
[string]::IsNullOrWhiteSpace($IntuneTenantIDTextbox.Text) `
-or [string]::IsNullOrWhiteSpace($IntuneClientIDTextbox.Text) `
-or [string]::IsNullOrWhiteSpace($IntuneRedirectUriTextbox.Text)
) {
$ConnectionStatusTextBlock.Foreground = "Red"
$ConnectionStatusTextBlock.Text = "Please fill in all fields."
$ConnectionStatusTextBlock.Tag = $null
$CreateButton.IsEnabled = $false
Close-PopUp
return
}
$ConnectionStatus = Connect-MSIntuneGraph -TenantID $IntuneTenantIDTextbox.Text -ClientID $IntuneClientIDTextbox.Text -RedirectUri $IntuneRedirectUriTextbox.Text
if ($ConnectionStatus.ExpiresOn) {
$ConnectionStatusTextBlock.Foreground = "Green"
Expand Down Expand Up @@ -271,20 +285,27 @@ function Start-InstallGUI {
"AllowAvailableUninstall" = $AllowUninstallCheckbox.IsChecked
"InstallExperience" = $InstallUserContext
}
Invoke-IntunePackage $Win32AppArgs
$AppInfo = @()
$SearchTextBox.Text = ""
$IDComboBox.Text = ""
$IDComboBox.Items.Clear()
$VersionTextBox.Text = ""
$OverrideTextBox.Text = ""
$IntuneDescriptionTextBox.Text = ""
$WhitelistCheckbox.IsChecked = $false
$AllowUninstallCheckbox.IsChecked = $false
$InstallUserContextCheckbox.IsChecked = $false
$CreateButton.IsEnabled = $false
$AppIcon.Source = $null
Close-PopUp
Invoke-IntunePackage $Win32AppArgs -WarningVariable warning

if([string]::IsNullOrEmpty($warning)) {
$AppInfo = @()
$SearchTextBox.Text = ""
$IDComboBox.Text = ""
$IDComboBox.Items.Clear()
$VersionTextBox.Text = ""
$OverrideTextBox.Text = ""
$IntuneDescriptionTextBox.Text = ""
$WhitelistCheckbox.IsChecked = $false
$AllowUninstallCheckbox.IsChecked = $false
$InstallUserContextCheckbox.IsChecked = $false
$CreateButton.IsEnabled = $false
$AppIcon.Source = $null
Close-PopUp
}

if (-not [string]::IsNullOrEmpty($warning)) {
Start-PopUp $warning
}
})

$GithubLinkLabel.Add_PreviewMouseDown({
Expand Down Expand Up @@ -329,7 +350,7 @@ Function Start-PopUp ($Message) {
$PopUpWindow.Icon = $IconBase64

#Store Form Objects In PowerShell
$XAML.SelectNodes("//*[@Name]") | foreach {
$XAML.SelectNodes("//*[@Name]") | ForEach-Object {
Set-Variable -Name "$($_.Name)" -Value $PopUpWindow.FindName($_.Name) -Scope Script
}

Expand Down Expand Up @@ -519,12 +540,27 @@ function Get-WingetAppInfo ($AppID, $AppVersion) {

#Get Google Image app icon
$SearchImageUrl = "https://www.google.com/search?tbm=isch&q=$($AppInfo.PackageName.replace('.','+'))+logo"
$IconUrl = ((Invoke-WebRequest -Uri $SearchImageUrl).Images | Select -ExpandProperty src)[1]
$AppInfo.Icon = "$Location\$($AppInfo.ID).jpg"
Invoke-WebRequest -Uri $IconUrl -OutFile $($AppInfo.Icon)
$images = (Invoke-WebRequest -Uri $SearchImageUrl -UseBasicParsing).Images
if ($images.Count -gt 1) {
$IconUrl = ($images | Select-Object -ExpandProperty src)[1]
}
if (-not [string]::IsNullOrEmpty($IconUrl)) {
$AppInfo.Icon = "$Location\$($AppInfo.ID).jpg"
try {
Invoke-WebRequest -Uri $IconUrl -OutFile $AppInfo.Icon -UseBasicParsing
}
catch {
$AppInfo.Icon = $null
}
}
}

function Invoke-IntunePackage ($Win32AppArgs) {
function Invoke-IntunePackage () {
[CmdletBinding()]
param (
$Win32AppArgs
)

# Package .intunewin file
if (!(Test-Path "$Location/Winget-Install*")) {
Get-GithubRepository $WIGithubLink
Expand All @@ -550,7 +586,10 @@ function Invoke-IntunePackage ($Win32AppArgs) {
$DetectionRule = New-IntuneWin32AppDetectionRuleScript -ScriptFile "$DetectionScriptPath\$DetectionScriptFile"

# Convert image file to icon
$Icon = New-IntuneWin32AppIcon -FilePath $AppInfo.Icon

if ($AppInfo.Icon) {
$Icon = New-IntuneWin32AppIcon -FilePath $AppInfo.Icon
}

# Add parameters to table for the Win32 app
$Win32AppArgs.DisplayName = $AppInfo.PackageName
Expand All @@ -574,7 +613,10 @@ function Invoke-IntunePackage ($Win32AppArgs) {
$Win32AppArgs.Icon = $Icon
}

Add-IntuneWin32App @Win32AppArgs
Add-IntuneWin32App @Win32AppArgs -WarningAction SilentlyContinue -WarningVariable warning
if ($warning) {
$warning | ForEach-Object { Write-Warning $_ }
}
}

function Get-WIPLatestVersion {
Expand Down Expand Up @@ -668,7 +710,7 @@ function Get-WIPLatestVersion {
Start-PopUp "Starting..."

# IntuneWin32App module needed
$IntuneWin32App = Get-InstalledModule "IntuneWin32App" -RequiredVersion $IntuneWin32AppVers -ErrorAction SilentlyContinue
$IntuneWin32App = Get-Module "IntuneWin32App" -ListAvailable | Where-Object { $PSItem.Version -eq $IntuneWin32AppVers }
if (!$IntuneWin32App) {
$NuGet = Get-PackageProvider -name "nuget" -ListAvailable -ErrorAction SilentlyContinue
if (!$NuGet) {
Expand Down