Skip to content

Commit 4d182ea

Browse files
committed
Add project files.
1 parent d3e0ca9 commit 4d182ea

12 files changed

Lines changed: 534 additions & 0 deletions

App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>

App.xaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Application x:Class="Endpoint_Manager_Scripts_Editor.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:Endpoint_Manager_Scripts_Editor"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
10+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
11+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
12+
<!-- Theme setting -->
13+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Dark.Steel.xaml" />
14+
</ResourceDictionary.MergedDictionaries>
15+
</ResourceDictionary>
16+
</Application.Resources>
17+
</Application>

App.xaml.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
using Microsoft.Identity.Client;
9+
10+
namespace Endpoint_Manager_Scripts_Editor
11+
{
12+
/// <summary>
13+
/// Interaction logic for App.xaml
14+
/// </summary>
15+
public partial class App : Application
16+
{
17+
static App()
18+
{
19+
_clientApp = PublicClientApplicationBuilder.Create(ClientId)
20+
//.WithAuthority($"{Instance}{Tenant}")
21+
//.WithDefaultRedirectUri()
22+
.Build();
23+
//TokenCacheHelper.EnableSerialization(_clientApp.UserTokenCache);
24+
}
25+
private static string ClientId = "d1ddf0e4-d672-4dae-b554-9d5bdfd93547"; //Microsoft - Microsoft Intune PowerShell
26+
//private static string Tenant = "<tenantId here>";
27+
//private static string Instance = "https://login.microsoftonline.com/";
28+
private static IPublicClientApplication _clientApp;
29+
30+
public static IPublicClientApplication PublicClientApp { get { return _clientApp; } }
31+
}
32+
}

Browserscript3x_42190.ico

66.1 KB
Binary file not shown.

FodyWeavers.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
2+
<Costura />
3+
</Weavers>

