domain disjoin script
Posted: Mon Jan 24, 2011 7:43 pm
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.
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.