Updates
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user