├── .gitattributes
├── .gitignore
├── AutopilotOOBE.png
├── AutopilotOOBE.psd1
├── AutopilotOOBE.psm1
├── CustomProfile
├── BG.json
├── BH.json
├── HalfMan.json
├── OSD.json
├── OSDeploy.json
├── SeguraOSD.json
└── SoCal.json
├── LICENSE
├── Project
├── App.config
├── App.xaml
├── App.xaml.cs
├── AutopilotOOBE.csproj
├── AutopilotOOBE.sln
├── MainWindow.ps1
├── MainWindow.xaml
├── MainWindow.xaml.cs
└── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── Public
├── Invoke-AutopilotOOBEcmd.ps1
├── Start-AutopilotOOBE.ps1
├── Test-AutopilotOOBEconnection.ps1
├── Test-AutopilotOOBEnetwork.ps1
└── Watch-AutopilotOOBEevents.ps1
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Cache objects
2 | Debug/
3 | packer_cache/
4 | .vs/
5 |
6 | # For built boxes
7 | *.box
8 |
--------------------------------------------------------------------------------
/AutopilotOOBE.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OSDeploy/AutopilotOOBE/67b6f4ca83503335bb94be636f42d8bca44fcb8e/AutopilotOOBE.png
--------------------------------------------------------------------------------
/AutopilotOOBE.psd1:
--------------------------------------------------------------------------------
1 | # Module Manifest
2 | #
3 |
4 | @{
5 |
6 | # Script module or binary module file associated with this manifest.
7 | RootModule = 'AutopilotOOBE.psm1'
8 |
9 | # Version number of his module.
10 | ModuleVersion = '24.1.29.1'
11 |
12 | # Supported PSEditions
13 | # CompatiblePSEditions = @()
14 |
15 | # ID used to uniquely identify this module
16 | GUID = 'ad57e6a2-f484-46cd-94e1-dbb33e3d7407'
17 |
18 | # Author of this module
19 | Author = 'David Segura @SeguraOSD'
20 |
21 | # Company or vendor of this module
22 | CompanyName = 'osdeploy.com'
23 |
24 | # Copyright statement for this module
25 | Copyright = '(c) 2024 David Segura osdeploy.com. All rights reserved.'
26 |
27 | # Description of the functionality provided by this module
28 | Description = @'
29 | Autopilot OOBE
30 | '@
31 |
32 | # Minimum version of the Windows PowerShell engine required by this module
33 | PowerShellVersion = '5.0'
34 |
35 | # Name of the Windows PowerShell host required by this module
36 | # PowerShellHostName = 'Windows PowerShell ISE Host'
37 |
38 | # Minimum version of the Windows PowerShell host required by this module
39 | # PowerShellHostVersion = ''
40 |
41 | # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
42 | # DotNetFrameworkVersion = ''
43 |
44 | # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
45 | # CLRVersion = ''
46 |
47 | # Processor architecture (None, X86, Amd64) required by this module
48 | # ProcessorArchitecture = ''
49 |
50 | # Modules that must be imported into the global environment prior to importing this module
51 | # RequiredModules = @()
52 |
53 | # Assemblies that must be loaded prior to importing this module
54 | # RequiredAssemblies = @()
55 |
56 | # Script files (.ps1) that are run in the caller's environment prior to importing this module.
57 | # ScriptsToProcess = @()
58 |
59 | # Type files (.ps1xml) to be loaded when importing this module
60 | # TypesToProcess = @()
61 |
62 | # Format files (.ps1xml) to be loaded when importing this module
63 | # FormatsToProcess = @()
64 |
65 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
66 | # NestedModules = @()
67 |
68 | # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
69 | FunctionsToExport = 'Invoke-AutopilotOOBEcmd','Start-AutopilotOOBE','Test-AutopilotOOBEnetwork','Test-AutopilotOOBEconnection','Watch-AutopilotOOBEevents'
70 |
71 | # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
72 | CmdletsToExport = @()
73 |
74 | # Variables to export from this module
75 | VariablesToExport = @()
76 |
77 | # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
78 | AliasesToExport = 'AutopilotOOBE'
79 |
80 | # DSC resources to export from this module
81 | # DscResourcesToExport = @()
82 |
83 | # List of all modules packaged with this module
84 | # ModuleList = @()
85 |
86 | # List of all files packaged with this module
87 | # FileList = @()
88 |
89 | # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
90 | PrivateData = @{
91 | PSData = @{
92 | # Tags applied to this module. These help with module discovery in online galleries.
93 | Tags = @('OSD','OSDeploy','OSDBuilder','OSDCloud','Autopilot')
94 |
95 | # A URL to the license for this module.
96 | LicenseUri = 'https://github.com/OSDeploy/AutopilotOOBE/blob/master/LICENSE'
97 |
98 | # A URL to the main website for this project.
99 | ProjectUri = 'https://github.com/OSDeploy/AutopilotOOBE'
100 |
101 | # A URL to an icon representing this module.
102 | IconUri = 'https://raw.githubusercontent.com/OSDeploy/AutopilotOOBE/master/AutopilotOOBE.png'
103 |
104 | # ReleaseNotes of this module
105 | ReleaseNotes = 'https://www.osdeploy.com/'
106 | } # End of PSData hashtable
107 | } # End of PrivateData hashtable
108 |
109 | # HelpInfo URI of this module
110 | # HelpInfoURI = ''
111 |
112 | # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
113 | # DefaultCommandPrefix = ''
114 | }
--------------------------------------------------------------------------------
/AutopilotOOBE.psm1:
--------------------------------------------------------------------------------
1 | #================================================
2 | # Functions
3 | # https://github.com/RamblingCookieMonster/PSStackExchange/blob/master/PSStackExchange/PSStackExchange.psm1
4 | #================================================
5 | $AutopilotOOBEPublicFunctions = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue )
6 | $AutopilotOOBEPrivateFunctions = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue )
7 |
8 | foreach ($Import in @($AutopilotOOBEPublicFunctions + $AutopilotOOBEPrivateFunctions)) {
9 | Try {. $Import.FullName}
10 | Catch {Write-Error -Message "Failed to import function $($Import.FullName): $_"}
11 | }
12 |
13 | Export-ModuleMember -Function $AutopilotOOBEPublicFunctions.BaseName
14 | #================================================
15 | # Alias
16 | #================================================
17 | New-Alias -Name AutopilotOOBE -Value Start-AutopilotOOBE -Force -ErrorAction SilentlyContinue
18 | Export-ModuleMember -Function Start-AutopilotOOBE -Alias AutopilotOOBE
--------------------------------------------------------------------------------
/CustomProfile/BG.json:
--------------------------------------------------------------------------------
1 | {
2 | "Assign": {
3 | "IsPresent": true
4 | },
5 | "AssignedUserExample": "someone@example.com",
6 | "AssignedComputerNameExample": "Azure AD Join Only",
7 | "Hidden": [
8 | "AddToGroup",
9 | "AssignedComputerName",
10 | "GroupTag",
11 | "AssignedUser"
12 | ],
13 | "PostAction": "Restart",
14 | "Run": "NetworkingWireless",
15 | "Title": "Brasfield \u0026 Gorrie Autopilot Registration"
16 | }
17 |
--------------------------------------------------------------------------------
/CustomProfile/BH.json:
--------------------------------------------------------------------------------
1 | {
2 | "Assign": {
3 | "IsPresent": true
4 | },
5 | "GroupTag": "Enterprise",
6 | "GroupTagOptions": [
7 | "Development",
8 | "Engineering",
9 | "Enterprise"
10 | ],
11 | "Hidden": [
12 | "AddToGroup",
13 | "AssignedComputerName",
14 | "AssignedUser"
15 | ],
16 | "PostAction": "Quit",
17 | "Run": "WindowsSettings",
18 | "Title": "Baker Hughes Autopilot Registration"
19 | }
--------------------------------------------------------------------------------
/CustomProfile/HalfMan.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OSDeploy/AutopilotOOBE/67b6f4ca83503335bb94be636f42d8bca44fcb8e/CustomProfile/HalfMan.json
--------------------------------------------------------------------------------
/CustomProfile/OSD.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OSDeploy/AutopilotOOBE/67b6f4ca83503335bb94be636f42d8bca44fcb8e/CustomProfile/OSD.json
--------------------------------------------------------------------------------
/CustomProfile/OSDeploy.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OSDeploy/AutopilotOOBE/67b6f4ca83503335bb94be636f42d8bca44fcb8e/CustomProfile/OSDeploy.json
--------------------------------------------------------------------------------
/CustomProfile/SeguraOSD.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OSDeploy/AutopilotOOBE/67b6f4ca83503335bb94be636f42d8bca44fcb8e/CustomProfile/SeguraOSD.json
--------------------------------------------------------------------------------
/CustomProfile/SoCal.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OSDeploy/AutopilotOOBE/67b6f4ca83503335bb94be636f42d8bca44fcb8e/CustomProfile/SoCal.json
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 OSDeploy.com David Segura
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Project/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Project/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Project/App.xaml.cs:
--------------------------------------------------------------------------------
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 |
9 | namespace AutopilotOOBE
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Project/AutopilotOOBE.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {51334E39-690F-4E6B-9E03-241BFCA7B4F7}
8 | WinExe
9 | AutopilotOOBE
10 | AutopilotOOBE
11 | v4.5
12 | 512
13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 | 4
15 | true
16 |
17 |
18 | AnyCPU
19 | true
20 | full
21 | false
22 | bin\Debug\
23 | DEBUG;TRACE
24 | prompt
25 | 4
26 |
27 |
28 | AnyCPU
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE
33 | prompt
34 | 4
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | 4.0
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | MSBuild:Compile
55 | Designer
56 |
57 |
58 | MSBuild:Compile
59 | Designer
60 |
61 |
62 | App.xaml
63 | Code
64 |
65 |
66 | MainWindow.xaml
67 | Code
68 |
69 |
70 |
71 |
72 | Code
73 |
74 |
75 | True
76 | True
77 | Resources.resx
78 |
79 |
80 | True
81 | Settings.settings
82 | True
83 |
84 |
85 | ResXFileCodeGenerator
86 | Resources.Designer.cs
87 |
88 |
89 | SettingsSingleFileGenerator
90 | Settings.Designer.cs
91 |
92 |
93 |
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/Project/AutopilotOOBE.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.31605.320
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutopilotOOBE", "AutopilotOOBE.csproj", "{51334E39-690F-4E6B-9E03-241BFCA7B4F7}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {51334E39-690F-4E6B-9E03-241BFCA7B4F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {51334E39-690F-4E6B-9E03-241BFCA7B4F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {51334E39-690F-4E6B-9E03-241BFCA7B4F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {51334E39-690F-4E6B-9E03-241BFCA7B4F7}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {1815EA71-37CB-4C85-B0CE-41E8F757765A}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/Project/MainWindow.ps1:
--------------------------------------------------------------------------------
1 | # PoSHPF - Version 1.2
2 | # Grab all resources (MahApps, etc), all XAML files, and any potential static resources
3 | $Global:resources = Get-ChildItem -Path "$PSScriptRoot\Resources\*.dll" -ErrorAction SilentlyContinue
4 | $Global:XAML = Get-ChildItem -Path "$PSScriptRoot\*.xaml" | Where-Object {$_.Name -ne 'App.xaml'} -ErrorAction SilentlyContinue #Changed path and exclude App.xaml
5 | $Global:MediaResources = Get-ChildItem -Path "$PSScriptRoot\Media" -ErrorAction SilentlyContinue
6 |
7 | # This class allows the synchronized hashtable to be available across threads,
8 | # but also passes a couple of methods along with it to do GUI things via the
9 | # object's dispatcher.
10 | class SyncClass
11 | {
12 | #Hashtable containing all forms/windows and controls - automatically created when newing up
13 | [hashtable]$SyncHash = [hashtable]::Synchronized(@{})
14 |
15 | # method to close the window - pass window name
16 | [void]CloseWindow($windowName){
17 | $this.SyncHash.$windowName.Dispatcher.Invoke([action]{$this.SyncHash.$windowName.Close()},"Normal")
18 | }
19 |
20 | # method to update GUI - pass object name, property and value
21 | [void]UpdateElement($object,$property,$value){
22 | $this.SyncHash.$object.Dispatcher.Invoke([action]{ $this.SyncHash.$object.$property = $value },"Normal")
23 | }
24 | }
25 | $Global:SyncClass = [SyncClass]::new() # create a new instance of this SyncClass to use.
26 |
27 | ###################
28 | ## Import Resources
29 | ###################
30 | # Load WPF Assembly
31 | Add-Type -assemblyName PresentationFramework
32 |
33 | # Load Resources
34 | foreach($dll in $resources) { [System.Reflection.Assembly]::LoadFrom("$($dll.FullName)") | out-null }
35 |
36 | ##############
37 | ## Import XAML
38 | ##############
39 | $xp = '[^a-zA-Z_0-9]' # All characters that are not a-Z, 0-9, or _
40 | $vx = @() # An array of XAML files loaded
41 |
42 | foreach($x in $XAML) {
43 | # Items from XAML that are known to cause issues
44 | # when PowerShell parses them.
45 | $xamlToRemove = @(
46 | 'mc:Ignorable="d"',
47 | "x:Class=`"(.*?)`"",
48 | "xmlns:local=`"(.*?)`""
49 | )
50 |
51 | $xaml = Get-Content $x.FullName # Load XAML
52 | $xaml = $xaml -replace "x:N",'N' # Rename x:Name to just Name (for consumption in variables later)
53 | foreach($xtr in $xamlToRemove){ $xaml = $xaml -replace $xtr } # Remove items from $xamlToRemove
54 |
55 | # Create a new variable to store the XAML as XML
56 | New-Variable -Name "xaml$(($x.BaseName) -replace $xp, '_')" -Value ($xaml -as [xml]) -Force
57 |
58 | # Add XAML to list of XAML documents processed
59 | $vx += "$(($x.BaseName) -replace $xp, '_')"
60 | }
61 | #######################
62 | ## Add Media Resources
63 | #######################
64 | $imageFileTypes = @(".jpg",".bmp",".gif",".tif",".png") # Supported image filetypes
65 | $avFileTypes = @(".mp3",".wav",".wmv") # Supported audio/visual filetypes
66 | $xp = '[^a-zA-Z_0-9]' # All characters that are not a-Z, 0-9, or _
67 | if($MediaResources.Count -gt 0){
68 | ## Okay... the following code is just silly. I know
69 | ## but hear me out. Adding the nodes to the elements
70 | ## directly caused big issues - mainly surrounding the
71 | ## "x:" namespace identifiers. This is a hacky fix but
72 | ## it does the trick.
73 | foreach($v in $vx)
74 | {
75 | $xml = ((Get-Variable -Name "xaml$($v)").Value) # Load the XML
76 |
77 | # add the resources needed for strings
78 | $xml.DocumentElement.SetAttribute("xmlns:sys","clr-namespace:System;assembly=System")
79 |
80 | # if the document doesn't already have a "Window.Resources" create it
81 | if($null -eq ($xml.DocumentElement.'Window.Resources')){
82 | $fragment = ""
83 | $fragment += ""
84 | }
85 |
86 | # Add each StaticResource with the key of the base name and source to the full name
87 | foreach($sr in $MediaResources)
88 | {
89 | $srname = "$($sr.BaseName -replace $xp, '_')$($sr.Extension.Substring(1).ToUpper())" #convert name to basename + Uppercase Extension
90 | if($sr.Extension -in $imageFileTypes){ $fragment += "" }
91 | if($sr.Extension -in $avFileTypes){
92 | $uri = [System.Uri]::new($sr.FullName)
93 | $fragment += "$uri"
94 | }
95 | }
96 |
97 | # if the document doesn't already have a "Window.Resources" close it
98 | if($null -eq ($xml.DocumentElement.'Window.Resources'))
99 | {
100 | $fragment += ""
101 | $fragment += ""
102 | $xml.DocumentElement.InnerXml = $fragment + $xml.DocumentElement.InnerXml
103 | }
104 | # otherwise just add the fragment to the existing resource dictionary
105 | else
106 | {
107 | $xml.DocumentElement.'Window.Resources'.ResourceDictionary.InnerXml += $fragment
108 | }
109 |
110 | # Reset the value of the variable
111 | (Get-Variable -Name "xaml$($v)").Value = $xml
112 | }
113 | }
114 | #################
115 | ## Create "Forms"
116 | #################
117 | $forms = @()
118 | foreach($x in $vx)
119 | {
120 | $Reader = (New-Object System.Xml.XmlNodeReader ((Get-Variable -Name "xaml$($x)").Value)) #load the xaml we created earlier into XmlNodeReader
121 | New-Variable -Name "form$($x)" -Value ([Windows.Markup.XamlReader]::Load($Reader)) -Force #load the xaml into XamlReader
122 | $forms += "form$($x)" #add the form name to our array
123 | $SyncClass.SyncHash.Add("form$($x)", (Get-Variable -Name "form$($x)").Value) #add the form object to our synched hashtable
124 | }
125 | #################################
126 | ## Create Controls (Buttons, etc)
127 | #################################
128 | $controls = @()
129 | $xp = '[^a-zA-Z_0-9]' # All characters that are not a-Z, 0-9, or _
130 | foreach($x in $vx)
131 | {
132 | $xaml = (Get-Variable -Name "xaml$($x)").Value #load the xaml we created earlier
133 | $xaml.SelectNodes("//*[@Name]") | %{ #find all nodes with a "Name" attribute
134 | $cname = "form$($x)Control$(($_.Name -replace $xp, '_'))"
135 | Set-Variable -Name "$cname" -Value $SyncClass.SyncHash."form$($x)".FindName($_.Name) #create a variale to hold the control/object
136 | $controls += (Get-Variable -Name "form$($x)Control$($_.Name)").Name #add the control name to our array
137 | $SyncClass.SyncHash.Add($cname, $SyncClass.SyncHash."form$($x)".FindName($_.Name)) #add the control directly to the hashtable
138 | }
139 | }
140 | ############################
141 | ## FORMS AND CONTROLS OUTPUT
142 | ############################
143 | <# Write-Host -ForegroundColor Cyan "The following forms were created:"
144 | $forms | %{ Write-Host -ForegroundColor Yellow " `$$_"} #output all forms to screen
145 | if($controls.Count -gt 0){
146 | Write-Host ""
147 | Write-Host -ForegroundColor Cyan "The following controls were created:"
148 | $controls | %{ Write-Host -ForegroundColor Yellow " `$$_"} #output all named controls to screen
149 | } #>
150 | #######################
151 | ## DISABLE A/V AUTOPLAY
152 | #######################
153 | foreach($x in $vx)
154 | {
155 | $carray = @()
156 | $fts = $syncClass.SyncHash."form$($x)"
157 | foreach($c in $fts.Content.Children)
158 | {
159 | if($c.GetType().Name -eq "MediaElement") #find all controls with the type MediaElement
160 | {
161 | $c.LoadedBehavior = "Manual" #Don't autoplay
162 | $c.UnloadedBehavior = "Stop" #When the window closes, stop the music
163 | $carray += $c #add the control to an array
164 | }
165 | }
166 | if($carray.Count -gt 0)
167 | {
168 | New-Variable -Name "form$($x)PoSHPFCleanupAudio" -Value $carray -Force # Store the controls in an array to be accessed later
169 | $syncClass.SyncHash."form$($x)".Add_Closed({
170 | foreach($c in (Get-Variable "form$($x)PoSHPFCleanupAudio").Value)
171 | {
172 | $c.Source = $null #stops any currently playing media
173 | }
174 | })
175 | }
176 | }
177 |
178 | #####################
179 | ## RUNSPACE FUNCTIONS
180 | #####################
181 | ## Yo dawg... Runspace to clean up Runspaces
182 | ## Thank you Boe Prox / Stephen Owen
183 | #region RSCleanup
184 | $Script:JobCleanup = [hashtable]::Synchronized(@{})
185 | $Script:Jobs = [system.collections.arraylist]::Synchronized((New-Object System.Collections.ArrayList)) #hashtable to store all these runspaces
186 | $jobCleanup.Flag = $True #cleanup jobs
187 | $newRunspace =[runspacefactory]::CreateRunspace() #create a new runspace for this job to cleanup jobs to live
188 | $newRunspace.ApartmentState = "STA"
189 | $newRunspace.ThreadOptions = "ReuseThread"
190 | $newRunspace.Open()
191 | $newRunspace.SessionStateProxy.SetVariable("jobCleanup",$jobCleanup) #pass the jobCleanup variable to the runspace
192 | $newRunspace.SessionStateProxy.SetVariable("jobs",$jobs) #pass the jobs variable to the runspace
193 | $jobCleanup.PowerShell = [PowerShell]::Create().AddScript({
194 | #Routine to handle completed runspaces
195 | Do {
196 | Foreach($runspace in $jobs) {
197 | If ($runspace.Runspace.isCompleted) { #if runspace is complete
198 | [void]$runspace.powershell.EndInvoke($runspace.Runspace) #then end the script
199 | $runspace.powershell.dispose() #dispose of the memory
200 | $runspace.Runspace = $null #additional garbage collection
201 | $runspace.powershell = $null #additional garbage collection
202 | }
203 | }
204 | #Clean out unused runspace jobs
205 | $temphash = $jobs.clone()
206 | $temphash | Where {
207 | $_.runspace -eq $Null
208 | } | ForEach {
209 | $jobs.remove($_)
210 | }
211 | Start-Sleep -Seconds 1 #lets not kill the processor here
212 | } while ($jobCleanup.Flag)
213 | })
214 | $jobCleanup.PowerShell.Runspace = $newRunspace
215 | $jobCleanup.Thread = $jobCleanup.PowerShell.BeginInvoke()
216 | #endregion RSCleanup
217 |
218 | #This function creates a new runspace for a script block to execute
219 | #so that you can do your long running tasks not in the UI thread.
220 | #Also the SyncClass is passed to this runspace so you can do UI
221 | #updates from this thread as well.
222 | function Start-BackgroundScriptBlock($scriptBlock){
223 | $newRunspace =[runspacefactory]::CreateRunspace()
224 | $newRunspace.ApartmentState = "STA"
225 | $newRunspace.ThreadOptions = "ReuseThread"
226 | $newRunspace.Open()
227 | $newRunspace.SessionStateProxy.SetVariable("SyncClass",$SyncClass)
228 | $PowerShell = [PowerShell]::Create().AddScript($scriptBlock)
229 | $PowerShell.Runspace = $newRunspace
230 | $PowerShell.BeginInvoke()
231 |
232 | #Add it to the job list so that we can make sure it is cleaned up
233 | <# [void]$Jobs.Add(
234 | [pscustomobject]@{
235 | PowerShell = $PowerShell
236 | Runspace = $PowerShell.BeginInvoke()
237 | }
238 | ) #>
239 | }
240 | #================================================
241 | # Customizations
242 | #================================================
243 | [string]$ModuleVersion = Get-Module -Name AutopilotOOBE | Sort-Object -Property Version | Select-Object -ExpandProperty Version -Last 1
244 | #================================================
245 | # Window Functions
246 | # Minimize Command and PowerShell Windows
247 | #================================================
248 | $Script:showWindowAsync = Add-Type -MemberDefinition @"
249 | [DllImport("user32.dll")]
250 | public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
251 | "@ -Name "Win32ShowWindowAsync" -Namespace Win32Functions -PassThru
252 | function Hide-CmdWindow() {
253 | $CMDProcess = Get-Process -Name cmd -ErrorAction Ignore
254 | foreach ($Item in $CMDProcess) {
255 | $null = $showWindowAsync::ShowWindowAsync((Get-Process -Id $Item.id).MainWindowHandle, 2)
256 | }
257 | }
258 | function Hide-PowershellWindow() {
259 | $null = $showWindowAsync::ShowWindowAsync((Get-Process -Id $pid).MainWindowHandle, 2)
260 | }
261 | function Show-PowershellWindow() {
262 | $null = $showWindowAsync::ShowWindowAsync((Get-Process -Id $pid).MainWindowHandle, 10)
263 | }
264 | #================================================
265 | # Sidebar
266 | #================================================
267 | if (Test-AutopilotOOBEconnection) {
268 | $formMainWindowControlOnlineStatusLabel.Background = 'Green'
269 | }
270 | else {
271 | $formMainWindowControlOnlineStatusLabel.Background = 'Red'
272 | }
273 |
274 | try {
275 | $Tpm = (Get-CimInstance -Namespace "root\CIMV2\Security\MicrosoftTPM" -ClassName Win32_Tpm).SpecVersion
276 | }
277 | catch {}
278 |
279 | if ($Tpm -match '2.0') {
280 | $formMainWindowControlTpmVersionLabel.Content = "TPM: 2.0"
281 | $formMainWindowControlTpmVersionLabel.Background = "Green"
282 | }
283 | elseif ($Tpm -match '1.2') {
284 | $formMainWindowControlTpmVersionLabel.Content = "TPM: 1.2"
285 | $formMainWindowControlTpmVersionLabel.Background = "Red"
286 | }
287 | else {
288 | $formMainWindowControlTpmVersionLabel.Content = "TPM"
289 | $formMainWindowControlTpmVersionLabel.Background = "Red"
290 | #$formMainWindowControlTpmVersionLabel.Visibility = "Collapsed"
291 | }
292 |
293 | $formMainWindowControlCSManufacturerControl.Content = ((Get-CimInstance -ClassName CIM_ComputerSystem).Manufacturer).Trim()
294 |
295 | if ($formMainWindowControlCSManufacturerControl.Content -match 'Lenovo') {
296 | $formMainWindowControlCSModelControl.Content = ((Get-CimInstance -ClassName Win32_ComputerSystemProduct).Version).Trim()
297 | }
298 | else {
299 | $formMainWindowControlCSModelControl.Content = ((Get-CimInstance -ClassName CIM_ComputerSystem).Model).Trim()
300 | }
301 |
302 | $SerialNumber = ((Get-CimInstance -ClassName Win32_BIOS).SerialNumber).Trim()
303 | $formMainWindowControlSerialNumberLabel.Content = $SerialNumber
304 |
305 | $BiosVersion = ((Get-CimInstance -ClassName Win32_BIOS).SMBIOSBIOSVersion).Trim()
306 | $formMainWindowControlBiosVersionLabel.Content = "BIOS $BiosVersion"
307 | #================================================
308 | # Parameters
309 | #================================================
310 | $AutopilotOOBEParams = (Get-Command Start-AutopilotOOBE).Parameters
311 | #================================================
312 | # Heading
313 | #================================================
314 | $formMainWindowControlHeading.Content = $Global:AutopilotOOBE.Title
315 | #================================================
316 | # SubHeading
317 | #================================================
318 | $Global:GetRegCurrentVersion = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
319 |
320 | $SubTitleProductName = ($Global:GetRegCurrentVersion).ProductName
321 |
322 | if ($Global:GetRegCurrentVersion.DisplayVersion -gt 0) {
323 | $SubTitleDisplayVersion = ($Global:GetRegCurrentVersion).DisplayVersion
324 | }
325 | else {
326 | $SubTitleDisplayVersion = ($Global:GetRegCurrentVersion).ReleaseId
327 | }
328 |
329 | $SubTitleBuildNumber = "$($Global:GetRegCurrentVersion.CurrentBuild).$($Global:GetRegCurrentVersion.UBR)"
330 |
331 | $formMainWindowControlSubHeading.Content = "$SubTitleProductName $SubTitleDisplayVersion ($SubTitleBuildNumber)"
332 | #================================================
333 | # GroupTag Control
334 | #================================================
335 | # Disable the Control
336 | if ($Disabled -contains 'GroupTag') {
337 | $formMainWindowControlGroupTagComboBox.IsEnabled = $false
338 | }
339 |
340 | # Hide the Control
341 | if ($Hidden -contains 'GroupTag') {
342 | $formMainWindowControlGroupTagStackPanel.Visibility = 'Collapsed'
343 | }
344 |
345 | # Populate the ComboBox
346 | $Global:AutopilotOOBE.GroupTagOptions | ForEach-Object {
347 | $formMainWindowControlGroupTagComboBox.Items.Add($_) | Out-Null
348 | }
349 |
350 | # Set the ComboBox Default
351 | if ($Global:AutopilotOOBE.GroupTag) {
352 | $formMainWindowControlGroupTagComboBox.Text = $Global:AutopilotOOBE.GroupTag
353 | }
354 | #================================================
355 | # AddToGroup Control
356 | #================================================
357 | # Disable the Control
358 | if ($Disabled -contains 'AddToGroup') {
359 | $formMainWindowControlAddToGroupComboBox.IsEnabled = $false
360 | }
361 |
362 | # Hide the Control
363 | if ($Hidden -contains 'AddToGroup') {
364 | $formMainWindowControlAddToGroupStackPanel.Visibility = 'Collapsed'
365 | }
366 |
367 | # Populate the Control
368 | $Global:AutopilotOOBE.AddToGroupOptions | ForEach-Object {
369 | $formMainWindowControlAddToGroupComboBox.Items.Add($_) | Out-Null
370 | }
371 |
372 | # Set the Default
373 | if ($Global:AutopilotOOBE.AddToGroup) {
374 | $formMainWindowControlAddToGroupComboBox.Text = $Global:AutopilotOOBE.AddToGroup
375 | }
376 | #================================================
377 | # AssignedUser Control
378 | #================================================
379 | # Disable the Control
380 | if ($Disabled -contains 'AssignedUser') {
381 | $formMainWindowControlAssignedUserTextBox.IsEnabled = $false
382 | }
383 |
384 | # Hide the Control
385 | if ($Hidden -contains 'AssignedUser') {
386 | $formMainWindowControlAssignedUserStackPanel.Visibility = 'Collapsed'
387 | }
388 |
389 | # Populate the Control
390 | $formMainWindowControlAssignedUserTextBox.Text = $Global:AutopilotOOBE.AssignedUserExample
391 | if ($Global:AutopilotOOBE.AssignedUser -gt 0) {
392 | $formMainWindowControlAssignedUserTextBox.Text = $Global:AutopilotOOBE.AssignedUser
393 | }
394 | #================================================
395 | # AssignedComputerName Control
396 | #================================================
397 | # Disable the Control
398 | if ($Disabled -contains 'AssignedComputerName') {
399 | $formMainWindowControlAssignedComputerNameTextBox.IsEnabled = $false
400 | }
401 |
402 | # Hide the Control
403 | if ($Hidden -contains 'AssignedComputerName') {
404 | $formMainWindowControlAssignedComputerNameStackPanel.Visibility = 'Collapsed'
405 | }
406 |
407 | # Populate the Control
408 | $formMainWindowControlAssignedComputerNameTextBox.Text = $Global:AutopilotOOBE.AssignedComputerNameExample
409 | if ($Global:AutopilotOOBE.AssignedComputerName -gt 0) {
410 | $formMainWindowControlAssignedComputerNameTextBox.Text = $Global:AutopilotOOBE.AssignedComputerName
411 | }
412 | #================================================
413 | # PostAction Control
414 | #================================================
415 | # Disable the Control
416 | if ($Disabled -contains 'PostAction') {$formMainWindowControlPostActionComboBox.IsEnabled = $false}
417 |
418 | # Hide the Control
419 | if ($Hidden -contains 'PostAction') {
420 | $formMainWindowControlPostActionStackPanel.Visibility = 'Collapsed'
421 | }
422 |
423 | # Values
424 | $PostActionComboBoxValues = @(
425 | 'Quit',
426 | 'Restart Computer',
427 | 'Shutdown Computer',
428 | 'Sysprep /oobe /quit',
429 | 'Sysprep /oobe /reboot',
430 | 'Sysprep /oobe /shutdown',
431 | 'Sysprep /generalize /oobe /reboot',
432 | 'Sysprep /generalize /oobe /shutdown'
433 | )
434 |
435 | # Populate the ComboBox
436 | $PostActionComboBoxValues | ForEach-Object {
437 | $formMainWindowControlPostActionComboBox.Items.Add($_) | Out-Null
438 | }
439 |
440 | # Set the Default
441 | switch ($Global:AutopilotOOBE.PostAction) {
442 | 'Quit' {$formMainWindowControlPostActionComboBox.SelectedValue = 'Quit'}
443 | 'Restart' {$formMainWindowControlPostActionComboBox.SelectedValue = 'Restart Computer'}
444 | 'Shutdown' {$formMainWindowControlPostActionComboBox.SelectedValue = 'Shutdown Computer'}
445 | 'Sysprep' {$formMainWindowControlPostActionComboBox.SelectedValue = 'Sysprep /oobe /quit'}
446 | 'SysprepReboot' {$formMainWindowControlPostActionComboBox.SelectedValue = 'Sysprep /oobe /reboot'}
447 | 'SysprepShutdown' {$formMainWindowControlPostActionComboBox.SelectedValue = 'Sysprep /oobe /shutdown'}
448 | 'GeneralizeReboot' {$formMainWindowControlPostActionComboBox.SelectedValue = 'Sysprep /generalize /oobe /reboot'}
449 | 'GeneralizeShutdown' {$formMainWindowControlPostActionComboBox.SelectedValue = 'Sysprep /generalize /oobe /shutdown'}
450 | Default {$formMainWindowControlPostActionComboBox.SelectedValue = 'Quit'}
451 | }
452 | #================================================
453 | # Assign CheckBox
454 | #================================================
455 | # Disable the Control
456 | if ($Disabled -contains 'Assign') {$formMainWindowControlAssignCheckBox.IsEnabled = $false}
457 |
458 | # Hide the Control
459 | if ($Hidden -contains 'Assign') {
460 | $formMainWindowControlAssignStackPanel.Visibility = 'Collapsed'
461 | }
462 |
463 | # Set the Default
464 | if ($Global:AutopilotOOBE.Assign -eq $true) {
465 | $formMainWindowControlAssignCheckBox.IsChecked = $true
466 | }
467 | #================================================
468 | # Register Control
469 | #================================================
470 | # Hide the Control
471 | if ($Hidden -contains 'Register') {
472 | $formMainWindowControlRegisterStackPanel.Visibility = 'Collapsed'
473 |
474 | if ($Global:RegAutoPilot.CloudAssignedForcedEnrollment -eq 1) {
475 | $CloudAssignedForcedEnrollment = 'Yes'
476 | $formMainWindow.Title = "AutopilotOOBE $ModuleVersion : Quit to OOBE"
477 | }
478 | else {
479 | $CloudAssignedForcedEnrollment = 'No'
480 | #$formMainWindow.Title = "AutopilotOOBE $ModuleVersion Device Not Registered"
481 | }
482 |
483 | if ($Global:RegAutoPilot.IsDevicePersonalized -eq 1) {
484 | $IsDevicePersonalized = 'Yes'
485 | }
486 | else {
487 | $IsDevicePersonalized = 'No'
488 | }
489 |
490 | if ($Global:RegAutoPilot.CloudAssignedLanguage) {
491 | $CloudAssignedLanguage = $Global:RegAutoPilot.CloudAssignedLanguage
492 | }
493 | else {
494 | $CloudAssignedLanguage = 'Operating System Default'
495 | }
496 |
497 | if (($Global:RegAutoPilot.CloudAssignedOobeConfig -band 512) -gt 0) {$PatchDownload = 'Yes'} else {$PatchDownload = 'No'}
498 | if (($Global:RegAutoPilot.CloudAssignedOobeConfig -band 128) -gt 0) {$TPMRequired = 'Yes'} else {$TPMRequired = 'No'}
499 | if (($Global:RegAutoPilot.CloudAssignedOobeConfig -band 64) -gt 0) {$DeviceAuth = 'Yes'} else {$DeviceAuth = 'No'}
500 | if (($Global:RegAutoPilot.CloudAssignedOobeConfig -band 32) -gt 0) {$TPMAttestation = 'Yes'} else {$TPMAttestation = 'No'}
501 | if (($Global:RegAutoPilot.CloudAssignedOobeConfig -band 4) -gt 0) {$SkipExpress = 'Yes'} else {$SkipExpress = 'No'}
502 | if (($Global:RegAutoPilot.CloudAssignedOobeConfig -band 2) -gt 0) {$DisallowAdmin = 'Yes'} else {$DisallowAdmin = 'No'}
503 |
504 | $formMainWindowControlInformationLabel.Content = @"
505 | Azure AD Tenant: $($Global:RegAutoPilot.CloudAssignedTenantDomain)
506 | Azure AD Tenant ID: $($Global:RegAutoPilot.CloudAssignedTenantId)
507 | MDM ID: $($Global:RegAutoPilot.CloudAssignedMdmId)
508 | Autopilot Service Correlation ID: $($Global:RegAutoPilot.AutopilotServiceCorrelationId)
509 |
510 | AAD Device Auth: $DeviceAuth
511 | AAD TPM Required: $TPMRequired
512 | Disallow Admin: $DisallowAdmin
513 | Enable Patch Download: $PatchDownload
514 | Forced Enrollment: $CloudAssignedForcedEnrollment
515 | Is Device Personalized: $IsDevicePersonalized
516 | Language: $CloudAssignedLanguage
517 | Skip Express Settings: $SkipExpress
518 | Telemetry Level: $($Global:RegAutoPilot.CloudAssignedTelemetryLevel)
519 | TPM Attestation: $TPMAttestation
520 | "@
521 | }
522 | else {
523 | $formMainWindow.Title = "AutopilotOOBE $ModuleVersion : Register Device"
524 | }
525 | #================================================
526 | # Run Controls
527 | #================================================
528 | # Hide the Control
529 | if ($Hidden -contains 'Run') {
530 | $formMainWindowControlRunStackPanel.Visibility = 'Collapsed'
531 | }
532 |
533 | # Values
534 | $RunComboBoxValues = @(
535 | 'Restart Computer',
536 | 'Shutdown Computer',
537 | 'Command Prompt',
538 | 'PowerShell',
539 | 'PowerShell ISE',
540 | 'Open Event Viewer',
541 | 'Open Windows Explorer',
542 | 'Show Network and Wireless Settings',
543 | 'Show Windows Security',
544 | 'Show Windows Settings',
545 | 'AutopilotDiagnostics',
546 | 'AutopilotDiagnostics Online',
547 | 'MDMDiagnosticsTool -out C:\Temp',
548 | 'MDMDiagnosticsTool -area Autopilot -cab C:\Temp\Autopilot.cab',
549 | 'MDMDiagnosticsTool -area Autopilot;TPM -cab C:\Temp\AutopilotTPM.cab',
550 | 'TPM Get',
551 | 'TPM Clear',
552 | 'TPM Initialize',
553 | 'Sysprep /oobe /quit',
554 | 'Sysprep /oobe /reboot',
555 | 'Sysprep /oobe /shutdown',
556 | 'Sysprep /audit /reboot'
557 | )
558 |
559 | # Populate the ComboBox
560 | $RunComboBoxValues | ForEach-Object {
561 | $formMainWindowControlRunComboBox.Items.Add($_) | Out-Null
562 | }
563 |
564 | # Set the ComboBox Default
565 | switch ($Global:AutopilotOOBE.Run) {
566 | 'Restart' {$formMainWindowControlRunComboBox.SelectedValue = 'Restart Computer'}
567 | 'Shutdown' {$formMainWindowControlRunComboBox.SelectedValue = 'Shutdown Computer'}
568 | 'CommandPrompt' {$formMainWindowControlRunComboBox.SelectedValue = 'Command Prompt'}
569 | 'PowerShell' {$formMainWindowControlRunComboBox.SelectedValue = 'PowerShell'}
570 | 'PowerShellISE' {$formMainWindowControlRunComboBox.SelectedValue = 'PowerShell ISE'}
571 | 'EventViewer' {$formMainWindowControlRunComboBox.SelectedValue = 'Open Event Viewer'}
572 | 'NetworkingWireless' {$formMainWindowControlRunComboBox.SelectedValue = 'Show Network and Wireless Settings'}
573 | 'WindowsExplorer' {$formMainWindowControlRunComboBox.SelectedValue = 'Open Windows Explorer'}
574 | 'WindowsSettings' {$formMainWindowControlRunComboBox.SelectedValue = 'Show Windows Settings'}
575 | 'AutopilotDiagnostics' {$formMainWindowControlRunComboBox.SelectedValue = 'AutopilotDiagnostics'}
576 | 'AutopilotDiagnosticsOnline' {$formMainWindowControlRunComboBox.SelectedValue = 'AutopilotDiagnostics Online'}
577 | 'MDMDiag' {$formMainWindowControlRunComboBox.SelectedValue = 'MDMDiagnosticsTool -out C:\Temp'}
578 | 'MDMDiagAutopilot' {$formMainWindowControlRunComboBox.SelectedValue = 'MDMDiagnosticsTool -area Autopilot -cab C:\Temp\Autopilot.cab'}
579 | 'MDMDiagAutopilotTPM' {$formMainWindowControlRunComboBox.SelectedValue = 'MDMDiagnosticsTool -area Autopilot;TPM -cab C:\Temp\AutopilotTPM.cab'}
580 | 'Sysprep' {$formMainWindowControlRunComboBox.SelectedValue = 'Sysprep /oobe /quit'}
581 | 'SysprepReboot' {$formMainWindowControlRunComboBox.SelectedValue = 'Sysprep /oobe /reboot'}
582 | 'SysprepShutdown' {$formMainWindowControlRunComboBox.SelectedValue = 'Sysprep /oobe /shutdown'}
583 | 'SysprepAudit' {$formMainWindowControlRunComboBox.SelectedValue = 'Sysprep /audit /reboot'}
584 | Default {$formMainWindowControlRunComboBox.SelectedValue = 'PowerShell'}
585 | }
586 |
587 | # Add Click
588 | $formMainWindowControlRunButton.add_Click( {
589 | switch ($formMainWindowControlRunComboBox.SelectedValue) {
590 | 'Restart Computer' {Restart-Computer}
591 | 'Shutdown Computer' {Stop-Computer}
592 | 'Command Prompt' {Start-Process Cmd.exe}
593 | 'PowerShell' {Start-Process PowerShell.exe -ArgumentList "-Nologo"}
594 | 'PowerShell ISE' {Start-Process PowerShell_ISE.exe}
595 | 'Open Event Viewer' {Start-Process -FilePath PowerShell.exe -ArgumentList '-NoLogo -Window Minimized',"-Command Invoke-AutopilotOOBEcmd EventViewer"}
596 | 'Open Windows Explorer' {Start-Process Explorer.exe}
597 | 'Show Network and Wireless Settings'{Start-Process ms-availablenetworks:}
598 | 'Show Windows Security' {Start-Process PowerShell.exe -ArgumentList "Add-AppxPackage -Register -DisableDevelopmentMode 'C:\Windows\SystemApps\Microsoft.Windows.SecHealthUI_cw5n1h2txyewy\AppXManifest.xml';start windowsdefender:"}
599 | 'Show Windows Settings' {Start-Process ms-settings:}
600 | 'AutopilotDiagnostics' {Start-Process -FilePath PowerShell.exe -ArgumentList '-NoLogo -NoExit',"-Command Invoke-AutopilotOOBEcmd AutopilotDiagnostics"}
601 | 'AutopilotDiagnostics Online' {Start-Process -FilePath PowerShell.exe -ArgumentList '-NoLogo -NoExit',"-Command Invoke-AutopilotOOBEcmd AutopilotDiagnosticsOnline"}
602 | 'MDMDiagnosticsTool -out C:\Temp' {Start-Process MDMDiagnosticsTool.exe -ArgumentList "-out C:\Temp"}
603 | 'MDMDiagnosticsTool -area Autopilot -cab C:\Temp\Autopilot.cab' {Start-Process MDMDiagnosticsTool.exe -ArgumentList "-area Autopilot","-cab C:\Temp\Autopilot.cab"}
604 | 'MDMDiagnosticsTool -area Autopilot;TPM -cab C:\Temp\AutopilotTPM.cab' {Start-Process MDMDiagnosticsTool.exe -ArgumentList "-area Autopilot;TPM","-cab C:\Temp\AutopilotTPM.cab"}
605 | 'TPM Get' {Start-Process -FilePath PowerShell.exe -ArgumentList '-NoLogo -NoExit',"-Command Invoke-AutopilotOOBEcmd GetTpm"}
606 | 'TPM Clear' {Start-Process -FilePath PowerShell.exe -ArgumentList '-NoLogo -NoExit',"-Command Invoke-AutopilotOOBEcmd ClearTpm"}
607 | 'TPM Initialize' {Start-Process -FilePath PowerShell.exe -ArgumentList '-NoLogo -NoExit',"-Command Invoke-AutopilotOOBEcmd InitializeTpm"}
608 | 'Sysprep /oobe /quit' {Start-Process "$env:SystemRoot\System32\Sysprep\Sysprep.exe" -ArgumentList "/oobe", "/quit"}
609 | 'Sysprep /oobe /reboot' {Start-Process "$env:SystemRoot\System32\Sysprep\Sysprep.exe" -ArgumentList "/oobe", "/reboot"}
610 | 'Sysprep /oobe /shutdown' {Start-Process "$env:SystemRoot\System32\Sysprep\Sysprep.exe" -ArgumentList "/oobe", "/shutdown"}
611 | 'Sysprep /audit /reboot' {Start-Process "$env:SystemRoot\System32\Sysprep\Sysprep.exe" -ArgumentList "/audit", "/reboot"}
612 | Default {}
613 | }
614 | })
615 | #================================================
616 | # Parameter Docs
617 | #================================================
618 | if ($Hidden -contains 'Docs') {
619 | $formMainWindowControlDocsStackPanel.Visibility = 'Collapsed'
620 | }
621 |
622 | $formMainWindowControlDocsComboBox.Items.Add('Windows Autopilot Documentation') | Out-Null
623 | $formMainWindowControlDocsComboBox.Items.Add('Windows Autopilot Overview') | Out-Null
624 | $formMainWindowControlDocsComboBox.Items.Add('Windows Autopilot User-Driven Mode') | Out-Null
625 | $formMainWindowControlDocsComboBox.Items.Add('Windows Autopilot for Pre-Provisioned Deployment') | Out-Null
626 | $formMainWindowControlDocsComboBox.Items.Add('Windows Autopilot Deployment for Existing Devices') | Out-Null
627 | $formMainWindowControlDocsComboBox.Items.Add('Manually register devices with Windows Autopilot') | Out-Null
628 | $formMainWindowControlDocsComboBox.Items.Add('Windows Autopilot Troubleshooting Overview') | Out-Null
629 | $formMainWindowControlDocsComboBox.Items.Add('Troubleshoot Autopilot Device Import and Enrollment') | Out-Null
630 | $formMainWindowControlDocsComboBox.Items.Add('Troubleshoot Autopilot OOBE Issues') | Out-Null
631 | $formMainWindowControlDocsComboBox.Items.Add('Troubleshoot Azure Active Directory Join Issues') | Out-Null
632 | $formMainWindowControlDocsComboBox.Items.Add('Windows Autopilot Known Issues') | Out-Null
633 | $formMainWindowControlDocsComboBox.Items.Add('Windows Autopilot Resolved Issues') | Out-Null
634 | $formMainWindowControlDocsComboBox.Items.Add('Sysprep Overview') | Out-Null
635 | $formMainWindowControlDocsComboBox.Items.Add('Sysprep Audit Mode Overview') | Out-Null
636 | $formMainWindowControlDocsComboBox.Items.Add('Sysprep Command-Line Options') | Out-Null
637 |
638 | if ($Hidden -contains 'Register') {
639 | $formMainWindowControlDocsComboBox.SelectedValue = 'Troubleshoot Autopilot OOBE Issues'
640 | }
641 | else {
642 | $formMainWindowControlDocsComboBox.SelectedValue = 'Windows Autopilot Documentation'
643 | }
644 |
645 | if ($Global:AutopilotOOBE.Docs) {
646 | $formMainWindowControlDocsComboBox.Items.Add($Global:AutopilotOOBE.Docs) | Out-Null
647 | $formMainWindowControlDocsComboBox.SelectedValue = $Global:AutopilotOOBE.Docs
648 | }
649 |
650 | $formMainWindowControlDocsButton.add_Click( {
651 | Write-Host -ForegroundColor Cyan "Run: $($formMainWindowControlDocsComboBox.SelectedValue)"
652 |
653 | if ($formMainWindowControlDocsComboBox.SelectedValue -eq 'Windows Autopilot Documentation') {Start-Process 'https://docs.microsoft.com/en-us/mem/autopilot/'}
654 | elseif ($formMainWindowControlDocsComboBox.SelectedValue -eq 'Windows Autopilot Overview') {Start-Process 'https://docs.microsoft.com/en-us/mem/autopilot/windows-autopilot'}
655 | elseif ($formMainWindowControlDocsComboBox.SelectedValue -eq 'Windows Autopilot User-Driven Mode') {Start-Process 'https://docs.microsoft.com/en-us/mem/autopilot/user-driven'}
656 | elseif ($formMainWindowControlDocsComboBox.SelectedValue -eq 'Windows Autopilot for Pre-Provisioned Deployment') {Start-Process 'https://docs.microsoft.com/en-us/mem/autopilot/pre-provision'}
657 | elseif ($formMainWindowControlDocsComboBox.SelectedValue -eq 'Windows Autopilot Deployment for Existing Devices') {Start-Process 'https://docs.microsoft.com/en-us/mem/autopilot/existing-devices'}
658 | elseif ($formMainWindowControlDocsComboBox.SelectedValue -eq 'Manually register devices with Windows Autopilot') {Start-Process 'https://docs.microsoft.com/en-us/mem/autopilot/add-devices'}
659 | elseif ($formMainWindowControlDocsComboBox.SelectedValue -eq 'Windows Autopilot Troubleshooting Overview') {Start-Process 'https://docs.microsoft.com/en-us/mem/autopilot/troubleshooting'}
660 | elseif ($formMainWindowControlDocsComboBox.SelectedValue -eq 'Troubleshoot Autopilot Device Import and Enrollment') {Start-Process 'https://docs.microsoft.com/en-us/mem/autopilot/troubleshoot-device-enrollment'}
661 | elseif ($formMainWindowControlDocsComboBox.SelectedValue -eq 'Troubleshoot Autopilot OOBE Issues') {Start-Process 'https://docs.microsoft.com/en-us/mem/autopilot/troubleshoot-oobe'}
662 | elseif ($formMainWindowControlDocsComboBox.SelectedValue -eq 'Troubleshoot Azure Active Directory Join Issues') {Start-Process 'https://docs.microsoft.com/en-us/mem/autopilot/troubleshoot-aad-join'}
663 | elseif ($formMainWindowControlDocsComboBox.SelectedValue -eq 'Windows Autopilot Known Issues') {Start-Process 'https://docs.microsoft.com/en-us/mem/autopilot/known-issues'}
664 | elseif ($formMainWindowControlDocsComboBox.SelectedValue -eq 'Windows Autopilot Resolved Issues') {Start-Process 'https://docs.microsoft.com/en-us/mem/autopilot/resolved-issues'}
665 | elseif ($formMainWindowControlDocsComboBox.SelectedValue -eq 'Sysprep Overview') {Start-Process 'https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/sysprep--system-preparation--overview'}
666 | elseif ($formMainWindowControlDocsComboBox.SelectedValue -eq 'Sysprep Audit Mode Overview') {Start-Process 'https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/audit-mode-overview'}
667 | elseif ($formMainWindowControlDocsComboBox.SelectedValue -eq 'Sysprep Command-Line Options') {Start-Process 'https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/sysprep-command-line-options'}
668 | else {
669 | try {
670 | Start-Process $formMainWindowControlDocsComboBox.SelectedValue
671 | }
672 | catch {
673 | Write-Warning "Could not execute $($formMainWindowControlDocsComboBox.SelectedValue)"
674 | }
675 | }
676 | })
677 | #================================================
678 | # RegisterButton
679 | #================================================
680 | if ($env:UserName -ne 'defaultuser0') {
681 | $formMainWindowControlRegisterButton.IsEnabled = $false
682 | }
683 |
684 | $formMainWindowControlRegisterButton.add_Click( {
685 | $formMainWindow.Close()
686 | Show-PowershellWindow
687 |
688 | $Params = @{
689 | Online = $true
690 | }
691 |
692 | if ($formMainWindowControlAssignCheckbox.IsChecked) {
693 | $Params.Assign = $true
694 | }
695 |
696 | if ($formMainWindowControlAddToGroupComboBox.Text -gt 0) {
697 | $Params.AddToGroup = $formMainWindowControlAddToGroupComboBox.Text
698 | }
699 |
700 | if ($formMainWindowControlGroupTagComboBox.Text -gt 0) {
701 | $Params.GroupTag = $formMainWindowControlGroupTagComboBox.Text
702 | }
703 |
704 | if (($formMainWindowControlAssignedUserTextBox.Text -gt 0) -and ($formMainWindowControlAssignedUserTextBox.Text -notmatch $Global:AutopilotOOBE.AssignedUserExample)) {
705 | $Params.AssignedUser = $formMainWindowControlAssignedUserTextBox.Text
706 | }
707 |
708 | if (($formMainWindowControlAssignedComputerNameTextBox.Text -gt 0) -and ($formMainWindowControlAssignedComputerNameTextBox.Text -notmatch $Global:AutopilotOOBE.AssignedComputerNameExample)) {
709 | $Params.AssignedComputerName = $formMainWindowControlAssignedComputerNameTextBox.Text
710 | }
711 |
712 | $Transcript = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-AutopilotOOBE.log"
713 | Start-Transcript -Path (Join-Path "$env:SystemRoot\Temp" $Transcript) -ErrorAction Ignore
714 |
715 | Write-Host -ForegroundColor Cyan "Install-Script Get-WindowsAutoPilotInfo"
716 | Start-Sleep -Seconds 3
717 | Install-Script Get-WindowsAutoPilotInfo -Force -Verbose
718 |
719 | Write-Host ($Params | Out-String)
720 | Write-Host -ForegroundColor Cyan "Get-WindowsAutoPilotInfo @Params"
721 |
722 | Start-Sleep -Seconds 3
723 | $formMainWindow.Title = "AutopilotOOBE $ModuleVersion : Registering Device"
724 | Get-WindowsAutoPilotInfo @Params
725 | $formMainWindow.Title = "AutopilotOOBE $ModuleVersion : Restart Device"
726 |
727 | if ((Get-Process -Name powershell).MainWindowTitle -match 'Running') {
728 | Write-Warning "Waiting for Start-OOBEDeploy to finish"
729 | }
730 |
731 | while ((Get-Process -Name powershell).MainWindowTitle -match 'Running') {
732 | Start-Sleep -Seconds 10
733 | }
734 |
735 | if ($formMainWindowControlPostActionComboBox.SelectedValue -eq 'Restart Computer') {Restart-Computer}
736 | if ($formMainWindowControlPostActionComboBox.SelectedValue -eq 'Shutdown Computer') {Stop-Computer}
737 |
738 | if ($formMainWindowControlPostActionComboBox.SelectedValue -match 'Sysprep') {
739 | Write-Host -ForegroundColor Cyan "Executing Sysprep"
740 |
741 | if ($formMainWindowControlPostActionComboBox.SelectedValue -match 'quit') {
742 | Start-Sleep -Seconds 3
743 | Start-Process "$env:SystemRoot\System32\Sysprep\Sysprep.exe" -ArgumentList "/oobe", "/quit" -Wait
744 | }
745 |
746 | elseif (($formMainWindowControlPostActionComboBox.SelectedValue -match 'reboot') -and ($formMainWindowControlPostActionComboBox.SelectedValue -match 'generalize')) {
747 | Start-Sleep -Seconds 3
748 | Start-Process "$env:SystemRoot\System32\Sysprep\Sysprep.exe" -ArgumentList "generalize", "/oobe", "/reboot" -Wait
749 | }
750 | elseif (($formMainWindowControlPostActionComboBox.SelectedValue -match 'shutdown') -and ($formMainWindowControlPostActionComboBox.SelectedValue -match 'generalize')) {
751 | Start-Sleep -Seconds 3
752 | Start-Process "$env:SystemRoot\System32\Sysprep\Sysprep.exe" -ArgumentList "generalize", "/oobe", "/reboot" -Wait
753 | }
754 |
755 | elseif ($formMainWindowControlPostActionComboBox.SelectedValue -match 'reboot') {
756 | Start-Sleep -Seconds 3
757 | Start-Process "$env:SystemRoot\System32\Sysprep\Sysprep.exe" -ArgumentList "/oobe", "/reboot" -Wait
758 | }
759 | elseif ($formMainWindowControlPostActionComboBox.SelectedValue -match 'shutdown') {
760 | Start-Sleep -Seconds 3
761 | Start-Process "$env:SystemRoot\System32\Sysprep\Sysprep.exe" -ArgumentList "/oobe", "/shutdown" -Wait
762 | }
763 | }
764 | })
765 | #================================================
766 | # Hide Windows
767 | #================================================
768 | Hide-CmdWindow
769 | Hide-PowershellWindow
770 | ########################
771 | ## WIRE UP YOUR CONTROLS
772 | ########################
773 | # simple example: $formMainWindowControlButton.Add_Click({ your code })
774 | #
775 | # example with BackgroundScriptBlock and UpdateElement
776 | # $formmainControlButton.Add_Click({
777 | # $sb = {
778 | # $SyncClass.UpdateElement("formmainControlProgress","Value",25)
779 | # }
780 | # Start-BackgroundScriptBlock $sb
781 | # })
782 |
783 | ############################
784 | ###### DISPLAY DIALOG ######
785 | ############################
786 | [void]$formMainWindow.ShowDialog()
787 |
788 | ##########################
789 | ##### SCRIPT CLEANUP #####
790 | ##########################
791 | $jobCleanup.Flag = $false #Stop Cleaning Jobs
792 | $jobCleanup.PowerShell.Runspace.Close() #Close the runspace
793 | $jobCleanup.PowerShell.Dispose() #Remove the runspace from memory
--------------------------------------------------------------------------------
/Project/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
13 |
14 |
15 |
71 |
75 |
79 |
83 |
93 |
94 |
95 |
96 |
100 |
101 |
102 |
104 |
106 |
109 |
110 |
111 |
112 |
113 |
115 |
117 |
119 |
121 |
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 |
157 |
158 |
166 |
167 |
175 |
176 |
184 |
185 |
195 |
206 |
207 |
208 |
209 |
215 |
216 |
217 |
218 |
224 |
225 |
226 |
227 |
228 |
234 |
235 |
247 |
248 |
249 |
250 |
257 |
258 |
270 |
271 |
272 |
273 |
279 |
280 |
290 |
291 |
292 |
293 |
299 |
300 |
311 |
312 |
313 |
314 |
321 |
322 |
333 |
334 |
335 |
336 | Assign: Wait for Intune to assign an Autopilot profile for this device
343 |
344 |
345 |
346 |
347 |
356 |
357 |
358 |
359 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
382 |
383 |
391 |
392 |
393 |
403 |
404 |
413 |
414 |
415 |
416 |
--------------------------------------------------------------------------------
/Project/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace AutopilotOOBE
17 | {
18 | ///
19 | /// Interaction logic for MainWindow.xaml
20 | ///
21 | public partial class MainWindow : Window
22 | {
23 | public MainWindow()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Project/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
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("AutopilotOOBE")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("AutopilotOOBE")]
15 | [assembly: AssemblyCopyright("Copyright © 2024")]
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 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the 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")]
56 |
--------------------------------------------------------------------------------
/Project/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 |
12 | namespace AutopilotOOBE.Properties
13 | {
14 | ///
15 | /// A strongly-typed resource class, for looking up localized strings, etc.
16 | ///
17 | // This class was auto-generated by the StronglyTypedResourceBuilder
18 | // class via a tool like ResGen or Visual Studio.
19 | // To add or remove a member, edit your .ResX file then rerun ResGen
20 | // with the /str option, or rebuild your VS project.
21 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
22 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
23 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
24 | internal class Resources
25 | {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources()
33 | {
34 | }
35 |
36 | ///
37 | /// Returns the cached ResourceManager instance used by this class.
38 | ///
39 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
40 | internal static global::System.Resources.ResourceManager ResourceManager
41 | {
42 | get
43 | {
44 | if ((resourceMan == null))
45 | {
46 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AutopilotOOBE.Properties.Resources", typeof(Resources).Assembly);
47 | resourceMan = temp;
48 | }
49 | return resourceMan;
50 | }
51 | }
52 |
53 | ///
54 | /// Overrides the current thread's CurrentUICulture property for all
55 | /// resource lookups using this strongly typed resource class.
56 | ///
57 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
58 | internal static global::System.Globalization.CultureInfo Culture
59 | {
60 | get
61 | {
62 | return resourceCulture;
63 | }
64 | set
65 | {
66 | resourceCulture = value;
67 | }
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Project/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/Project/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 |
12 | namespace AutopilotOOBE.Properties
13 | {
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
17 | {
18 |
19 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
20 |
21 | public static Settings Default
22 | {
23 | get
24 | {
25 | return defaultInstance;
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Project/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Public/Invoke-AutopilotOOBEcmd.ps1:
--------------------------------------------------------------------------------
1 | function Invoke-AutopilotOOBEcmd {
2 | [CmdletBinding()]
3 | param (
4 | [ValidateSet(
5 | 'AutopilotDiagnostics',
6 | 'AutopilotDiagnosticsOnline',
7 | 'GetTpm',
8 | 'ClearTpm',
9 | 'InitializeTpm',
10 | 'EventViewer'
11 | )]
12 | [string]$Action
13 | )
14 | #================================================
15 | # Resources
16 | #================================================
17 | $MDMEventLog = @'
18 |
19 |
20 |
21 |
22 |
23 |
24 | MDMDiagnosticsTool
25 | MDMDiagnosticsTool
26 | 1
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | '@
49 | #================================================
50 | # Transcript
51 | #================================================
52 | $Transcript = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$Action.log"
53 | Start-Transcript -Path (Join-Path "$env:SystemRoot\Temp" $Transcript) -ErrorAction Ignore
54 | #================================================
55 | # Switch
56 | #================================================
57 | switch ($Action) {
58 | AutopilotDiagnostics {
59 | if (!(Get-Command Get-AutopilotDiagnostics -ErrorAction Ignore)) {
60 | Write-Host -ForegroundColor Cyan "Install-Script Get-AutopilotDiagnostics -Force -Verbose"
61 | Install-Script Get-AutopilotDiagnostics -Force -Verbose
62 | }
63 | if (Test-Path "$env:ProgramFiles\WindowsPowerShell\Scripts\Get-AutopilotDiagnostics.ps1") {
64 | & "$env:ProgramFiles\WindowsPowerShell\Scripts\Get-AutopilotDiagnostics.ps1"
65 | }
66 | else {
67 | Write-Warning "Unable to find $env:ProgramFiles\WindowsPowerShell\Scripts\Get-AutopilotDiagnostics.ps1"
68 | }
69 | }
70 | AutopilotDiagnosticsOnline {
71 | if (!(Get-Command Get-AutopilotDiagnostics -ErrorAction Ignore)) {
72 | Write-Host -ForegroundColor Cyan "Install-Script Get-AutopilotDiagnostics -Force -Verbose"
73 | Install-Script Get-AutopilotDiagnostics -Force -Verbose
74 | }
75 | if (Test-Path "$env:ProgramFiles\WindowsPowerShell\Scripts\Get-AutopilotDiagnostics.ps1") {
76 | & "$env:ProgramFiles\WindowsPowerShell\Scripts\Get-AutopilotDiagnostics.ps1" -Online
77 | }
78 | else {
79 | Write-Warning "Unable to find $env:ProgramFiles\WindowsPowerShell\Scripts\Get-AutopilotDiagnostics.ps1"
80 | }
81 | }
82 | GetTpm {
83 | Get-Tpm
84 | }
85 | ClearTpm {
86 | Clear-Tpm
87 | Write-Warning "Restart the computer to complete the process"
88 | }
89 | InitializeTpm {
90 | Initialize-Tpm -AllowClear -AllowPhysicalPresence
91 | Write-Warning "Restart the computer to complete the process"
92 | }
93 | EventViewer {
94 | $MDMEventLog | Set-Content -Path "$env:ProgramData\Microsoft\Event Viewer\Views\MDMDiagnosticsTool.xml" -Force
95 | Start-Sleep -Seconds 2
96 | try {
97 | Restart-Service -Name EventLog -Force -ErrorAction Ignore
98 | }
99 | catch {
100 | #Nothing
101 | }
102 | Show-EventLog
103 | }
104 | }
105 | Stop-Transcript
106 | }
--------------------------------------------------------------------------------
/Public/Start-AutopilotOOBE.ps1:
--------------------------------------------------------------------------------
1 | function Start-AutopilotOOBE {
2 | [CmdletBinding()]
3 | param (
4 | [Parameter(ValueFromPipeline = $true)]
5 | [string]$CustomProfile,
6 |
7 | [ValidateSet (
8 | 'GroupTag',
9 | 'AddToGroup',
10 | 'AssignedUser',
11 | 'AssignedComputerName',
12 | 'PostAction',
13 | 'Assign'
14 | )]
15 | [string[]]$Disabled,
16 |
17 | [ValidateSet (
18 | 'GroupTag',
19 | 'AddToGroup',
20 | 'AssignedUser',
21 | 'AssignedComputerName',
22 | 'PostAction',
23 | 'Assign',
24 | 'Register',
25 | 'Run',
26 | 'Docs'
27 | )]
28 | [string[]]$Hidden,
29 |
30 | [string]$AddToGroup,
31 | [string[]]$AddToGroupOptions,
32 | [switch]$Assign,
33 | [string]$AssignedUser,
34 | [string]$AssignedUserExample = 'someone@example.com',
35 | [string]$AssignedComputerName,
36 | [string]$AssignedComputerNameExample = 'Azure AD Join Only',
37 | [string]$GroupTag,
38 | [string[]]$GroupTagOptions,
39 | [ValidateSet (
40 | 'Quit',
41 | 'Restart',
42 | 'Shutdown',
43 | 'Sysprep',
44 | 'SysprepReboot',
45 | 'SysprepShutdown',
46 | 'GeneralizeReboot',
47 | 'GeneralizeShutdown'
48 | )]
49 | [string]$PostAction = 'Quit',
50 | [ValidateSet (
51 | 'CommandPrompt',
52 | 'PowerShell',
53 | 'PowerShellISE',
54 | 'WindowsExplorer',
55 | 'WindowsSettings',
56 | 'NetworkingWireless',
57 | 'Restart',
58 | 'Shutdown',
59 | 'Sysprep',
60 | 'SysprepReboot',
61 | 'SysprepShutdown',
62 | 'SysprepAudit',
63 | 'EventViewer',
64 | 'GetAutopilotDiagnostics',
65 | 'GetAutopilotDiagnosticsOnline',
66 | 'MDMDiag',
67 | 'MDMDiagAutopilot',
68 | 'MDMDiagAutopilotTPM'
69 | )]
70 | [string]$Run = 'PowerShell',
71 | [string]$Docs,
72 | [string]$Title = 'Autopilot Manual Registration'
73 | )
74 | #================================================
75 | # WinPE and WinOS Start
76 | #================================================
77 | if ($env:SystemDrive -eq 'X:') {
78 | Write-Host -ForegroundColor DarkGray "========================================================================="
79 | Write-Host -ForegroundColor Green "Start-AutopilotOOBE in WinPE"
80 | $ProgramDataOSDeploy = 'C:\ProgramData\OSDeploy'
81 | $JsonPath = "$ProgramDataOSDeploy\OSDeploy.AutopilotOOBE.json"
82 | }
83 | if ($env:SystemDrive -ne 'X:') {
84 | Write-Host -ForegroundColor DarkGray "========================================================================="
85 | Write-Host -ForegroundColor Green "Start-AutopilotOOBE"
86 | $ProgramDataOSDeploy = "$env:ProgramData\OSDeploy"
87 | $JsonPath = "$ProgramDataOSDeploy\OSDeploy.AutopilotOOBE.json"
88 | }
89 | #================================================
90 | # WinOS Transcript
91 | #================================================
92 | if ($env:SystemDrive -ne 'X:') {
93 | Write-Host -ForegroundColor DarkGray "========================================================================="
94 | Write-Host -ForegroundColor Cyan "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Start-Transcript"
95 | $Transcript = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Start-AutopilotOOBE.log"
96 | Start-Transcript -Path (Join-Path "$env:SystemRoot\Temp" $Transcript) -ErrorAction Ignore
97 | $host.ui.RawUI.WindowTitle = "Start-AutopilotOOBE $env:SystemRoot\Temp\$Transcript"
98 | }
99 | #================================================
100 | # WinOS Console Disable Line Wrap
101 | #================================================
102 | reg add HKCU\Console /v LineWrap /t REG_DWORD /d 0 /f
103 | #================================================
104 | # Custom Profile Sample Variables
105 | #================================================
106 | if ($CustomProfile -eq 'Sample') {
107 | $Title = 'Sample Autopilot Registration'
108 | $AddToGroup = 'Administrators'
109 | $AssignedUserExample = 'someone@osdeploy.com'
110 | $AssignedComputerName = 'OSD-' + ((Get-CimInstance -ClassName Win32_BIOS).SerialNumber).Trim()
111 | $PostAction = 'Shutdown'
112 | $Assign = $true
113 | $Run = 'PowerShell'
114 | $Docs = 'https://www.osdeploy.com/'
115 | $Hidden = 'GroupTag'
116 | }
117 | #================================================
118 | # Custom Profile
119 | #================================================
120 | if ($CustomProfile) {
121 | Write-Host -ForegroundColor DarkGray "========================================================================="
122 | Write-Host -ForegroundColor Cyan "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Loading AutopilotOOBE Custom Profile $CustomProfile"
123 |
124 | $CustomProfileJson = Get-ChildItem "$($MyInvocation.MyCommand.Module.ModuleBase)\CustomProfile" *.json | Where-Object {$_.BaseName -eq $CustomProfile} | Select-Object -First 1
125 |
126 | if ($CustomProfileJson) {
127 | Write-Host -ForegroundColor DarkGray "Saving Module CustomProfile to $JsonPath"
128 | if (!(Test-Path "$ProgramDataOSDeploy")) {New-Item "$ProgramDataOSDeploy" -ItemType Directory -Force | Out-Null}
129 | Copy-Item -Path $CustomProfileJson.FullName -Destination $JsonPath -Force -ErrorAction Ignore
130 | }
131 | }
132 | #================================================
133 | # Import Json
134 | #================================================
135 | if (Test-Path $JsonPath) {
136 | Write-Host -ForegroundColor DarkGray "Importing Configuration $JsonPath"
137 | $ImportAutopilotOOBE = @()
138 | $ImportAutopilotOOBE = Get-Content -Raw -Path $JsonPath | ConvertFrom-Json
139 |
140 | $ImportAutopilotOOBE.PSObject.Properties | ForEach-Object {
141 | if ($_.Value -match 'IsPresent=True') {
142 | $_.Value = $true
143 | }
144 | if ($_.Value -match 'IsPresent=False') {
145 | $_.Value = $false
146 | }
147 | if ($null -eq $_.Value) {
148 | Continue
149 | }
150 | Set-Variable -Name $_.Name -Value $_.Value -Force
151 | }
152 | }
153 | #================================================
154 | # WinOS
155 | #================================================
156 | if ($env:SystemDrive -ne 'X:') {
157 | #================================================
158 | # Set-PSRepository
159 | #================================================
160 | $PSGalleryIP = (Get-PSRepository -Name PSGallery).InstallationPolicy
161 | if ($PSGalleryIP -eq 'Untrusted') {
162 | Write-Host -ForegroundColor DarkGray "========================================================================="
163 | Write-Host -ForegroundColor Cyan "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Set-PSRepository -Name PSGallery -InstallationPolicy Trusted"
164 | Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
165 | }
166 | #================================================
167 | # Watch-AutopilotOOBEevents
168 | #================================================
169 | Write-Host -ForegroundColor DarkGray "========================================================================="
170 | Write-Host -ForegroundColor Cyan "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Watch-AutopilotOOBEevents"
171 | Write-Host -ForegroundColor DarkCyan 'The EventLog is being monitored for MDM Diagnostic Events in a minimized window'
172 | Write-Host -ForegroundColor DarkCyan 'Use Alt+Tab to view the progress in the separate PowerShell session'
173 | Start-Process PowerShell.exe -WindowStyle Minimized -ArgumentList "-NoExit -Command Watch-AutopilotOOBEevents"
174 | #================================================
175 | # Test-AutopilotOOBEnetwork
176 | #================================================
177 | Write-Host -ForegroundColor DarkGray "========================================================================="
178 | Write-Host -ForegroundColor Cyan "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Test-AutopilotOOBEnetwork"
179 | Write-Host -ForegroundColor DarkCyan 'Required Autopilot network addresses are being tested in a minimized window'
180 | Write-Host -ForegroundColor DarkCyan 'Use Alt+Tab to view the progress in the separate PowerShell session'
181 | Start-Process PowerShell.exe -WindowStyle Minimized -ArgumentList "-NoExit -Command Test-AutopilotOOBEnetwork"
182 | #================================================
183 | # Test-AutopilotRegistry
184 | #================================================
185 | Write-Host -ForegroundColor DarkGray "========================================================================="
186 | Write-Host -ForegroundColor Cyan "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Test-AutopilotRegistry"
187 | Write-Host -ForegroundColor DarkCyan 'Gathering Autopilot Registration information from the Registry'
188 | $Global:RegAutoPilot = Get-ItemProperty 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Provisioning\Diagnostics\AutoPilot'
189 |
190 | Write-Host -ForegroundColor Gray "IsAutoPilotDisabled: $($Global:RegAutoPilot.IsAutoPilotDisabled)"
191 | Write-Host -ForegroundColor Gray "CloudAssignedForcedEnrollment: $($Global:RegAutoPilot.CloudAssignedForcedEnrollment)"
192 | Write-Host -ForegroundColor Gray "CloudAssignedTenantDomain: $($Global:RegAutoPilot.CloudAssignedTenantDomain)"
193 | Write-Host -ForegroundColor Gray "CloudAssignedTenantId: $($Global:RegAutoPilot.CloudAssignedTenantId)"
194 | Write-Host -ForegroundColor Gray "CloudAssignedTenantUpn: $($Global:RegAutoPilot.CloudAssignedTenantUpn)"
195 | Write-Host -ForegroundColor Gray "CloudAssignedLanguage: $($Global:RegAutoPilot.CloudAssignedLanguage)"
196 |
197 | if ($Global:RegAutoPilot.CloudAssignedForcedEnrollment -eq 1) {
198 | Write-Host -ForegroundColor Gray "TenantId: $($Global:RegAutoPilot.TenantId)"
199 | Write-Host -ForegroundColor Gray "CloudAssignedMdmId: $($Global:RegAutoPilot.CloudAssignedMdmId)"
200 | Write-Host -ForegroundColor Gray "AutopilotServiceCorrelationId: $($Global:RegAutoPilot.AutopilotServiceCorrelationId)"
201 | Write-Host -ForegroundColor Gray "CloudAssignedOobeConfig: $($Global:RegAutoPilot.CloudAssignedOobeConfig)"
202 | Write-Host -ForegroundColor Gray "CloudAssignedTelemetryLevel: $($Global:RegAutoPilot.CloudAssignedTelemetryLevel)"
203 | Write-Host -ForegroundColor Gray "IsDevicePersonalized: $($Global:RegAutoPilot.IsDevicePersonalized)"
204 | Write-Host -ForegroundColor Gray "SetTelemetryLevel_Succeeded_With_Level: $($Global:RegAutoPilot.SetTelemetryLevel_Succeeded_With_Level)"
205 | Write-Host -ForegroundColor Gray "IsForcedEnrollmentEnabled: $($Global:RegAutoPilot.IsForcedEnrollmentEnabled)"
206 | Write-Host -ForegroundColor Green "This device has already been Autopilot Registered. Registration will not be enabled"
207 | Start-Sleep -Seconds 2
208 | $Disabled = 'GroupTag','AddToGroup','AssignedUser','AssignedComputerName','PostAction','Assign'
209 | $Hidden = 'GroupTag','AddToGroup','AssignedUser','AssignedComputerName','PostAction','Assign','Register'
210 | $Run = 'MDMDiagAutopilotTPM'
211 | $Title = 'Autopilot Registration Information'
212 | }
213 | #================================================
214 | # Date Time
215 | #================================================
216 | Write-Host -ForegroundColor DarkGray "========================================================================="
217 | Write-Host -ForegroundColor Cyan "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Verify Date and Time"
218 | Write-Host -ForegroundColor DarkCyan 'Make sure the Time is set properly in the System BIOS as this can cause issues'
219 | Get-Date
220 | Get-TimeZone
221 | Start-Sleep -Seconds 5
222 | #================================================
223 | # RegisterButton
224 | #================================================
225 | if ($env:UserName -ne 'defaultuser0') {
226 | Write-Warning 'The register button is disabled when the UserName is not defaultuser0'
227 | Start-Sleep -Seconds 5
228 | }
229 | }
230 | #================================================
231 | # WinPE and WinOS Configuration Json
232 | #================================================
233 | $Global:AutopilotOOBE = [ordered]@{
234 | AddToGroup = $AddToGroup
235 | AddToGroupOptions = $AddToGroupOptions
236 | Assign = $Assign
237 | AssignedUser = $AssignedUser
238 | AssignedUserExample = $AssignedUserExample
239 | AssignedComputerName = $AssignedComputerName
240 | AssignedComputerNameExample = $AssignedComputerNameExample
241 | Disabled = $Disabled
242 | GroupTag = $GroupTag
243 | GroupTagOptions = $GroupTagOptions
244 | Hidden = $Hidden
245 | PostAction = $PostAction
246 | Run = $Run
247 | Docs = $Docs
248 | Title = $Title
249 | }
250 | if ($env:SystemDrive -eq 'X:') {
251 | if (!(Test-Path "$ProgramDataOSDeploy")) {New-Item "$ProgramDataOSDeploy" -ItemType Directory -Force | Out-Null}
252 | Write-Host -ForegroundColor DarkGray "Exporting Configuration $ProgramDataOSDeploy\OSDeploy.AutopilotOOBE.json"
253 | @($Global:AutopilotOOBE.Keys) | ForEach-Object {
254 | if (-not $Global:AutopilotOOBE[$_]) { $Global:AutopilotOOBE.Remove($_) }
255 | }
256 | $Global:AutopilotOOBE | ConvertTo-Json | Out-File "$ProgramDataOSDeploy\OSDeploy.AutopilotOOBE.json" -Force
257 | }
258 | else {
259 | Write-Host -ForegroundColor DarkGray "Exporting Configuration $env:Temp\OSDeploy.AutopilotOOBE.json"
260 | @($Global:AutopilotOOBE.Keys) | ForEach-Object {
261 | if (-not $Global:AutopilotOOBE[$_]) { $Global:AutopilotOOBE.Remove($_) }
262 | }
263 | $Global:AutopilotOOBE | ConvertTo-Json | Out-File "$env:Temp\OSDeploy.AutopilotOOBE.json" -Force
264 | #================================================
265 | # Launch
266 | #================================================
267 | Write-Host -ForegroundColor DarkGray "========================================================================="
268 | Write-Host -ForegroundColor Cyan "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Starting AutopilotOOBE GUI"
269 | Start-Sleep -Seconds 2
270 | & "$($MyInvocation.MyCommand.Module.ModuleBase)\Project\MainWindow.ps1"
271 | #================================================
272 | }
273 | }
--------------------------------------------------------------------------------
/Public/Test-AutopilotOOBEconnection.ps1:
--------------------------------------------------------------------------------
1 | function Test-AutopilotOOBEconnection {
2 | [CmdletBinding()]
3 | param (
4 | [Parameter(ValueFromPipeline = $True)]
5 | [string]$Uri = 'google.com'
6 | )
7 |
8 | begin {}
9 |
10 | process {
11 | $Params = @{
12 | Method = 'Head'
13 | Uri = $Uri
14 | UseBasicParsing = $True
15 | }
16 |
17 | try {
18 | Write-Verbose "Test-WebConnection OK: $Uri"
19 | Invoke-WebRequest @Params | Out-Null
20 | $true
21 | }
22 | catch {
23 | Write-Verbose "Test-WebConnection FAIL: $Uri"
24 | $false
25 | }
26 | finally {
27 | $Error.Clear()
28 | }
29 | }
30 |
31 | end {}
32 | }
--------------------------------------------------------------------------------
/Public/Test-AutopilotOOBEnetwork.ps1:
--------------------------------------------------------------------------------
1 | function Test-AutopilotOOBEnetwork {
2 | [CmdletBinding()]
3 | param ()
4 | #================================================
5 | # Initialize
6 | #================================================
7 | $Title = 'Test-AutopilotOOBEnetwork'
8 | $host.ui.RawUI.WindowTitle = $Title
9 | $host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.size(2000,2000)
10 | $host.ui.RawUI.BackgroundColor = ($bckgrnd = 'Black')
11 | Clear-Host
12 | #================================================
13 | # Temp
14 | #================================================
15 | if (!(Test-Path "$env:SystemDrive\Temp")) {
16 | New-Item -Path "$env:SystemDrive\Temp" -ItemType Directory -Force
17 | }
18 | #================================================
19 | # Transcript
20 | #================================================
21 | $Transcript = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$Title.log"
22 | Start-Transcript -Path (Join-Path "$env:SystemDrive\Temp" $Transcript) -ErrorAction Ignore
23 | $host.ui.RawUI.WindowTitle = "$Title $env:SystemDrive\Temp\$Transcript"
24 | #================================================
25 | # Networking Requirements
26 | #================================================
27 | Write-Host -ForegroundColor DarkGray '========================================================================='
28 | Write-Host -ForegroundColor Cyan "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Test HTTPS Networking Requirements"
29 | Write-Host -ForegroundColor DarkGray "https://docs.microsoft.com/en-us/mem/autopilot/networking-requirements"
30 |
31 | $Global:ProgressPreference = 'SilentlyContinue'
32 | #================================================
33 | # Microsoft NCSI Connect Test
34 | #================================================
35 | Write-Host -ForegroundColor DarkGray '========================================================================='
36 | Write-Host -ForegroundColor Cyan 'Microsoft NCSI Connect Test'
37 |
38 | $Urls = @(
39 | 'http://www.msftconnecttest.com/connecttest.txt'
40 | )
41 |
42 | foreach ($Uri in $Urls){
43 | try {
44 | if ($null = Invoke-WebRequest -Uri $Uri -Method Head -UseBasicParsing -ErrorAction Stop) {
45 | Write-Host -ForegroundColor DarkCyan "PASS: $Uri"
46 | }
47 | else {
48 | }
49 | }
50 | catch {
51 | Write-Host -ForegroundColor Yellow "FAIL: $Uri"
52 | }
53 | }
54 | #================================================
55 | # PowerShell Gallery
56 | #================================================
57 | Write-Host -ForegroundColor DarkGray '========================================================================='
58 | Write-Host -ForegroundColor Cyan "PowerShell Gallery"
59 |
60 | $ComputerNames = @('powershellgallery.com')
61 | $Ports = @(443)
62 |
63 | foreach ($ComputerName in $ComputerNames){
64 | foreach ($Port in $Ports){
65 | try {
66 | if (Test-NetConnection -ComputerName $ComputerName -Port $Port -InformationLevel Quiet -ErrorAction Stop -WarningAction 'Continue') {
67 | Write-Host -ForegroundColor DarkCyan "PASS: $ComputerName [Port: $Port]"
68 | }
69 | else {
70 | Write-Host -ForegroundColor Yellow "FAIL: $ComputerName [Port: $Port]"
71 | }
72 | }
73 | catch {}
74 | finally {}
75 | }
76 | }
77 | #================================================
78 | # Windows Autopilot Deployment Service
79 | #================================================
80 | Write-Host -ForegroundColor DarkGray '========================================================================='
81 | Write-Host -ForegroundColor Cyan "Windows Autopilot Deployment Service"
82 |
83 | $ComputerNames = @(
84 | 'cs.dds.microsoft.com'
85 | 'login.live.com'
86 | 'ztd.dds.microsoft.com'
87 | )
88 | $Ports = @(443)
89 |
90 | foreach ($ComputerName in $ComputerNames){
91 | foreach ($Port in $Ports){
92 | try {
93 | if (Test-NetConnection -ComputerName $ComputerName -Port $Port -InformationLevel Quiet -ErrorAction Stop -WarningAction 'Continue') {
94 | Write-Host -ForegroundColor DarkCyan "PASS: $ComputerName [Port: $Port]"
95 | }
96 | else {
97 | Write-Host -ForegroundColor Yellow "FAIL: $ComputerName [Port: $Port]"
98 | }
99 | }
100 | catch {}
101 | finally {}
102 | }
103 | }
104 | #================================================
105 | # Windows Activation
106 | # https://support.microsoft.com/en-us/topic/windows-activation-or-validation-fails-with-error-code-0x8004fe33-a9afe65e-230b-c1ed-3414-39acd7fddf52
107 | #================================================
108 | Write-Host -ForegroundColor DarkGray '========================================================================='
109 | Write-Host -ForegroundColor Cyan 'Windows Activation'
110 |
111 | $Urls = @(
112 | 'http://crl.microsoft.com/pki/crl/products/MicProSecSerCA_2007-12-04.crl'
113 | )
114 |
115 | foreach ($Uri in $Urls){
116 | try {
117 | if ($null = Invoke-WebRequest -Uri $Uri -Method Head -UseBasicParsing -ErrorAction Stop) {
118 | Write-Host -ForegroundColor DarkCyan "PASS: $Uri"
119 | }
120 | else {
121 | }
122 | }
123 | catch {
124 | Write-Host -ForegroundColor Yellow "FAIL: $Uri"
125 | }
126 | }
127 |
128 | $ComputerNames = @(
129 | 'activation.sls.microsoft.com'
130 | 'activation-v2.sls.microsoft.com'
131 | 'displaycatalog.mp.microsoft.com'
132 | 'displaycatalog.md.mp.microsoft.com'
133 | 'go.microsoft.com'
134 | 'licensing.mp.microsoft.com'
135 | 'licensing.md.mp.microsoft.com'
136 | 'login.live.com'
137 | 'purchase.md.mp.microsoft.com'
138 | 'purchase.mp.microsoft.com'
139 | 'validation.sls.microsoft.com'
140 | 'validation-v2.sls.microsoft.com'
141 | )
142 | $Ports = @(443)
143 |
144 | foreach ($ComputerName in $ComputerNames){
145 | foreach ($Port in $Ports){
146 | try {
147 | if (Test-NetConnection -ComputerName $ComputerName -Port $Port -InformationLevel Quiet -ErrorAction Stop -WarningAction 'Continue') {
148 | Write-Host -ForegroundColor DarkCyan "PASS: $ComputerName [Port: $Port]"
149 | }
150 | else {
151 | Write-Host -ForegroundColor Yellow "FAIL: $ComputerName [Port: $Port]"
152 | }
153 | }
154 | catch {}
155 | finally {}
156 | }
157 | }
158 | #================================================
159 | # Azure Active Directory | Office 365 IP Address and URL web service
160 | # https://docs.microsoft.com/en-us/microsoft-365/enterprise/microsoft-365-ip-web-service?view=o365-worldwide
161 | #================================================
162 | Write-Host -ForegroundColor DarkGray '========================================================================='
163 | Write-Host -ForegroundColor Cyan "Office 365 IP Address and URL Web Service"
164 |
165 | $Urls = @()
166 |
167 | foreach ($Uri in $Urls){
168 | try {
169 | if ($null = Invoke-WebRequest -Uri $Uri -Method Head -UseBasicParsing -ErrorAction Stop) {
170 | Write-Host -ForegroundColor DarkCyan "PASS: $Uri"
171 | }
172 | else {
173 | }
174 | }
175 | catch {
176 | Write-Host -ForegroundColor Yellow "FAIL: $Uri"
177 | }
178 | }
179 |
180 | $ComputerNames = @(
181 | 'broadcast.skype.com'
182 | 'compliance.microsoft.com'
183 | 'lync.com'
184 | 'mail.protection.outlook.com'
185 | 'msftidentity.com'
186 | 'msidentity.com'
187 | 'officeapps.live.com'
188 | 'online.office.com'
189 | 'outlook.office.com'
190 | 'portal.cloudappsecurity.com'
191 | 'protection.office.com'
192 | 'protection.outlook.com'
193 | 'security.microsoft.com'
194 | 'sharepoint.com'
195 | 'skypeforbusiness.com'
196 | 'teams.microsoft.com'
197 | 'account.activedirectory.windowsazure.com'
198 | 'account.office.net'
199 | 'accounts.accesscontrol.windows.net'
200 | 'adminwebservice.microsoftonline.com'
201 | 'api.passwordreset.microsoftonline.com'
202 | 'autologon.microsoftazuread-sso.com'
203 | 'becws.microsoftonline.com'
204 | 'broadcast.skype.com'
205 | 'clientconfig.microsoftonline-p.net'
206 | 'companymanager.microsoftonline.com'
207 | 'compliance.microsoft.com'
208 | 'device.login.microsoftonline.com'
209 | 'graph.microsoft.com'
210 | 'graph.windows.net'
211 | 'login.microsoft.com'
212 | 'login.microsoftonline.com'
213 | 'login.microsoftonline-p.com'
214 | 'login.windows.net'
215 | 'logincert.microsoftonline.com'
216 | 'loginex.microsoftonline.com'
217 | 'login-us.microsoftonline.com'
218 | 'nexus.microsoftonline-p.com'
219 | 'office.live.com'
220 | 'outlook.office.com'
221 | 'outlook.office365.com'
222 | 'passwordreset.microsoftonline.com'
223 | 'protection.office.com'
224 | 'provisioningapi.microsoftonline.com'
225 | 'security.microsoft.com'
226 | 'smtp.office365.com'
227 | 'teams.microsoft.com'
228 | )
229 | $Ports = @(443)
230 |
231 | foreach ($ComputerName in $ComputerNames){
232 | foreach ($Port in $Ports){
233 | try {
234 | if (Test-NetConnection -ComputerName $ComputerName -Port $Port -InformationLevel Quiet -ErrorAction Stop -WarningAction 'Continue') {
235 | Write-Host -ForegroundColor DarkCyan "PASS: $ComputerName [Port: $Port]"
236 | }
237 | else {
238 | Write-Host -ForegroundColor Yellow "FAIL: $ComputerName [Port: $Port]"
239 | }
240 | }
241 | catch {}
242 | finally {}
243 | }
244 | }
245 | #================================================
246 | # Intune
247 | # https://docs.microsoft.com/en-us/mem/intune/fundamentals/network-bandwidth-use
248 | # https://docs.microsoft.com/en-us/mem/intune/fundamentals/intune-endpoints#access-for-managed-devices
249 | #================================================
250 | Write-Host -ForegroundColor DarkGray '========================================================================='
251 | Write-Host -ForegroundColor Cyan "Intune Access for managed devices"
252 |
253 | $ComputerNames = @(
254 | 'login.microsoftonline.com'
255 | #'*.officeconfig.msocdn.com'
256 | 'config.office.com'
257 | 'graph.windows.net'
258 | 'enterpriseregistration.windows.net'
259 | 'portal.manage.microsoft.com'
260 | 'm.manage.microsoft.com'
261 | 'fef.msuc03.manage.microsoft.com'
262 | 'wip.mam.manage.microsoft.com'
263 | 'mam.manage.microsoft.com'
264 | #'*manage.microsoft.com'
265 | )
266 | $Ports = @(443)
267 |
268 | foreach ($ComputerName in $ComputerNames){
269 | foreach ($Port in $Ports){
270 | try {
271 | if (Test-NetConnection -ComputerName $ComputerName -Port $Port -InformationLevel Quiet -ErrorAction Stop -WarningAction 'Continue') {
272 | Write-Host -ForegroundColor DarkCyan "PASS: $ComputerName [Port: $Port]"
273 | }
274 | else {
275 | Write-Host -ForegroundColor Yellow "FAIL: $ComputerName [Port: $Port]"
276 | }
277 | }
278 | catch {}
279 | finally {}
280 | }
281 | }
282 | #================================================
283 | # Intune
284 | # https://docs.microsoft.com/en-us/mem/intune/fundamentals/network-bandwidth-use
285 | # https://docs.microsoft.com/en-us/mem/intune/fundamentals/intune-endpoints#network-requirements-for-powershell-scripts-and-win32-apps
286 | #================================================
287 | Write-Host -ForegroundColor DarkGray '========================================================================='
288 | Write-Host -ForegroundColor Cyan "Intune Network requirements for PowerShell scripts and Win32 apps"
289 |
290 | $ComputerNames = @(
291 | 'naprodimedatapri.azureedge.net'
292 | 'naprodimedatasec.azureedge.net'
293 | 'naprodimedatahotfix.azureedge.net'
294 | 'euprodimedatapri.azureedge.net'
295 | 'euprodimedatasec.azureedge.net'
296 | 'euprodimedatahotfix.azureedge.net'
297 | 'approdimedatapri.azureedge.net'
298 | 'approdimedatasec.azureedge.net'
299 | 'approdimedatahotfix.azureedge.net'
300 |
301 | )
302 | $Ports = @(443)
303 |
304 | foreach ($ComputerName in $ComputerNames){
305 | foreach ($Port in $Ports){
306 | try {
307 | if (Test-NetConnection -ComputerName $ComputerName -Port $Port -InformationLevel Quiet -ErrorAction Stop -WarningAction 'Continue') {
308 | Write-Host -ForegroundColor DarkCyan "PASS: $ComputerName [Port: $Port]"
309 | }
310 | else {
311 | Write-Host -ForegroundColor Yellow "FAIL: $ComputerName [Port: $Port]"
312 | }
313 | }
314 | catch {}
315 | finally {}
316 | }
317 | }
318 | #================================================
319 | # Windows Update
320 | # https://docs.microsoft.com/en-US/windows/deployment/update/windows-update-troubleshooting
321 | #================================================
322 | Write-Host -ForegroundColor DarkGray '========================================================================='
323 | Write-Host -ForegroundColor Cyan "Windows Update"
324 |
325 | $ComputerNames = @(
326 | 'emdl.ws.microsoft.com'
327 | 'dl.delivery.mp.microsoft.com'
328 | #'windowsupdate.com'
329 | )
330 | $Ports = @(80)
331 |
332 | foreach ($ComputerName in $ComputerNames){
333 | foreach ($Port in $Ports){
334 | try {
335 | if (Test-NetConnection -ComputerName $ComputerName -Port $Port -InformationLevel Quiet -ErrorAction Stop -WarningAction 'Continue') {
336 | Write-Host -ForegroundColor DarkCyan "PASS: $ComputerName [Port: $Port]"
337 | }
338 | else {
339 | Write-Host -ForegroundColor Yellow "FAIL: $ComputerName [Port: $Port]"
340 | }
341 | }
342 | catch {}
343 | finally {}
344 | }
345 | }
346 | #================================================
347 | # Autopilot self-Deploying mode and Autopilot pre-provisioning
348 | #================================================
349 | Write-Host -ForegroundColor DarkGray '========================================================================='
350 | Write-Host -ForegroundColor Cyan "Autopilot self-Deploying mode and Autopilot pre-provisioning"
351 |
352 | $ComputerNames = @(
353 | 'ekop.intel.com'
354 | 'ekcert.spserv.microsoft.com'
355 | 'ftpm.amd.com'
356 | )
357 | $Ports = @(443)
358 |
359 | foreach ($ComputerName in $ComputerNames){
360 | foreach ($Port in $Ports){
361 | try {
362 | if (Test-NetConnection -ComputerName $ComputerName -Port $Port -InformationLevel Quiet -ErrorAction Stop -WarningAction 'Continue') {
363 | Write-Host -ForegroundColor DarkCyan "PASS: $ComputerName [Port: $Port]"
364 | }
365 | else {
366 | Write-Host -ForegroundColor Yellow "FAIL: $ComputerName [Port: $Port]"
367 | }
368 | }
369 | catch {}
370 | finally {}
371 | }
372 | }
373 | #================================================
374 | # Complete
375 | #================================================
376 | $Global:ProgressPreference = 'Continue'
377 | }
--------------------------------------------------------------------------------
/Public/Watch-AutopilotOOBEevents.ps1:
--------------------------------------------------------------------------------
1 | function Watch-AutopilotOOBEevents {
2 | [CmdletBinding()]
3 | param (
4 | [switch]$Full
5 | )
6 | #================================================
7 | # Initialize
8 | #================================================
9 | $Title = 'Watch-AutopilotOOBEevents'
10 | $host.ui.RawUI.WindowTitle = $Title
11 | $host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.size(2000,2000)
12 | $host.ui.RawUI.BackgroundColor = ($bckgrnd = 'Black')
13 | Clear-Host
14 | #================================================
15 | # Temp
16 | #================================================
17 | if (!(Test-Path "$env:SystemDrive\Temp")) {
18 | New-Item -Path "$env:SystemDrive\Temp" -ItemType Directory -Force
19 | }
20 | #================================================
21 | # Transcript
22 | #================================================
23 | $Transcript = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$Title.log"
24 | Start-Transcript -Path (Join-Path "$env:SystemDrive\Temp" $Transcript) -ErrorAction Ignore
25 | $host.ui.RawUI.WindowTitle = "$Title $env:SystemDrive\Temp\$Transcript"
26 | #================================================
27 | # Main Variables
28 | #================================================
29 | $Monitor = $true
30 | $Results = @()
31 | $FormatEnumerationLimit = -1
32 | # This will go back 1 days in the logs. Adjust as needed
33 | [DateTime]$StartTime = (Get-Date).AddDays(- 1)
34 |
35 | $InfoWhite = @()
36 | $InfoCyan = @(62402,62406)
37 | $InfoBlue = @()
38 | $InfoDarkBlue = @()
39 |
40 | if ($Full) {
41 | $ExcludeEventId = @()
42 | }
43 | else {
44 | $ExcludeEventId = @(3,9,10,11,90,91)
45 | $ExcludeEventId += @(101,104,106,108,110,111,112,144)
46 | $ExcludeEventId += @(200,202,257,258,259,260,263,265,266,272)
47 | $ExcludeEventId += @(507,509,510,511,512,513,514,516,518,520,522,524,525)
48 | $ExcludeEventId += @(813)
49 | $ExcludeEventId += @(1000,1001,1100,1101,1102,1709)
50 | $ExcludeEventId += @(28017,28018,28019,28032,28115,28125)
51 | $ExcludeEventId += @(62144,62170,62460)
52 | $ExcludeEventId += @(705,1007)
53 | }
54 |
55 | # Remove Line Wrap
56 | reg add HKCU\Console /v LineWrap /t REG_DWORD /d 0 /f
57 | #================================================
58 | # LogName
59 | # These are the WinEvent logs to monitor
60 | #================================================
61 | $LogName = @(
62 | 'Microsoft-Windows-AAD/Operational'
63 | #'Microsoft-Windows-AppXDeploymentServer/Operational'
64 | 'Microsoft-Windows-AssignedAccess/Admin'
65 | 'Microsoft-Windows-AssignedAccess/Operational'
66 | 'Microsoft-Windows-AssignedAccessBroker/Admin'
67 | 'Microsoft-Windows-AssignedAccessBroker/Operational'
68 | 'Microsoft-Windows-Crypto-NCrypt/Operational'
69 | 'Microsoft-Windows-DeviceManagement-Enterprise-Diagnostics-Provider/Admin'
70 | #'Microsoft-Windows-DeviceManagement-Enterprise-Diagnostics-Provider/Debug'
71 | 'Microsoft-Windows-DeviceManagement-Enterprise-Diagnostics-Provider/Operational'
72 | 'Microsoft-Windows-ModernDeployment-Diagnostics-Provider/Autopilot'
73 | 'Microsoft-Windows-ModernDeployment-Diagnostics-Provider/ManagementService'
74 | 'Microsoft-Windows-Provisioning-Diagnostics-Provider/Admin'
75 | 'Microsoft-Windows-Shell-Core/Operational'
76 | 'Microsoft-Windows-Time-Service/Operational'
77 | 'Microsoft-Windows-User Device Registration/Admin'
78 | )
79 | #================================================
80 | # FilterHashtable
81 | #================================================
82 | $FilterHashtable = @{
83 | StartTime = $StartTime
84 | LogName = $LogName
85 | }
86 | #================================================
87 | # Get-WinEvent Results
88 | #================================================
89 | $Results = Get-WinEvent -FilterHashtable $FilterHashtable -ErrorAction Ignore | Sort-Object TimeCreated | Where-Object {$_.Id -notin $ExcludeEventId}
90 | $Results = $Results | Select-Object TimeCreated,LevelDisplayName,LogName,Id, @{Name='Message';Expression={ ($_.Message -Split '\n')[0]}}
91 | $Clixml = "$env:SystemDrive\Temp\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Events.clixml"
92 | $Results | Export-Clixml -Path $Clixml
93 | #================================================
94 | # Display Results
95 | #================================================
96 | foreach ($Item in $Results) {
97 | if ($Item.LevelDisplayName -eq 'Error') {
98 | Write-Host "$($Item.TimeCreated) ERROR:$($Item.Id)`t$($Item.Message)" -ForegroundColor Red
99 | }
100 | elseif ($Item.LevelDisplayName -eq 'Warning') {
101 | Write-Host "$($Item.TimeCreated) WARN :$($Item.Id)`t$($Item.Message)" -ForegroundColor Yellow
102 | }
103 | elseif (($Item.Message -match 'fail') -or ($Item.Message -match 'empty profile')) {
104 | Write-Host "$($Item.TimeCreated) INFO :$($Item.Id)`t$($Item.Message)" -ForegroundColor Red
105 | }
106 | elseif ($Item.Message -like "Autopilot*") {
107 | Write-Host "$($Item.TimeCreated) INFO :$($Item.Id)`t$($Item.Message)" -ForegroundColor Cyan
108 | }
109 | elseif ($Item.Id -in $InfoWhite) {
110 | Write-Host "$($Item.TimeCreated) INFO :$($Item.Id)`t$($Item.Message)" -ForegroundColor White
111 | }
112 | elseif ($Item.Id -in $InfoCyan) {
113 | Write-Host "$($Item.TimeCreated) INFO :$($Item.Id)`t$($Item.Message)" -ForegroundColor Cyan
114 | }
115 | elseif ($Item.Id -in $InfoBlue) {
116 | Write-Host "$($Item.TimeCreated) INFO :$($Item.Id)`t$($Item.Message)" -ForegroundColor Blue
117 | }
118 | elseif ($Item.Id -in $InfoDarkBlue) {
119 | Write-Host "$($Item.TimeCreated) INFO :$($Item.Id)`t$($Item.Message)" -ForegroundColor DarkBlue
120 | }
121 | else {
122 | Write-Host "$($Item.TimeCreated) INFO :$($Item.Id)`t$($Item.Message)" -ForegroundColor DarkGray
123 | }
124 | }
125 | #================================================
126 | # Monitor New Events
127 | #================================================
128 | if ($Monitor) {
129 | Write-Host -ForegroundColor Cyan "Listening for new events"
130 | while ($true) {
131 | Start-Sleep -Seconds 10 | Out-Null
132 | #================================================
133 | # Get-WinEvent NewResults
134 | #================================================
135 | $NewResults = @()
136 | $NewResults = Get-WinEvent -FilterHashtable $FilterHashtable -ErrorAction Ignore | Sort-Object TimeCreated | Where-Object {$_.Id -notin $ExcludeEventId} | Where-Object {$_.TimeCreated -notin $Results.TimeCreated}
137 | if ($NewResults) {
138 | [array]$Results += [array]$NewResults
139 | [array]$Results | Export-Clixml -Path $Clixml
140 | }
141 | $NewResults = $NewResults | Select-Object TimeCreated,LevelDisplayName,LogName,Id, @{Name='Message';Expression={ ($_.Message -Split '\n')[0]}}
142 | #================================================
143 | # Display Results
144 | #================================================
145 | foreach ($Item in $NewResults) {
146 | if ($Item.LevelDisplayName -eq 'Error') {
147 | Write-Host "$($Item.TimeCreated) ERROR:$($Item.Id)`t$($Item.Message)" -ForegroundColor Red
148 | }
149 | elseif ($Item.LevelDisplayName -eq 'Warning') {
150 | Write-Host "$($Item.TimeCreated) WARN :$($Item.Id)`t$($Item.Message)" -ForegroundColor Yellow
151 | }
152 | elseif (($Item.Message -match 'fail') -or ($Item.Message -match 'empty profile')) {
153 | Write-Host "$($Item.TimeCreated) INFO :$($Item.Id)`t$($Item.Message)" -ForegroundColor Red
154 | }
155 | elseif ($Item.Message -like "Autopilot*") {
156 | Write-Host "$($Item.TimeCreated) INFO :$($Item.Id)`t$($Item.Message)" -ForegroundColor Cyan
157 | }
158 | elseif ($Item.Id -in $InfoWhite) {
159 | Write-Host "$($Item.TimeCreated) INFO :$($Item.Id)`t$($Item.Message)" -ForegroundColor White
160 | }
161 | elseif ($Item.Id -in $InfoCyan) {
162 | Write-Host "$($Item.TimeCreated) INFO :$($Item.Id)`t$($Item.Message)" -ForegroundColor Cyan
163 | }
164 | elseif ($Item.Id -in $InfoBlue) {
165 | Write-Host "$($Item.TimeCreated) INFO :$($Item.Id)`t$($Item.Message)" -ForegroundColor Blue
166 | }
167 | elseif ($Item.Id -in $InfoDarkBlue) {
168 | Write-Host "$($Item.TimeCreated) INFO :$($Item.Id)`t$($Item.Message)" -ForegroundColor DarkBlue
169 | }
170 | else {
171 | Write-Host "$($Item.TimeCreated) INFO :$($Item.Id)`t$($Item.Message)" -ForegroundColor DarkGray
172 | }
173 | }
174 | }
175 | }
176 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AutopilotOOBE
2 | https://autopilotoobe.osdeploy.com/
--------------------------------------------------------------------------------