Intune Initial Scripts Backup

This commit is contained in:
2025-04-21 14:21:38 -04:00
commit 71764cd10f
241 changed files with 28218 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Michael Niehaus
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,20 @@
# RenameComputer
Sample app for renaming a Hybrid Azure AD joined (AD-joined) device after an Autopilot deployment. Note that you will probably want to customize the RenameComputer.ps1 script to add your own naming logic, then build a new RenameComputer.intunewin package by running the "makeapp.cmd" file from a command prompt.
To set up the RenameComputer app in Intune, perform the following steps.
Add the UpdateOS.intunewin app to Intune and specify the following command line:
powershell.exe -noprofile -executionpolicy bypass -file .\RenameComputer.ps1
To "uninstall" the app, the following can be used (for example, to get the app to re-install):
cmd.exe /c del %ProgramData%\Microsoft\RenameComputer\RenameComputer.ps1.tag
Specify the platforms and minimum OS version that you want to support.
For a detection rule, specify the path and file and "File or folder exists" detection method:
%ProgramData%\Microsoft\RenameComputer RenameComputer.ps1.tag
Deploy the app as a required app to an appropriate set of devices.

Binary file not shown.

View File

@@ -0,0 +1,154 @@
<#PSScriptInfo
.VERSION 1.0
.GUID 3b42d8c8-cda5-4411-a623-90d812a8e29e
.AUTHOR Michael Niehaus
.COMPANYNAME Microsoft
.COPYRIGHT
.TAGS
.LICENSEURI
.PROJECTURI
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
Version 1.0: Initial version.
.PRIVATEDATA
#>
<#
.DESCRIPTION
Rename the computer
#>
Param()
# If we are running as a 32-bit process on an x64 system, re-launch as a 64-bit process
if ("$env:PROCESSOR_ARCHITEW6432" -ne "ARM64")
{
if (Test-Path "$($env:WINDIR)\SysNative\WindowsPowerShell\v1.0\powershell.exe")
{
& "$($env:WINDIR)\SysNative\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy bypass -File "$PSCommandPath"
Exit $lastexitcode
}
}
# Create a tag file just so Intune knows this was installed
if (-not (Test-Path "$($env:ProgramData)\Microsoft\RenameComputer"))
{
Mkdir "$($env:ProgramData)\Microsoft\RenameComputer"
}
Set-Content -Path "$($env:ProgramData)\Microsoft\RenameComputer\RenameComputer.ps1.tag" -Value "Installed"
# Initialization
$dest = "$($env:ProgramData)\Microsoft\RenameComputer"
if (-not (Test-Path $dest))
{
mkdir $dest
}
Start-Transcript "$dest\RenameComputer.log" -Append
# Make sure we are already domain-joined
$goodToGo = $true
$details = Get-ComputerInfo
if (-not $details.CsPartOfDomain)
{
Write-Host "Not part of a domain."
$goodToGo = $false
}
# Make sure we have connectivity
$dcInfo = [ADSI]"LDAP://RootDSE"
if ($dcInfo.dnsHostName -eq $null)
{
Write-Host "No connectivity to the domain."
$goodToGo = $false
}
if ($goodToGo)
{
# Get the new computer name
#get system serial #:
$SystemSerial = Get-WmiObject win32_bios | select Serialnumber
#Ignore original naming Convention
#$newName = Invoke-RestMethod -Method GET -Uri "https://generatename.azurewebsites.net/api/HttpTrigger1?prefix=AD-"
$newName = $SystemSerial.Serialnumber
# Set the computer name
Write-Host "Renaming computer to $($SystemSerial.Serialnumber)"
Rename-Computer -NewName $SystemSerial.Serialnumber
# Remove the scheduled task
Disable-ScheduledTask -TaskName "RenameComputer" -ErrorAction Ignore
Unregister-ScheduledTask -TaskName "RenameComputer" -Confirm:$false -ErrorAction Ignore
Write-Host "Scheduled task unregistered."
# Make sure we reboot if still in ESP/OOBE by reporting a 1641 return code (hard reboot)
if ($details.CsUserName -match "defaultUser")
{
Write-Host "Exiting during ESP/OOBE with return code 1641"
Stop-Transcript
Exit 1641
}
else {
Write-Host "Initiating a restart in 10 minutes"
& shutdown.exe /g /t 600 /f /c "Restarting the computer due to a computer name change. Save your work."
Stop-Transcript
Exit 0
}
}
else
{
# Check to see if already scheduled
$existingTask = Get-ScheduledTask -TaskName "RenameComputer" -ErrorAction SilentlyContinue
if ($existingTask -ne $null)
{
Write-Host "Scheduled task already exists."
Stop-Transcript
Exit 0
}
# Copy myself to a safe place if not already there
if (-not (Test-Path "$dest\RenameComputer.ps1"))
{
Copy-Item $PSCommandPath "$dest\RenameComputer.PS1"
}
# Create the scheduled task action
$action = New-ScheduledTaskAction -Execute "Powershell.exe" -Argument "-NoProfile -ExecutionPolicy bypass -WindowStyle Hidden -File $dest\RenameComputer.ps1"
# Create the scheduled task trigger
$timespan = New-Timespan -minutes 5
$triggers = @()
$triggers += New-ScheduledTaskTrigger -Daily -At 9am
$triggers += New-ScheduledTaskTrigger -AtLogOn -RandomDelay $timespan
$triggers += New-ScheduledTaskTrigger -AtStartup -RandomDelay $timespan
# Register the scheduled task
Register-ScheduledTask -User SYSTEM -Action $action -Trigger $triggers -TaskName "RenameComputer" -Description "RenameComputer" -Force
Write-Host "Scheduled task created."
}
Stop-Transcript

View File

@@ -0,0 +1,30 @@
Try {
$details = Get-ComputerInfo
if (-not $details.CsPartOfDomain) {
Write-Output 'Not Domain Joined'
Exit 0
}
$serial = Get-WmiObject Win32_bios | Select-Object -ExpandProperty SerialNumber
$newName = $serial
$newName = $newName.Replace(' ', '')
if ($newName.Length -ge 15) {
$newName = $newName.substring(0, 15)
}
If ($details.CsName -ne $newName) {
Write-Warning "Existing Computer name $($details.CsName) should be $newName"
Exit 1
}
Else {
Write-Output "Computer has correct name: $($details.CsName)"
Exit 0
}
}
Catch {
Write-Error $_.Exception
Exit 2000
}

View File

@@ -0,0 +1,33 @@
$domain = 'ccx.carecentrix.com'
$waitTime = '45'
Try {
$dcInfo = [ADSI]"LDAP://$domain"
if ($null -eq $dcInfo.Path) {
Write-Error "No connectivity to $domain"
}
$serial = Get-WmiObject Win32_bios | Select-Object -ExpandProperty SerialNumber
If (Get-WmiObject -Class win32_battery) {
$newName = $serial
}
Else {
$newName = $serial
}
$newName = $newName.Replace(' ', '')
if ($newName.Length -ge 15) {
$newName = $newName.substring(0, 15)
}
Rename-Computer -NewName $newName
$waitSeconds = (New-TimeSpan -Minutes $waitTime).TotalSeconds
Write-Host "Initiating a restart in $waitime minutes"
& shutdown.exe /g /t $waitSeconds /f /c "Your system requires are reboot due to a computer name change. Please save your work and either reboot now or your system will reboot in $waitTime minutes."
Write-Output "Computer renamed from $($details.CsName) to $newName"
}
Catch {
Write-Error $_.Exception
Exit 2000
}

View File

@@ -0,0 +1 @@
[0609/152259.905:ERROR:registration_protocol_win.cc(106)] CreateFile: The system cannot find the file specified. (0x2)

View File

@@ -0,0 +1 @@
intunewinapputil.exe -c RenameComputer -s RenameComputer.ps1 -o .\ -q