MainWindow.xaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<mah:MetroWindow x:Class="Endpoint_Manager_Scripts_Editor.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
7+
xmlns:local="clr-namespace:Endpoint_Manager_Scripts_Editor"
8+
mc:Ignorable="d"
9+
Title="Script Viewer for Microsoft Endpoint Manager" Height="500" Width="1000" Background="Black" ShowTitleBar="False" WindowStartupLocation="CenterScreen" WindowStyle="None" ResizeMode="CanResizeWithGrip" ShowMaxRestoreButton="True" ShowMinButton="True" ShowCloseButton="True" MouseLeftButtonDown="MetroWindow_MouseLeftButtonDown">
10+
<Grid>
11+
<Grid.RowDefinitions>
12+
<RowDefinition Height="Auto"/>
13+
<RowDefinition Height="Auto"/>
14+
<RowDefinition Height="1*"/>
15+
<RowDefinition Height="Auto"/>
16+
<RowDefinition Height="Auto"/>
17+
</Grid.RowDefinitions>
18+
<TextBlock Text="Script Viewer for Microsoft Endpoint Manager" Foreground="#BB86FC" FontFamily="Consolas" FontWeight="Bold" FontSize="22" Margin="5" HorizontalAlignment="Center"/>
19+
<StackPanel Grid.Row="1" Orientation="Horizontal">
20+
<Button Content="Connect Endpoint Manager" Click="Btn_ConnectIntune" Margin="5" Foreground="#03DAC5" FontSize="12" FontFamily="Consolas"/>
21+
<ComboBox Name="ComboBox" Width="500" Margin="5" FontSize="14" FontFamily="Consolas" ItemsSource="{Binding comboSource}" mah:TextBoxHelper.Watermark="Select Script" SelectionChanged="ComboBox_SelectionChanged"/>
22+
</StackPanel>
23+
<TextBox Grid.Row="2" Name="ScriptWindow" Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FontSize="14" FontFamily="Consolas" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" IsReadOnly="True"/>
24+
<Grid Grid.Row="3">
25+
<Grid.ColumnDefinitions>
26+
<ColumnDefinition Width="1*"/>
27+
</Grid.ColumnDefinitions>
28+
<WrapPanel Grid.Column="0" Orientation="Horizontal">
29+
<TextBlock Name="FileName" Text="Filename: |" Foreground="DarkGray" VerticalAlignment="Center" Margin="5" IsEnabled="False" FontSize="14" FontFamily="Consolas"/>
30+
<TextBlock Name="RunasThirtyTwo" Text="Run as 32-bit: |" Foreground="DarkGray" VerticalAlignment="Center" Margin="5" IsEnabled="False" FontSize="14" FontFamily="Consolas"/>
31+
<TextBlock Name="SignatureCheck" Text="Enforce signature check: |" Foreground="DarkGray" VerticalAlignment="Center" Margin="5" IsEnabled="False" FontSize="14" FontFamily="Consolas"/>
32+
<TextBlock Name="RunasAccount" Text="Run as account: |" Foreground="DarkGray" VerticalAlignment="Center" Margin="5" IsEnabled="False" FontSize="14" FontFamily="Consolas"/>
33+
<TextBlock Name="Created" Text="Created: |" Foreground="DarkGray" VerticalAlignment="Center" Margin="5" IsEnabled="False" FontSize="14" FontFamily="Consolas"/>
34+
<TextBlock Name="Modified" Text="Modified: |" Foreground="DarkGray" VerticalAlignment="Center" Margin="5" IsEnabled="False" FontSize="14" FontFamily="Consolas"/>
35+
<TextBlock Name="Description" Text="Description: " Foreground="DarkGray" VerticalAlignment="Center" Margin="5" IsEnabled="False" FontSize="14" FontFamily="Consolas"/>
36+
</WrapPanel>
37+
</Grid>
38+
<Grid Grid.Row="4">
39+
<Grid.ColumnDefinitions>
40+
<ColumnDefinition Width="1*"/>
41+
<ColumnDefinition Width="Auto"/>
42+
</Grid.ColumnDefinitions>
43+
<TextBlock Grid.Column="0" Name="Status" Text="Connect to Endpoint Manager" Foreground="#03DAC5" VerticalAlignment="Center" Margin="5" FontSize="14" FontFamily="Consolas"/>
44+
<StackPanel Grid.Column="1" Orientation="Horizontal">
45+
<TextBlock Name="Tenant" Text="TenantId: " Foreground="#03DAC5" VerticalAlignment="Center" Margin="5" FontSize="14" FontFamily="Consolas"/>
46+
<TextBlock Name="Account" Text="Account: " Foreground="#03DAC5" VerticalAlignment="Center" Margin="5,5,10,5" FontSize="14" FontFamily="Consolas"/>
47+
</StackPanel>
48+
</Grid>
49+
</Grid>
50+
</mah:MetroWindow>

