Last active
February 25, 2021 15:39
-
-
Save tabs-not-spaces/5ab2525657c578ef4683bd3c9ba5f43c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$script:tick = [char]0x221a | |
$hashPath = "$env:SystemDrive\hwhash.csv" | |
function Install-PreReq { | |
[cmdletbinding()] | |
param ( | |
[Parameter(Mandatory = $true)] | |
[string[]]$reqs, | |
[Parameter(Mandatory = $false)] | |
[ValidateSet('Module', 'Script')] | |
$type = "Module" | |
) | |
foreach ($x in $reqs) { | |
Write-Host "Installing $type`: $x`.." -Foreground Blue -NoNewLine | |
if ($type -eq "Script") { | |
$exists = Get-Command -Name $x -errorAction SilentlyContinue | |
} | |
else { | |
$exists = Get-Module -Name $x -ListAvailable -errorAction SilentlyContinue | |
} | |
if (!($exists)) { | |
Invoke-Expression "Install-$type $x -Force -Confirm:`$false" | |
} | |
Write-Host " $script:tick" -Foreground Green | |
} | |
} | |
try { | |
Write-Host "Installing pre-reqs.." -Foreground Yellow | |
Find-PackageProvider -Name "Nuget" | Install-PackageProvider -Force -Confirm:$false | Out-Null | |
Install-PreReq -reqs "Get-WindowsAutoPilotInfo" -type "Script" | |
Install-PreReq -reqs "Microsoft.Graph.Intune", "WindowsAutoPilotIntune" -type "Module" | |
Write-Host "Grabbing device hash.." -Foreground Yellow -NoNewLine | |
if (!(Test-Path $hashPath)) { | |
$csv = Get-WindowsAutoPilotInfo | |
$csv | Export-Csv -Path $hashPath -NoTypeInformation -Force | |
} | |
if (Test-Path $hashPath) { | |
Write-Host " $script:tick" -Foreground Green | |
} | |
Write-Host "Authenticating to Azure tenant.." -Foreground Yellow -NoNewLine | |
$context = Connect-MSGraph | |
if ($context) { | |
Write-Host " $script:tick" -Foreground Green | |
Write-Host "Uploading hardware hash to tenant.." -ForegroundColor Yellow | |
Import-AutoPilotCSV -csvFile $hashPath | |
} | |
else { | |
Write-Host " X" -Foreground Red | |
throw "Authentication probably failed.." | |
} | |
} | |
catch { | |
$errorMsg = $_.Exception.Message | |
} | |
finally { | |
if ($errorMsg) { | |
Write-Warning $errorMsg | |
} | |
else { | |
Write-Host "Script completed with no obvious isssues.." -ForegroundColor Green | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment