├── .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 | 207 | 208 | 209 | 216 | 217 | 218 | 225 | 226 | 227 | 228 | 248 | 249 | 250 | 271 | 272 | 273 | 291 | 292 | 293 | 312 | 313 | 314 | 334 | 335 | 336 | Assign: Wait for Intune to assign an Autopilot profile for this device 343 | 344 | 345 | 346 | 347 |