unjoin domain & uninstall configmgr client in task sequence

Hi there,

because of several reasons i tried to setup a task sequence for our windows 7 OSD to

1. unjoin the domain (=join workgroup) with a powershell-script and

2. uninstall configmgr client.



so here is my script for unjoining the domain:

$WID=[System.Security.Principal.WindowsIdentity]::GetCurrent();
$WIP=new-object System.Security.Principal.WindowsPrincipal($WID);
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator;
If ($WIP.IsInRole($adminRole)){
}else {
  $newProcess = new-object System.Diagnostics.ProcessStartInfo 'PowerShell';
  $newProcess.Arguments = $myInvocation.MyCommand.Definition
  $newProcess.Verb = 'runas'
  [System.Diagnostics.Process]::Start($newProcess);Write-Host 'Prompting for Elevation'
  exit
}
#####################
# Add Scripts Below #
#####################
$Workgroup = "private" #IF you want to add computer to domain edit here(Domain name)
$Password = "******" | ConvertTo-SecureString -asPlainText -Force
$Username = "$domain\username"
$Credential = New-Object System.Management.Automation.PSCredential($Username,$Password)
Add-Computer -WorkGroup $Workgroup -Credential $credential -Force

the script does work when executed manually but does not work in task sequence.

also i am not quite sure in which order both steps should be executed and if this is really possible!

does anyone have experience with unjoining the domain in the task sequence?



August 22nd, 2015 5:15am

Use psexec.exe to execute that script in system context and see if it still working. Also keep in mind that you won't see a popup when using a TS. 
Free Windows Admin Tool Kit Click here and download it now
August 22nd, 2015 5:52am

yes executing the script did not work through psexec...
August 22nd, 2015 8:44am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics