forked from cameronkollwitz/CMTFTPSettings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMTFTPSettings.ps1
168 lines (153 loc) · 7.02 KB
/
CMTFTPSettings.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
<#
.SYNOPSIS
Quickly modify the Configuration Manager TFTP settings.
.DESCRIPTION
GUI to change the TFTP settings and restart the PXE service.
.NOTES (ORIGINAL)
Version 1.0: Initial script
- Jorgen Nilsson <https://www.ccmexec.com/>
.NOTES
Works with PowerShell 7.1+
.NOTES
Created By: Cameron Kollwitz <[email protected]>
Updated By: Eizedev ([email protected])
Version: 1.3.0
Date: 2022-05-18
File Name: CMTFTPSettings.ps1
#>
# Find correct service (PXE without WDS = SCCMPxe, with WDS = WDSServer)
$ServiceName = "WDSServer"
If (Get-Service -Name SccmPxe -ErrorAction SilentlyContinue | Tee-Object -Variable ServiceConfig)
{
# if service is not disabled, use the this service
if ($ServiceConfig.StartType -ne 'Disabled')
{
$ServiceName = "SccmPxe"
}
}
If (Get-Service -Name WDSServer -ErrorAction SilentlyContinue | Tee-Object -Variable ServiceConfig)
{
# if service is not disabled, use the this service
if ($ServiceConfig.StartType -ne 'Disabled')
{
$ServiceName = $ServiceName
}
}
$inputXML = @"
<Window x:Name="SCCM_TFTP_Changer" x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="ConfigMgr TFTP Settings" Height="267.52" Width="384.414">
<Grid Margin="0,0,2,-3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="48*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="36*"/>
<ColumnDefinition Width="246*"/>
</Grid.ColumnDefinitions>
<Button x:Name="Save" Content="Save" HorizontalAlignment="Left" Margin="62.8,139,0,0" VerticalAlignment="Top" Width="75" Grid.Column="3"/>
<Label x:Name="label" Content="TFTP BlockSize value" HorizontalAlignment="Left" Margin="38,35,0,0" VerticalAlignment="Top" Width="177" Grid.ColumnSpan="4"/>
<Button x:Name="Exit" Content="Exit" HorizontalAlignment="Left" Margin="152.8,139,0,0" VerticalAlignment="Top" Width="75" Grid.Column="3"/>
<Button x:Name="Restart" Content="Restart $ServiceName" HorizontalAlignment="Left" Margin="38,139,0,0" VerticalAlignment="Top" Width="110" Grid.ColumnSpan="4"/>
<Label x:Name="label1" Content="TFTP WindowsSize value" HorizontalAlignment="Left" Margin="38,76,0,0" VerticalAlignment="Top" Width="142" Grid.ColumnSpan="4"/>
<ComboBox x:Name="TFTPBlockSize" Grid.Column="3" HorizontalAlignment="Left" Margin="105.8,39,0,0" VerticalAlignment="Top" Width="120" SelectedIndex="0">
<ComboBoxItem Content="1024"/>
<ComboBoxItem Content="1456"/>
<ComboBoxItem Content="2048"/>
<ComboBoxItem Content="4096"/>
<ComboBoxItem Content="8192"/>
<ComboBoxItem Content="16384"/>
</ComboBox>
<ComboBox x:Name="TFTPWindowsSize" Grid.Column="3" HorizontalAlignment="Left" Margin="105.8,76,0,0" VerticalAlignment="Top" Width="120" SelectedIndex="0">
<ComboBoxItem Content="1"/>
<ComboBoxItem Content="2"/>
<ComboBoxItem Content="4"/>
<ComboBoxItem Content="8"/>
<ComboBoxItem Content="16"/>
</ComboBox>
<TextBox x:Name="textBox" Grid.ColumnSpan="4" HorizontalAlignment="Left" Height="23" Margin="38,182,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="284" IsReadOnly="True"/>
</Grid>
</Window>
"@
$inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^<Win.*', '<Window'
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = $inputXML
#Read XAML
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
try { $Form = [Windows.Markup.XamlReader]::Load( $reader ) }
catch { Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed." }
#===========================================================================
# Load XAML Objects In PowerShell
#===========================================================================
$xaml.SelectNodes("//*[@Name]") | ForEach-Object { Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name) }
Function Get-FormVariables
{
if ($global:ReadmeDisplay -ne $true)
{
Write-Host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow
$global:ReadmeDisplay = $true
}
Write-Host "Found the following interactable elements from our form" -ForegroundColor Cyan
Get-Variable WPF*
}
function Wait-ServiceStatus($searchString, $status)
{
# Get all services where Name matches $searchString and loop through each of them.
foreach ($service in (Get-Service -Name $searchString))
{
# Wait for the service to reach the $status or a maximum of 30 seconds
$service.WaitForStatus($status, '00:01:00')
}
}
# Getting current values from registry
Try
{
$comboBlockSize = $Form.FindName("TFTPBlockSize")
$comboWindowSize = $Form.FindName("TFTPWindowsSize")
$windowSize = Get-ItemPropertyValue "HKLM:\SOFTWARE\Microsoft\SMS\DP" -Name "RamDiskTFTPWindowSize" -ErrorAction Stop
$blockSize = Get-ItemPropertyValue "HKLM:\SOFTWARE\Microsoft\SMS\DP" -Name "RamDiskTFTPBlockSize" -ErrorAction Stop
$comboBlockSize.text = $blockSize
$comboWindowSize.text = $windowSize
$WPFTextbox.Text = ("Shown values are the current values")
}
Catch
{
#$WPFTextbox.Text = ("Cannot find current values, using defaults")
$windowSize = 1
$comboWindowSize.text = $windowSize
$blockSize = 4096
$comboBlockSize.text = $blockSize
}
$WPFExit.Add_Click( { $form.Close() })
$WPFRestart.Add_Click(
{
$WPFTextbox.Text = ("Service is restarting")
Start-Job -ScriptBlock { Restart-Service $ServiceName }
Start-Sleep -s 3
Wait-ServiceStatus $ServiceName "Running"
$WPFTextbox.Text = ("$ServiceName Service Restarted")
}
)
$WPFSave.Add_Click(
{
Try
{
New-ItemProperty "HKLM:\SOFTWARE\Microsoft\SMS\DP" -Name "RamDiskTFTPWindowSize" -Value $WPFTFTPWindowsSize.text -PropertyType Dword -Force -ErrorAction Stop
New-ItemProperty "HKLM:\SOFTWARE\Microsoft\SMS\DP" -Name "RamDiskTFTPBlockSize" -Value $WPFTFTPBlocksize.text -PropertyType Dword -Force -ErrorAction Stop
}
Catch
{
$WPFTextbox.Text = ("Write to registry Failed! Check your permissions")
}
$WPFTextbox.Text = ("Write to registry completed")
}
)
#===========================================================================
# Shows the form
#===========================================================================
# write-host "To show the form, run the following" -ForegroundColor Cyan
$Form.ShowDialog() | Out-Null