MainWindow.xaml.cs

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
using System.Windows.Controls;
9+
using System.Windows.Input;
10+
using System.Windows.Interop;
11+
using Microsoft.Identity.Client;
12+
using Newtonsoft.Json;
13+
14+
namespace Endpoint_Manager_Scripts_Editor
15+
{
16+
public partial class MainWindow
17+
{
18+
string[] scopes = new string[] { "DeviceManagementConfiguration.ReadWrite.All" };
19+
private RootValue scripts;
20+
private string authToken;
21+
22+
public MainWindow()
23+
{
24+
InitializeComponent();
25+
}
26+
27+
private async void Btn_ConnectIntune(object sender, RoutedEventArgs e)
28+
{
29+
AuthenticationResult authResult = null;
30+
var app = App.PublicClientApp;
31+
32+
var accounts = await app.GetAccountsAsync();
33+
var firstAccount = accounts.FirstOrDefault();
34+
35+
try
36+
{
37+
authResult = await app.AcquireTokenSilent(scopes, firstAccount)
38+
.ExecuteAsync();
39+
}
40+
catch (MsalUiRequiredException ex)
41+
{
42+
// A MsalUiRequiredException happened on AcquireTokenSilent.
43+
// This indicates you need to call AcquireTokenInteractive to acquire a token
44+
System.Diagnostics.Debug.WriteLine($"MsalUiRequiredException: {ex.Message}");
45+
46+
try
47+
{
48+
authResult = await app.AcquireTokenInteractive(scopes)
49+
.WithAccount(accounts.FirstOrDefault())
50+
.WithParentActivityOrWindow(new WindowInteropHelper(this).Handle) // optional, used to center the browser on the window
51+
.WithPrompt(Microsoft.Identity.Client.Prompt.SelectAccount)
52+
.ExecuteAsync();
53+
}
54+
catch (MsalException msalex)
55+
{
56+
Status.Text = $"Error Acquiring Token:{System.Environment.NewLine}{msalex}";
57+
}
58+
}
59+
catch (Exception ex)
60+
{
61+
Status.Text = $"Error Acquiring Token Silently:{System.Environment.NewLine}{ex}";
62+
return;
63+
}
64+
65+
if (authResult != null)
66+
{
67+
Tenant.Text = $"TenantId: {authResult.TenantId}";
68+
Account.Text = $"Account: {authResult.Account.Username}";
69+
Status.Text = "Retrieving list of scripts";
70+
authToken = authResult.AccessToken;
71+
string graphAPIEndpoint = "https://graph.microsoft.com/beta/deviceManagement/deviceManagementScripts";
72+
var result = await GetHttpContentWithToken(graphAPIEndpoint, authResult.AccessToken);
73+
74+
scripts = JsonConvert.DeserializeObject<RootValue>(result);
75+
ArrayList scriptList = new ArrayList();
76+
foreach (Script script in scripts.value)
77+
{
78+
scriptList.Add(script.displayName);
79+
};
80+
scriptList.Sort();
81+
ComboBox.ItemsSource = scriptList;
82+
Status.Text = "Select a script";
83+
}
84+
}
85+
86+
public async Task<string> GetHttpContentWithToken(string url, string token)
87+
{
88+
var httpClient = new System.Net.Http.HttpClient();
89+
System.Net.Http.HttpResponseMessage response;
90+
91+
try
92+
{
93+
var request = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, url);
94+
//Add the token in Authorization header
95+
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
96+
response = await httpClient.SendAsync(request);
97+
var content = await response.Content.ReadAsStringAsync();
98+
return content;
99+
}
100+
catch (Exception ex)
101+
{
102+
return ex.ToString();
103+
}
104+
}
105+
106+
private async void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
107+
{
108+
int index = scripts.value.FindIndex(x => x.displayName == ComboBox.SelectedItem);
109+
string id = scripts.value[index].id;
110+
string graphAPIEndpoint = "https://graph.microsoft.com/beta/deviceManagement/deviceManagementScripts" + "/" + id;
111+
var result = await GetHttpContentWithToken(graphAPIEndpoint, authToken);
112+
113+
Script script = JsonConvert.DeserializeObject<Script>(result);
114+
var base64 = Convert.FromBase64String(script.scriptContent);
115+
var scriptText = Encoding.UTF8.GetString(base64);
116+
ScriptWindow.Text = scriptText;
117+
FileName.IsEnabled = true;
118+
FileName.Foreground = System.Windows.Media.Brushes.AntiqueWhite;
119+
FileName.Text = $"Filename: {script.fileName} |";
120+
RunasThirtyTwo.IsEnabled = true;
121+
RunasThirtyTwo.Text = $"Run as 32-bit: {script.runAs32Bit} |";
122+
RunasThirtyTwo.Foreground = System.Windows.Media.Brushes.AntiqueWhite;
123+
SignatureCheck.IsEnabled = true;
124+
SignatureCheck.Text = $"Enforce signature check: {script.enforceSignatureCheck} |";
125+
SignatureCheck.Foreground = System.Windows.Media.Brushes.AntiqueWhite;
126+
RunasAccount.IsEnabled = true;
127+
RunasAccount.Text = $"Run as account: {script.runAsAccount} |";
128+
RunasAccount.Foreground = System.Windows.Media.Brushes.AntiqueWhite;
129+
Created.IsEnabled = true;
130+
Created.Text = $"Created: {script.createdDateTime} |";
131+
Created.Foreground = System.Windows.Media.Brushes.AntiqueWhite;
132+
Modified.IsEnabled = true;
133+
Modified.Text = $"Modified: {script.lastModifiedDateTime} |";
134+
Modified.Foreground = System.Windows.Media.Brushes.AntiqueWhite;
135+
Description.IsEnabled = true;
136+
Description.Text = $"Description: {script.description}";
137+
Description.Foreground = System.Windows.Media.Brushes.AntiqueWhite;
138+
}
139+
140+
private void MetroWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
141+
{
142+
this.DragMove();
143+
}
144+
}
145+
public class RootValue
146+
{
147+
public string odatametadata { get; set; }
148+
public List<Script> value;
149+
}
150+
public class Script
151+
{
152+
public bool enforceSignatureCheck { get; set; }
153+
public bool runAs32Bit { get; set; }
154+
public string id { get; set; }
155+
public string displayName { get; set; }
156+
public string scriptContent { get; set; }
157+
public string description { get; set; }
158+
public DateTime createdDateTime { get; set; }
159+
public DateTime lastModifiedDateTime { get; set; }
160+
public string runAsAccount { get; set; }
161+
public string fileName { get; set; }
162+
}
163+
164+
}

