Special thanks to Mark Kent on the SMSlist that found the bug in the script and special thanks to Trevor Sullivan for creating the code fix so fast.
The script wasn’t checking the right service, there was a typo on the service. I had CCMSetup instead of CCMExec.
That has been fixed. It also didn’t have a solution for when the service was disabled. That has now bin fixed.
Here is the updated code. The whole script is attached.
Add this at the end (doesn't matter where it goes, because it's a function definition):
' ******************************************************
' * EnableService Function *
' ******************************************************
Function EnableService(svcName)
If svcName <> "" Then
logfile.writeline "Changing start mode for service (" & svcName & ") to automatic"
set ccmsvc = GetObject("winmgmts:root\cimv2:Win32_Service.Name='" & svcName & "'")
logfile.writeline "Current start mode for service (" & svcName & ") is: " & ccmsvc.StartMode
result = ccmsvc.ChangeStartMode("automatic")
logfile.writeline "Changing start mode for service (" & svcName & ") resulted in: " & result
End If
End Function
And then modify this section (add line 212):
209 Elseif LCase(Results) = LCase("Stopped")Then
210 logfile.WriteLine "ccmsetup service Is In a stopped state, enabling and starting service"
211 wShShell1.LogEvent 1, "ccmsetup service Is In a stopped state, enabling and starting service"212 call EnableService("ccmexec") ' Add this line!
213 KickService("ccmsetup") ' Chris, shouldn't this be ccmexec, not ccmsetup?
Ok so I'm in the middle of migrating a large side by side site to SCCM. I have a problem, a firewall is blocking the remote execution of the right click tools for change site code. This method uses a VB script an a WMI connection. but something is blocking it from running. So I figure I will out smart it and use a VB script to move the clients.
Well that would be great but again I have a problem with MacAfee, Proventia, or maybe even a GPO is blocking the remote execution of the vbscript. I included the Vbscript I use incase you wanted it.
So I ask the list if there is any other way of doing this. does anybody have an EXE that can do the job without using vbscript.
Trevor Sullivan jumped right on it and writes this quick little app that does exactly what I needed using C#.
Just advertise this to the machines that are giving you a hard time.
Remember that when you advertise a site code change you should only receive a status of running in your advertisement report. If you receive anything else the client wasn't moved. This is because the client, once moved, no longer sees the old site so you never receive a successful status. Just give it a little time and it should show up in the new console.
Attached to this blog is everything you need.
*********************************************
Just run:
AssignSiteCode.exe 123
Here is the code behind the EXE.
using System;
using System.Management;
namespace AssignConfigMgrClient
{
class Program
{
static void Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine("Invalid syntax");
Environment.Exit(10);
}
if (args[0].Length != 3)
{
Console.WriteLine("Invalid site code. Please use 3 digits");
Environment.Exit(20);
}
string[] clientargs = new string[1];
clientargs[0] = args[0];
ManagementClass mo = new ManagementClass(new ManagementPath(@"root\ccm:sms_client"));
mo.InvokeMethod("SetAssignedSite", clientargs);
}
}
}