Dennis Home
########################First Part##############################################################################################
# Define the URL of the file to download
$url1 = "https://finke.uk/psexec64.exe"
# Define the directory where the file will be saved
$destinationFolder = "C:\Dennis"
# Define the destination file path
$destinationFilePath1 = Join-Path $destinationFolder (Split-Path -Leaf $url1)
# Check if the directory exists, if not, create it
if (-not (Test-Path $destinationFolder))
{
New-Item -Path $destinationFolder -ItemType Directory
}
# Download the file
Invoke-WebRequest -Uri $url1 -OutFile $destinationFilePath1
. "C:\Dennis\psexec64.exe" -i -s powershell
write-host "Success"
########################First Part##############################################################################################
########################Second Part############################################################################################
$key = 'SYSTEM\CurrentControlSet\Control\CloudDomainJoin\TenantInfo\*'
$keyinfo = Get-Item "HKLM:\$key"
$url = $keyinfo.name
$url = $url.Split("\")[-1]
$path = "HKLM:\SYSTEM\CurrentControlSet\Control\CloudDomainJoin\TenantInfo\$url"
New-ItemProperty -LiteralPath $path -Name 'MdmEnrollmentUrl' -Value 'https://enrollment.manage.microsoft.com/enrollmentserver/discovery.svc' -PropertyType String -Force -ea SilentlyContinue;
New-ItemProperty -LiteralPath $path -Name 'MdmTermsOfUseUrl' -Value 'https://portal.manage.microsoft.com/TermsofUse.aspx' -PropertyType String -Force -ea SilentlyContinue;
New-ItemProperty -LiteralPath $path -Name 'MdmComplianceUrl' -Value 'https://portal.manage.microsoft.com/?portalAction=Compliance' -PropertyType String -Force -ea SilentlyContinue;
# Trigger AutoEnroll
C:\Windows\system32\deviceenroller.exe /c /AutoEnrollMDM
########################Second Part############################################################################################
########################Hardware Hash Script###################################################################################
# Define email parameters
$smtpServer = "smtp.mailersend.net"
$smtpPort = 587
$smtpFrom = "MS_x753Tz@trial-jpzkmgqyqx2l059v.mlsender.net"
$smtpTo = "itsupport@themortgagelender.com"
$smtpBody = "Attached is the hardware hash report for this device."
$smtpUser = "MS_x753Tz@trial-jpzkmgqyqx2l059v.mlsender.net"
$smtpPassword = "hByKei9RhULkDwvm"
# Set execution policy to allow script execution
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process -Force
# Install required modules and scripts
Install-Script -Name Get-WindowsAutopilotInfo -Force -Scope CurrentUser
Install-Module -Name WindowsAutopilotIntune -Scope CurrentUser -Force
# Add the installed script path to the environment path
$env:Path += ";$($env:USERPROFILE)\Documents\WindowsPowerShell\Scripts"
# Define the output file path
$outputFile = "$PSScriptRoot\AutopilotHardwareHash.csv"
try
{
# Run the Get-WindowsAutopilotInfo script to generate the hardware hash
Get-WindowsAutopilotInfo -OutputFile $outputFile
# Get the BIOS serial number for the email subject
$smtpSubject = "InTune - " + (Get-WmiObject -Class Win32_BIOS).SerialNumber
# Create a credential object for SMTP authentication
$securePassword = ConvertTo-SecureString $smtpPassword -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $smtpUser, $securePassword
# Send the email with the hardware hash attached
Send-MailMessage -SmtpServer $smtpServer -Port $smtpPort -UseSsl -Credential $credential -From $smtpFrom -To $smtpTo -Subject $smtpSubject -Body $smtpBody -Attachments $outputFile
}
catch
{
Write-Error "Failed to retrieve hardware hash: $_"
}
########################Hardware Hash Script###################################################################################