Hi,
I am trying to write a script which disjoin a server from a domain. I have got a piece of code from WMIcodecreater for this one. It works fine if i use the server name in the script.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & strComputer & "rootCIMV2")
' Obtain an instance of the the class
' using a key property value.
Set objShare = objWMIService.Get("Win32_ComputerSystem.Name='W*****19'")
' Obtain an InParameters object specific
' to the method.
Set objInParam = objShare.Methods_("UnjoinDomainOrWorkgroup"). _
inParameters.SpawnInstance_()
' Add the input parameters.
objInParam.Properties_.Item("FUnjoinOptions") = 0
' Execute the method and obtain the return status.
' The OutParameters object in objOutParams
' is created by the provider.
Set objOutParams = objWMIService.ExecMethod("Win32_ComputerSystem.Name='W*****19'", "UnjoinDomainOrWorkgroup", objInParam)
' List OutParams
Wscript.Echo "Out Parameters: "
Wscript.echo "ReturnValue: " & objOutParams.ReturnValue
Instead of hardcoding the server name in the script, how do i make it to work on any other server like..
Set objShare = objWMIService.Get("Win32_ComputerSystem.Name='" & strComputer & "'"), but it gives an error SWbemServiceEx: Not found.
Please suggest.
domain disjoin script
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
domain disjoin script
Just change the name of teh server before connecting to teh service.
Don't know where you got the code but it looks to be a mix of mismatched parts. Just query teh computer for teh object and execute the method on the object.
The computer will not be removed from the domain until it is rebooted.
jvierra2011-01-25 07:57:24
Code: Select all
strComputer = "server2"
Set wmi = GetObject("winmgmts:" & strComputer & "rootCIMV2")
Set coll = wmi.ExecQuery("select * from Win32_ComputerSystem")
For Each c In coll
c.UnjoinDomainOrWorkgroup "mypassword", "myaadminaccout", 0
Next
The computer will not be removed from the domain until it is rebooted.
jvierra2011-01-25 07:57:24
domain disjoin script
By th eway -
This is all of the code you need in powershell.
This is all of the code you need in powershell.
Code: Select all
$computer='somepc'
[wmi]"
$computerrootcimv2:win32_computersystem.Name=`'$computer`'").UnjoinDomainOrWorkgroup()
- superfly12
- Posts: 133
- Last visit: Sun Nov 02, 2014 4:37 pm
domain disjoin script
Thanks for you time to reply.There is data center movement scheduled and the servers should be renamed to reflect the location and i think they will be doing in bunches.You have mentioned that "YOu do not have to rejoin if you use the rename correctly.", does it mean that i don't have to disjoin and rejoin to reflect the new name ? I was thinking that i have to disjoin it first, then rename and reboot it and then join the domain. Please correct me if im wrong.
- charlinparker
- Posts: 1
- Last visit: Sun Jun 17, 2012 5:19 pm
domain disjoin script
I had gone through the post, We need to disjoin more than 20 computers from a domain, is there anyway we can do this by a script easily? It is a Server 2000 Domain they are on, 99% of them are Windows XP Pc's and rest are Windows 2000 PC's.
Please produce some more attachments about the topic for view detail information.domein
professionele web hosting
Please produce some more attachments about the topic for view detail information.domein
professionele web hosting