-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntunewin_GUI.ps1
142 lines (120 loc) · 6.07 KB
/
Intunewin_GUI.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Quick and dirty IntuneWinAppUtil GUI
# Downloaded from https://github.com/Microsoft/Microsoft-Win32-Content-Prep-Tool
#region User Configuration
# Path to IntuneWinAppUtil.exe
$intuneWinAppUtil = "$env:USERPROFILE\OneDrive\Documents\Scripts\Intune\IntuneWinAppUtil.exe"
# Path where the output .intunewin files will be saved
$outputPath = "$env:USERPROFILE\OneDrive\Documents\Scripts\Intune\~IntuneWin"
#endregion
# Load the necessary assemblies
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Create the form
$form = New-Object System.Windows.Forms.Form
$form.Text = 'IntuneWin App Packager'
$form.Size = New-Object System.Drawing.Size(550, 250)
$form.StartPosition = 'CenterScreen'
# Source Path Label
$labelSourcePath = New-Object System.Windows.Forms.Label
$labelSourcePath.Location = New-Object System.Drawing.Point(20, 20)
$labelSourcePath.Size = New-Object System.Drawing.Size(100, 20)
$labelSourcePath.Text = 'Source Path:'
$form.Controls.Add($labelSourcePath)
# Source Path TextBox
$textBoxSourcePath = New-Object System.Windows.Forms.TextBox
$textBoxSourcePath.Location = New-Object System.Drawing.Point(20, 40)
$textBoxSourcePath.Size = New-Object System.Drawing.Size(400, 20)
$form.Controls.Add($textBoxSourcePath)
# Setup File Label
$labelSetupFile = New-Object System.Windows.Forms.Label
$labelSetupFile.Location = New-Object System.Drawing.Point(20, 80)
$labelSetupFile.Size = New-Object System.Drawing.Size(400, 20)
$labelSetupFile.Text = 'Setup File (e.g., setup.exe, installer.msi, install.ps1):'
$form.Controls.Add($labelSetupFile)
# Setup File TextBox
$textBoxSetupFile = New-Object System.Windows.Forms.TextBox
$textBoxSetupFile.Location = New-Object System.Drawing.Point(20, 100)
$textBoxSetupFile.Size = New-Object System.Drawing.Size(400, 20)
$form.Controls.Add($textBoxSetupFile)
# Browse Source Button
$buttonBrowseSource = New-Object System.Windows.Forms.Button
$buttonBrowseSource.Location = New-Object System.Drawing.Point(430, 40)
$buttonBrowseSource.Size = New-Object System.Drawing.Size(75, 20)
$buttonBrowseSource.Text = 'Browse'
$buttonBrowseSource.Add_Click({
$folderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
$result = $folderBrowser.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
$textBoxSourcePath.Text = $folderBrowser.SelectedPath
}
})
$form.Controls.Add($buttonBrowseSource)
# Browse Setup File Button
$buttonBrowseSetup = New-Object System.Windows.Forms.Button
$buttonBrowseSetup.Location = New-Object System.Drawing.Point(430, 100)
$buttonBrowseSetup.Size = New-Object System.Drawing.Size(75, 20)
$buttonBrowseSetup.Text = 'Browse'
$buttonBrowseSetup.Add_Click({
$fileBrowser = New-Object System.Windows.Forms.OpenFileDialog
$fileBrowser.Filter = "Setup Files (*.exe;*.msi;*.ps1)|*.exe;*.msi;*.ps1;*.bat;*.cmd|All Files (*.*)|*.*"
$fileBrowser.InitialDirectory = $textBoxSourcePath.Text
$result = $fileBrowser.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
$textBoxSetupFile.Text = Split-Path $fileBrowser.FileName -Leaf
}
})
$form.Controls.Add($buttonBrowseSetup)
# Status Label
$labelStatus = New-Object System.Windows.Forms.Label
$labelStatus.Location = New-Object System.Drawing.Point(20, 180)
$labelStatus.Size = New-Object System.Drawing.Size(550, 60)
$labelStatus.Text = ''
$form.Controls.Add($labelStatus)
# Create Button
$buttonCreate = New-Object System.Windows.Forms.Button
$buttonCreate.Location = New-Object System.Drawing.Point(20, 140)
$buttonCreate.Size = New-Object System.Drawing.Size(100, 30)
$buttonCreate.Text = 'Create Package'
$buttonCreate.Add_Click({
if ([string]::IsNullOrWhiteSpace($textBoxSourcePath.Text) -or
[string]::IsNullOrWhiteSpace($textBoxSetupFile.Text)) {
[System.Windows.Forms.MessageBox]::Show('Please fill in all fields.', 'Error', [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
return
}
# Validate paths
if (-not (Test-Path $textBoxSourcePath.Text)) {
[System.Windows.Forms.MessageBox]::Show('Source path does not exist.', 'Error', [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
return
}
$setupFilePath = Join-Path $textBoxSourcePath.Text $textBoxSetupFile.Text
if (-not (Test-Path $setupFilePath)) {
[System.Windows.Forms.MessageBox]::Show('Setup file does not exist in the source path.', 'Error', [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
return
}
# Create output directory if it doesn't exist
if (-not (Test-Path $outputPath)) {
New-Item -ItemType Directory -Path $outputPath | Out-Null
}
# Build arguments - note the changed parameter format
$arguments = "-c `"$($textBoxSourcePath.Text)`" -s `"$($textBoxSetupFile.Text)`" -o `"$outputPath`" -q"
try {
$labelStatus.Text = "Creating package... Please wait."
$labelStatus.Refresh()
$process = Start-Process -FilePath $intuneWinAppUtil -ArgumentList $arguments -Wait -NoNewWindow -PassThru
if ($process.ExitCode -eq 0) {
$labelStatus.Text = "Package created successfully!`nLocation: $outputPath"
[System.Windows.Forms.MessageBox]::Show("Package created successfully!`nLocation: $outputPath", 'Success', [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)
}
else {
throw "IntuneWinAppUtil.exe exited with code: $($process.ExitCode)"
}
}
catch {
$errorMessage = "Error creating package: $_"
$labelStatus.Text = $errorMessage
[System.Windows.Forms.MessageBox]::Show($errorMessage, 'Error', [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
}
})
$form.Controls.Add($buttonCreate)
# Show the form
$form.ShowDialog()