Advertisement
Guest User

enroll.cmd

a guest
Apr 11th, 2025
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | Software | 0 0
  1. @REM This script is tenant specific!
  2. @powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$_=((Get-Content \"%~f0\") -join \"`n\");iex $_.Substring($_.IndexOf(\"goto :\"+\"EOF\")+9)"
  3. @goto :EOF
  4.  
  5. #Provisioned App Removal List and afterwards loop through the remaining... This list is specific to a default Windows 11 install.
  6. $DefaultRemove = @(
  7. "Microsoft.549981C3F5F10"
  8. "Microsoft.BingNews"
  9. "Microsoft.BingWeather"
  10. "Microsoft.GamingApp"
  11. "Microsoft.GetHelp"
  12. "Microsoft.Getstarted"
  13. "Microsoft.MicrosoftOfficeHub"
  14. "Microsoft.MicrosoftSolitaireCollection"
  15. "Microsoft.MicrosoftStickyNotes"
  16. "Microsoft.People"
  17. "Microsoft.Todos"
  18. "Microsoft.WindowsAlarms"
  19. "microsoft.windowscommunicationsapps"
  20. "Microsoft.WindowsFeedbackHub"
  21. "Microsoft.WindowsMaps"
  22. "Microsoft.Xbox.TCUI"
  23. "Microsoft.XboxGameOverlay"
  24. "Microsoft.XboxGamingOverlay"
  25. "Microsoft.XboxIdentityProvider"
  26. "Microsoft.XboxSpeechToTextOverlay"
  27. "Microsoft.YourPhone"
  28. "Microsoft.ZuneMusic"
  29. "Microsoft.ZuneVideo"
  30. )
  31.  
  32. Write-Host "Removing Microsoft Provisioned Bloat"
  33. ForEach ($toremove in $DefaultRemove) {
  34. Get-ProvisionedAppxPackage -Online -ErrorAction SilentlyContinue | Where-Object DisplayName -EQ $toremove | Remove-ProvisionedAppxPackage -Online -AllUsers | Out-Null
  35. Write-Host "." -NoNewline -ForegroundColor 'Yellow'
  36. }
  37.  
  38. # Clean up user interface
  39. # Registry modifications with error handling
  40. try {
  41. Write-Host "Modifying default user registry settings"
  42. REG LOAD HKLM\Default C:\Users\Default\NTUSER.DAT
  43.  
  44. $RegistryPath = "HKLM:\Default\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
  45. @{
  46. "ShowTaskViewButton" = 0
  47. "TaskbarDa" = 0
  48. "TaskbarMn" = 0
  49. }.GetEnumerator() | ForEach-Object {
  50. New-ItemProperty -Path $RegistryPath -Name $_.Key -Value $_.Value -PropertyType Dword -Force
  51. }
  52.  
  53. REG UNLOAD HKLM\Default
  54. }
  55. catch {
  56. Write-Host "Error modifying registry: $($_.Exception.Message)"
  57. }
  58.  
  59. Set-Culture en-NZ
  60. Set-WinSystemLocale -SystemLocale en-NZ
  61. Set-TimeZone -Name 'New Zealand Standard Time'
  62. Set-WinHomeLocation -GeoId 0xb7
  63. Set-WinUserLanguageList en-NZ -Force -Confirm:$false
  64.  
  65. # Add PC to Autopilot
  66. $TryAgain = $true
  67. If (!(tnc).PingSucceeded) {
  68. Write-Warning "No network available!"
  69. Write-Host "Please connect an ethernet cable or connect to Wi-Fi and then press any key when connected"
  70. start ms-availablenetworks:
  71. $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | OUT-NULL
  72. $HOST.UI.RawUI.Flushinputbuffer()
  73. $TryAgain = (tnc).PingSucceeded
  74. }
  75. If (!($TryAgain)) {
  76. Write-Warning "Unable to access the network - we're quitting"
  77. } else {
  78. Try {
  79. Install-PackageProvider -Name NuGet -Force -Confirm:$false
  80. Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
  81. Install-Script -name Get-WindowsAutopilotInfo -Force -Confirm:$false
  82. Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned
  83.  
  84. $AutopilotParams = @{
  85. Online = $true
  86. TenantId = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeee' # TenantId
  87. AppId = 'aaaaaaa-bbbb-cccc-dddd-eeeeeeee' # AppId
  88. AppSecret = 'MyReallyStrongAppSecret' # AppSecret
  89. GroupTag = "Autopilot"
  90. Assign = $true
  91. }
  92.  
  93. Write-Host "Registering device with Windows Autopilot..."
  94. $autopilotResult = Get-WindowsAutopilotInfo @AutopilotParams
  95.  
  96. if ($autopilotResult) {
  97. Write-Host "Device successfully registered with Autopilot" -ForegroundColor Green
  98. Restart-Computer -Force -Confirm:$false
  99. } else {
  100. Write-Host "Failed to register device with Autopilot" -ForegroundColor Red
  101. Write-Host "Please contact IT Support" -ForegroundColor Red
  102. }
  103. } Catch {
  104. Clear
  105. Write-Host "An error has occurred:" -ForegroundColor Red
  106. Write-Host "$($_.Exception.Message)"
  107. Write-Host "Please contact IT Support" -ForegroundColor Red
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement