#############################################################################################################
Description: Check if Windows Autopilot Device exists and import / update it based on Default or LOCATION code
Author: Thiago Beier thiago.beier@gmail.com @thiagobeier
Usage: registers Windows devices to autopilot - Intune - Default
Envirionment: DEV - CONTOSO
Version: 1.1 - parameter Capitalized Case sensitive based on latest .\get-windowsautopilotinfo.ps1 or get-windowsautopilotinfocommunity.ps1 v3.0.4 - Wipe fix
#############################################################################################################>
clear-host
#region Functions
# Functions
# Function to send notificaton to teams
function SendTeamsNotification {
#sending end-user toast notification
Write-Output 'sending end-user toast notification'
$payload = @{
"channel" = "#general"
"text" = "
Alert
| Current Device Name | Current LOCATION-ID code | Date & Time | SERIAL | New LOCATION-ID code |
|---|
| $env:COMPUTERNAME | $($tmp.grouptag) | $dt | $serial | $DefaultGroupTag |
"
}
#then we invoke web request using the uri which is the Teamswebhook url alongside the post method to send our request
Invoke-WebRequest -UseBasicParsing `
-Body (ConvertTo-Json -Compress -InputObject $payload) `
-Method Post `
-Uri ""
Write-Output "The condition was true"
}
#endregion
#region requirements
$LogFolder = 'C:\Logs'
#endregion
#region logfolder
#Test to see if folder [$LogFolder] exists"
if (Test-Path -Path $LogFolder) {
"Log folder exists!"
} else {
"Log folder doesn't exist."
New-Item -ItemType Directory -Path $LogFolder
}
#endregion
#Date and time
$dt = Get-Date -Format "dd-MM-yyyy-HH-mm-ss"
$logfile = "$LogFolder\autopilot-registration-$dt.log"
Start-Transcript -Path $logfile
# begin
# Gather Autopilot details
"Gathering Autopilot details"
$session = New-CimSession
$serial = (Get-CimInstance -CimSession $session -Class Win32_BIOS).SerialNumber
$devDetail = (Get-CimInstance -CimSession $session -Namespace root/cimv2/mdm/dmmap -Class MDM_DevDetail_Ext01 -Filter "InstanceID='Ext' AND ParentID='./DevDetail'")
$hash = $devDetail.DeviceHardwareData
"Installing Required PowerShell modules"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Add the .\get-windowsautopilotinfo.ps1 community version requirements to not fail running it straight from PowerShell Gallery
$getwindowsautopilotinfocommunity = Get-InstalledScript get-windowsautopilotinfocommunity
if ($getwindowsautopilotinfocommunity) {
"getwindowsautopilotinfocommunity found"
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.208 -Confirm:$false -Force:$true
} else {
#Install-Script -Name get-windowsautopilotinfocommunity -Confirm:$false -Force:$true
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.208 -Confirm:$false -Force:$true
}
# Registering Device in Windows autopilot devices
"Registering Device in Windows autopilot devices"
#$DefaultGroupTag = "AADJ" #this is for Azure AD domain join windows autopilot deployment profile
$DefaultGroupTag = "" #this is for Hybrid Azure AD domain join windows autopilot deployment profile (default)
# Sending Teams Notification to Teams Channel
"Sending Teams Notification to Teams Channel"
#SendTeamsNotification
"Wait until device restarts to proceed with Autopilot"
.\get-windowsautopilotinfo.ps1 -Online -TenantId -AppId -AppSecret -GroupTag $DefaultGroupTag -Assign -Reboot -Verbose
# end
Stop-Transcript