Properties/AssemblyInfo.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Reflection;
2+
using System.Resources;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
using System.Windows;
6+
7+
// General Information about an assembly is controlled through the following
8+
// set of attributes. Change these attribute values to modify the information
9+
// associated with an assembly.
10+
[assembly: AssemblyTitle("Script Viewer for Microsoft Endpoint Manager")]
11+
[assembly: AssemblyDescription("")]
12+
[assembly: AssemblyConfiguration("")]
13+
[assembly: AssemblyCompany("smsagent.blog")]
14+
[assembly: AssemblyProduct("Script Viewer for Microsoft Endpoint Manager")]
15+
[assembly: AssemblyCopyright("Copyright ©Trevor Jones 2022")]
16+
[assembly: AssemblyTrademark("")]
17+
[assembly: AssemblyCulture("")]
18+
19+
// Setting ComVisible to false makes the types in this assembly not visible
20+
// to COM components. If you need to access a type in this assembly from
21+
// COM, set the ComVisible attribute to true on that type.
22+
[assembly: ComVisible(false)]
23+
24+
//In order to begin building localizable applications, set
25+
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
26+
//inside a <PropertyGroup>. For example, if you are using US english
27+
//in your source files, set the <UICulture> to en-US. Then uncomment
28+
//the NeutralResourceLanguage attribute below. Update the "en-US" in
29+
//the line below to match the UICulture setting in the project file.
30+
31+
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32+
33+
34+
[assembly: ThemeInfo(
35+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36+
//(used if a resource is not found in the page,
37+
// or application resource dictionaries)
38+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39+
//(used if a resource is not found in the page,
40+
// app, or any theme specific resource dictionaries)
41+
)]
42+
43+
44+
// Version information for an assembly consists of the following four values:
45+
//
46+
// Major Version
47+
// Minor Version
48+
// Build Number
49+
// Revision
50+
//
51+
// You can specify all the values or you can default the Build and Revision Numbers
52+
// by using the '*' as shown below:
53+
// [assembly: AssemblyVersion("1.0.*")]
54+
[assembly: AssemblyVersion("1.0.0.0")]
55+
[assembly: AssemblyFileVersion("1.0.0.0")]

Properties/Settings.Designer.cs

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Properties/Settings.settings

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
3+
<Profiles>
4+
<Profile Name="(Default)" />
5+
</Profiles>
6+
<Settings />
7+
</SettingsFile>

0 commit comments

Comments
 (0)