36 lines
740 B
PowerShell
36 lines
740 B
PowerShell
function Join-HJLaw
|
|
{
|
|
param(
|
|
[string]$DeviceName
|
|
)
|
|
|
|
if (-not $DeviceName -eq "")
|
|
{
|
|
Rename-Computer -NewName $DeviceName
|
|
}
|
|
$ppkg = $false
|
|
Get-ProvisioningPackage -AllInstalledPackages | ForEach-Object {
|
|
if($_.PackagePath -like "*HJLaw*")
|
|
{
|
|
if ($_.IsInstalled)
|
|
{
|
|
$ppkg = $true
|
|
}
|
|
}
|
|
}
|
|
if (-not $ppkg)
|
|
{
|
|
$registryPath = "HKLM:\SOFTWARE\Microsoft\Enrollments"
|
|
$subKeys = Get-ChildItem -Path $registryPath
|
|
foreach ($subKey in $subKeys)
|
|
{
|
|
Remove-Item -Path "$registryPath\$($subKey.PSChildName)" -Recurse -Force
|
|
}
|
|
dsregcmd /leave
|
|
Uninstall-ProvisioningPackage -AllInstalledPackages
|
|
|
|
Install-ProvisioningPackage -PackagePath '.\HJLaw.ppkg' -QuietInstall -Force
|
|
dsregcmd /status
|
|
}
|
|
}
|