I have managed to sort this here's my code if anyone needs it. This works on remote machines as long as the access rights are correct.
Imports System
Imports Microsoft.Win32
Imports System.Management
Imports System.Management.Instrumentation
Try
Dim ComputerName as string = ""
Dim ConnectionOpt As New ConnectionOptions()
ConnectionOpt.Authentication = AuthenticationLevel.PacketPrivacy
Console.WriteLine("Connecting to " & ComputerName & " WMI Namespace")
Dim scope As New ManagementScope("\\" & ComputerName & _
"\root\cimv2", ConnectionOpt)
scope.Connect()
Console.WriteLine("Connection Succeeded")
Dim classInstance As New ManagementObject(scope, _
New ManagementPath("Win32_ComputerSystem.Name='" _
& ComputerName & "'"), Nothing)
Dim inParams As ManagementBaseObject = _
classInstance.GetMethodParameters("unjoindomainorworkgroup")
Console.WriteLine("Removing " & ComputerName & _
" from Domain and adding to Workgroup")
inParams("FunjoinOptions") = 1
inParams("Password") = "xxxxxxxx"
inParams("UserName") = "xxxxxxxx"
Dim outParams As UInt32 = _
classInstance.InvokeMethod("unjoindomainorworkgroup", Nothing)
Console.WriteLine("Removal Succeeded.")
Catch err As ManagementException
Console.WriteLine("Removal Failed!")
Console.WriteLine("Error: " & err.Message)
End Try
Try
Console.WriteLine("Connecting to " & ComputerName & " WMI Namespace")
Dim ConnectionOpt As New ConnectionOptions()
ConnectionOpt.Authentication = AuthenticationLevel.PacketPrivacy
Dim scope As New ManagementScope("\\" & ComputerName & _
"\root\cimv2", ConnectionOpt)
scope.Connect()
Console.WriteLine("Connection Succeeded")
Console.WriteLine("Renaming " & ComputerName & " to " _
& NewComputerName ")
Dim classInstance As New ManagementObject _
(scope, New ManagementPath("Win32_ComputerSystem.Name=
ComputerName & "'"), Nothing)
Dim inParams As ManagementBaseObject = _
classInstance.GetMethodParameters("Rename")
inParams("Name") = "NewComputerName"
inParams("Password") = "xxxxxxxx"
inParams("UserName") = "xxxxxxxx"
Dim outParams As ManagementBaseObject = _
classInstance.InvokeMethod("Rename", inParams, Nothing)
Console.WriteLine("Rename Successful")
Catch err As ManagementException
Console.WriteLine("Rename Failed!")
Console.WriteLine("Error: " & err.Message)
End Try
Console.WriteLine("")
Console.WriteLine("Workstation Must Be Restarted!")