-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStart-IntuneAppCreator.ps1
176 lines (153 loc) · 6.17 KB
/
Start-IntuneAppCreator.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<#
Version: 1.0
Author: Jannik Reinhard (jannikreinhard.com)
Script: Start-IntuneAppCreator
Description:
Add cocolatey apps easy to intune
Release notes:
1.0 :
- Init
1.1 :
- Only install 'Microsoft.Graph.Devices.CorporateManagement'
- Minor changes
- Bug fixes
1.2 :
- Rename Tool
- Only allow custom repositories
#>
###########################################################################################################
############################################ Functions ####################################################
###########################################################################################################
function Get-MessageScreen{
param (
[Parameter(Mandatory = $true)]
[String]$xamlPath
)
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
Add-Type -AssemblyName PresentationFramework
[xml]$xaml = Get-Content $xamlPath
$global:messageScreen = ([Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $xaml)))
$global:messageScreenTitle = $global:messageScreen.FindName("TextMessageHeader")
$global:messageScreenText = $global:messageScreen.FindName("TextMessageBody")
$global:button1 = $global:messageScreen.FindName("ButtonMessage1")
$global:button2 = $global:messageScreen.FindName("ButtonMessage2")
$global:messageScreenTitle.Text = "Initializing Intune App Creator"
$global:messageScreenText.Text = "Starting Intune App Creator"
[System.Windows.Forms.Application]::DoEvents()
$global:messageScreen.Show() | Out-Null
[System.Windows.Forms.Application]::DoEvents()
}
function Import-AllModules
{
foreach($file in (Get-Item -path "$global:Path\modules\*.psm1"))
{
$fileName = [IO.Path]::GetFileName($file)
if($skipModules -contains $fileName) { Write-Warning "Module $fileName excluded"; continue; }
$module = Import-Module $file -PassThru -Force -Global -ErrorAction SilentlyContinue
if($module)
{
$global:messageScreenText.Text = "Module $($module.Name) loaded successfully"
}
else
{
$global:messageScreenText.Text = "Failed to load module $file"
}
[System.Windows.Forms.Application]::DoEvents()
}
}
###########################################################################################################
############################################## Start ######################################################
###########################################################################################################
# Configure
$global:ChocolateyAppName = 'Chocolatey'
# App Info
$appName = "Intune App Creator (Unofficial)"
$appVersion = "1.2"
# Global Var
$global:Path = $PSScriptRoot
$global:PathSources = "$global:Path\.sources"
$global:Auth = $false
$global:ChocolateyAppId = $null
#####################
####### Start #######
#####################
# Start Start Screen
Get-MessageScreen -xamlPath ("$global:Path\xaml\message.xaml")
$global:messageScreenTitle.Text = "Initializing Intune App Creator"
$global:messageScreenText.Text = "Starting Intune App Creator"
[System.Windows.Forms.Application]::DoEvents()
# Load all Modules
$global:messageScreenText.Text = "Load all Modules"
[System.Windows.Forms.Application]::DoEvents()
Import-AllModules
# Init App
$global:messageScreenText.Text = "Init application and load dlls"
[System.Windows.Forms.Application]::DoEvents()
if (-not (Start-Init)){
Write-Error "Error while loading the dlls. Exit the script"
Write-Warning "Unblock all dlls and restart the powershell seassion"
$global:messageScreen.Hide()
Exit
}
# Load main windows
$returnMainForm = New-XamlScreen -xamlPath ("$global:Path\xaml\ui.xaml")
$global:formMainForm = $returnMainForm[0]
$xamlMainForm = $returnMainForm[1]
$xamlMainForm.SelectNodes("//*[@Name]") | % {Set-Variable -Name "WPF$($_.Name)" -Value $formMainForm.FindName($_.Name)}
$global:formMainForm.add_Loaded({
$global:messageScreen.Hide()
$global:formMainForm.Activate()
})
$theme = [MaterialDesignThemes.Wpf.ResourceDictionaryExtensions]::GetTheme($global:formMainForm.Resources)
[void][MaterialDesignThemes.Wpf.ThemeExtensions]::SetBaseTheme($theme, [MaterialDesignThemes.Wpf.Theme]::'Dark')
[void][MaterialDesignThemes.Wpf.ResourceDictionaryExtensions]::SetTheme($global:formMainForm.Resources, $theme)
$WPFLabelToolName.Content = "$appName - V$appVersion"
$Script:messageQueue = [MaterialDesignThemes.Wpf.SnackbarMessageQueue]::new()
$Script:messageQueue.DiscardDuplicates = $true
# Load the click actions
$global:messageScreenText.Text = "Load Actions"
[System.Windows.Forms.Application]::DoEvents()
Set-UiAction
Set-UiActionButton
# Load User Interface
Set-UserInterface
# Get UserId
$global:messageScreen.Hide()
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$title = 'Authentication'
$msg = 'Enter your UPN:'
$userId = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
$global:messageScreen.Show()
# Login
$login = Set-LoginOrLogout -userId $userId
if($login -eq $false){
Write-Error "Error during authentication"
Write-Warning "Please try again"
$global:messageScreen.Hide()
Exit
}
# Get Custom Repository
$global:repositoryUrl = ""
While("" -eq $repositoryUrl){
$global:messageScreen.Hide()
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$title = 'Custom chocolatey repository'
$msg = 'Enter your custom chocolatey repository url (community.chocolatey.org is not allow):'
$repo = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
if($repo -like '*chocolatey.org*'){
[System.Windows.MessageBox]::Show('The chocolatey community repository is not allow.')
}else{$global:repositoryUrl = $repo}
}
$global:messageScreen.Show()
# Install IntuneWinAppUtility
$global:messageScreenText.Text = "Download IntuneWinAppUtil"
[System.Windows.Forms.Application]::DoEvents()
Install-IntuneWinAppUtility
# Install Chocolatey
Install-Chocolatey
# Get app id from Chocolatey
$global:messageScreenText.Text = "Get App Id from Chocolatey"
[System.Windows.Forms.Application]::DoEvents()
Show-InstallChocolatey
#Load Form
$formMainForm.ShowDialog() | out-null