Powershell Removing PC from Domain using KACE
Hi there,
My client requested to remove 150 PCs from domain for training. I have created a powershell and worked on the PC, but I couldn't get it to work via KACE.
Here is my script
$credential = New-Object System.Management.Automation.PsCredential("domain\adminaccount", (ConvertTo-SecureString "password" -AsPlainText -Force))
Remove-computer -Credential $credential -Force -passthru -verbose;Restart-Computer
I found a post here that suggested to push the powershell as an application. I created a distribution
The command is
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nologo -executionpolicy bypass -noprofile -file "$(KACE_DEPENDENCY_DIR)\RemovefromDomain.ps1"
I have also tried like
powershell.exe -nologo -executionpolicy bypass -noprofile -file "RemovefromDomain.ps1"
The script download fine to KACE download folder on C drive but doesn't seem to run correctly. I am not sure where and how to check why is not running correctly.
Thanks in advance
My client requested to remove 150 PCs from domain for training. I have created a powershell and worked on the PC, but I couldn't get it to work via KACE.
Here is my script
$credential = New-Object System.Management.Automation.PsCredential("domain\adminaccount", (ConvertTo-SecureString "password" -AsPlainText -Force))
Remove-computer -Credential $credential -Force -passthru -verbose;Restart-Computer
I found a post here that suggested to push the powershell as an application. I created a distribution
The command is
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nologo -executionpolicy bypass -noprofile -file "$(KACE_DEPENDENCY_DIR)\RemovefromDomain.ps1"
I have also tried like
powershell.exe -nologo -executionpolicy bypass -noprofile -file "RemovefromDomain.ps1"
The script download fine to KACE download folder on C drive but doesn't seem to run correctly. I am not sure where and how to check why is not running correctly.
Thanks in advance
0 Comments
[ + ] Show comments
Answers (1)
Answer Summary:
Please log in to answer
Posted by:
SMal.tmcc
9 years ago
Top Answer
you can do this with wmic also
wmic.exe /interactive:off ComputerSystem Where "Name='%computername%'" Call UnJoinDomainOrWorkgroup FUnjoinOptions=0
wmic.exe /interactive:off ComputerSystem Where "Name='%computername%'" Call JoinDomainOrWorkgroup name="WORKGROUP"
Comments:
-
Thanks so much. I got this working using your command. I pushed it out as an application and added a reboot in the end and it worked. - yzhang 9 years ago