-
Notifications
You must be signed in to change notification settings - Fork 1
/
testui.ps1
157 lines (124 loc) · 5.53 KB
/
testui.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
# Check if the current instance is running as administrator
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
# Relaunch the script with administrator rights
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -ArgumentList $arguments -Verb RunAs
exit
}
Write-Host ""
Write-Host "MMMMMMMM MMMMMMMM DDDDDDDDDDDDDD "
Write-Host "M:::::::M M:::::::M D:::::::::::::DDD "
Write-Host "M::::::::M M::::::::M D::::::::::::::::DD "
Write-Host "M:::::::::M M:::::::::M DDD:::::DDDDD::::::D "
Write-Host "M::::::::::M M::::::::::M D:::::D D::::::D "
Write-Host "M:::::::::::M M:::::::::::M D:::::D D::::::D"
Write-Host "M:::::::M::::M M::::M:::::::M D:::::D D::::::D"
Write-Host "M::::::M M::::M M::::M M::::::M D:::::D D::::::D"
Write-Host "M::::::M M::::M::::M M::::::M D:::::D D::::::D"
Write-Host "M::::::M M:::::::M M::::::M D:::::D D::::::D"
Write-Host "M::::::M M:::::M M::::::M D:::::D D::::::D"
Write-Host "M::::::M MMMMM M::::::M D:::::D D::::::D "
Write-Host "M::::::M M::::::M DDD:::::DDDDD::::::D "
Write-Host "M::::::M M::::::M D::::::::::::::::DD "
Write-Host "M::::::M M::::::M D:::::::::::::DDD "
Write-Host "MMMMMMMM MMMMMMMM DDDDDDDDDDDDDD "
Write-Host ""
Write-Host "========Mattia Diana========"
Write-Host "=====Powershell Toolbox====="
# Check the system's theme from the registry
$theme = Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize' -Name 'AppsUseLightTheme'
if ($theme.AppsUseLightTheme -eq 1) {
$isLightTheme = $true
$backgroundColor = "White" # Light mode background color
$textColor = "Black" # Dark mode text color
$accentColor = "Blue"
} else {
$isLightTheme = $false
$backgroundColor = "#2D2D30" # Dark mode background color, using a common dark theme color
$textColor = "White" # Dark mode text color
$accentColor = "Blue"
}
# Load WPF and XAML libraries
Add-Type -AssemblyName PresentationFramework
# WPF GUI Design in XAML
[xml]$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="PowerShell Remote Manager" Height="450" Width="800">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <!-- For static controls: TextBox and Buttons -->
<RowDefinition Height="*" /> <!-- For ScrollViewer, will take up remaining space -->
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Margin="10">
<TextBox Name="txtHostname" />
<Button Name="btnAdd" Content="Add" />
<Button Name="btnRemove" Content="Remove" />
</StackPanel>
<!-- ScrollViewer in a separate row, taking up the remaining space -->
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Visible">
<StackPanel Name="panelDevices" />
</ScrollViewer>
</Grid>
<TabControl Grid.Column="1" Margin="10">
<TabItem Header="Options">
<StackPanel>
<CheckBox Name="chkOption1" Content="Option 1" />
<CheckBox Name="chkOption2" Content="Option 2" />
<Button Name="btnRun" Content="Run" />
</StackPanel>
</TabItem>
</TabControl>
</Grid>
</Window>
"@
# Parse the XAML
$reader = New-Object System.Xml.XmlNodeReader $xaml
$window = [Windows.Markup.XamlReader]::Load($reader)
# Access controls from the parsed XAML
$txtHostname = $window.FindName("txtHostname")
$btnAdd = $window.FindName("btnAdd")
$btnRemove = $window.FindName("btnRemove")
$panelDevices = $window.FindName("panelDevices")
$btnRun = $window.FindName("btnRun")
# Device management functions
function Add-Device {
$hostname = $txtHostname.Text
if (-not $hostname) { return }
if (-not (Test-Connection $hostname -Quiet -Count 1)) { return }
$checkbox = New-Object System.Windows.Controls.CheckBox
$checkbox.Content = $hostname
$checkbox.Margin = New-Object System.Windows.Thickness(5)
$panelDevices.Children.Add($checkbox)
}
function Remove-Device {
$selectedDevices = $panelDevices.Children | Where-Object { $_.IsChecked -eq $true }
foreach ($device in $selectedDevices) {
$panelDevices.Children.Remove($device)
}
}
# Event handlers
$btnAdd.Add_Click({ Add-Device })
$btnRemove.Add_Click({ Remove-Device })
$btnRun.Add_Click({
$selectedDevices = @()
foreach ($deviceCheckBox in $panelDevices.Children) {
if ($deviceCheckBox.IsChecked -eq $true) {
$selectedDevices += $deviceCheckBox.Content
}
}
foreach ($hostname in $selectedDevices) {
Write-Host "Selected device: $hostname"
# Implement the desired actions here
}
[System.Windows.MessageBox]::Show("Actions have been performed on the selected devices.")
})
$listDevices.Items.Add($env:COMPUTERNAME)
Write-Host "Connected with: {$env:COMPUTERNAME}"
# Show the GUI
$window.ShowDialog() | Out-Null