Since the release of ConfigMgr 1610 we’ve had the possibility to manage roaming clients through what’s called the Cloud Management Gateway. Nowadays clients are not only connected from the inside of the corporate network, but they are being connected from anywhere in the world where there’s internet connectivity. Previously we could manage such clients through what’s called Internet Based Client Management (IBCM) that would require additional on-premise infrastructure and expose those resources on the internet. With the Cloud Management Gateway we can simply leverage the power of the cloud that does not require any internet exposed infrastructure. With the Cloud Management Gateway, there are some really nice benefits that we’ve just discussed. Another advantage of the Cloud Management Gateway is that it’s running on Azure virtual machines. This in fact means that you don’t need to maintain the infrastructure, you simply leave that up to Microsoft. However, there are  some disadvantages that you should be aware of as well. For instance if you’re an IT Pro and would like to explore the possibilities the Cloud Management Gateway can bring to your environment in terms of managing roaming clients, and would like to test it out in a lab environment before you set it up in a production environment, you should pay attention to the cost of running a single or multiple instances of Azure virtual machines.

This post will not touch on the subject of installing or configuring a Cloud Management Gateway, there are a lot of great posts out there talking about this already.

Why and how would I automate the state

Every Cloud Management Gateway that you add in ConfigMgr can be stopped and started quite easily with PowerShell, either through the SMS Provider by invoking the available methods or by using cmdlets from the Configuration Manager module. For your convenience, I’ve written a PowerShell script intended to easily start or stop the Cloud Management Gateway service (in order words, save you a few bucks). For those of you thinking, why not simply just click the Stop or Start button in the ConfigMgr console? Absolutely, that’s an option that you have. But if you’re like me and have tons of other things going on at the same time, it could be a good idea to schedule the operational times that your Cloud Management Gateway is running in your lab environment being available to your clients.

The script in this post are using the Configuration Manager PowerShell module cmdlets available, however you can also accomplish the same automation using the SMS Provider directly. If you look at the SMS_AzureService class, there’s two interesting static methods available:

  • Start
  • Stop

This class was introduced with the Cloud Distribution Point functionality, but now also houses instances for Cloud Management Gateway. For more information regarding this class, see the documentation:

https://docs.microsoft.com/en-us/sccm/develop/reference/core/servers/configure/sms_azureservice-server-wmi-class

Download the script

Like many of our scripts, we’ve uploaded it to our GitHub repository available on the following link:

https://github.com/SCConfigMgr/ConfigMgr/blob/master/Site%20Administration/Set-CMCloudManagementGatewayState.ps1

The script available above has been designed to be able to be scheduled through e.g. Task Scheduler in your lab environment, but of course it’s also possible to invoke it manually. There are also some built in checks that prevents you from initiating a start or stop action if the Cloud Management Gateway resource is in a specific state where it’s for instance currently stopping or starting.

Starting a Cloud Management Gateway

When you want to get your Cloud Management Gateway resources up and running from a stopped state, use the following command line:

# Start a single Cloud Management Gateway resource
.\Set-CMCloudMAnagementGatewayState.ps1 -CloudServiceName "ContosoCMG01.cloudapp.net" -ServiceState Start -Verbose

# Start multiple Cloud Management Gateway resources
.\Set-CMCloudMAnagementGatewayState.ps1 -CloudServiceName "ContosoCMG01.cloudapp.net", "ContosoCMG02.cloudapp.net" -ServiceState Start -Verbose

Below is a sample output from the script when it has instructed a single Cloud Management Gateway resource to start:

And in the picture below you can see the start action being shown in the ConfigMgr console:

Stopping a Cloud Management Gateway

We’ve seen how a Cloud Management Gateway can be started with the script included in this post, but we can also stop it by using the following command line:

# Stop a single Cloud Management Gateway resource
.\Set-CMCloudMAnagementGatewayState.ps1 -CloudServiceName "ContosoCMG01.cloudapp.net" -ServiceState Stop -Verbose

# Stop multiple Cloud Management Gateway resources
.\Set-CMCloudMAnagementGatewayState.ps1 -CloudServiceName "ContosoCMG01.cloudapp.net", "ContosoCMG02.cloudapp.net" -ServiceState Stop -Verbose

Below is a sample output from the script when it has instructed a single Cloud Management Gateway resource to stop:

Just like for the starting part, below is a picture of what it looks like from the ConfigMgr console when the stop action has been invoked:

With this script, we can now save a few bucks in our lab environment but also any production environment where there’s no requirement for a Cloud Management Gateway resource to be online and available to clients on a 24/7 basis.

 

 

(1084)

Nickolaj Andersen

Principal Consultant and Enterprise Mobility MVP since 2016. Nickolaj has been in the IT industry for the past 10 years specializing in Enterprise Mobility and Security, Windows devices and deployments including automation. Currently working for TrueSec as a Principal Consultant. Awarded as PowerShell Hero in 2015 by the community for his script and tools contributions. Creator of ConfigMgr Prerequisites Tool, ConfigMgr OSD FrontEnd, ConfigMgr WebService to name a few. Frequent speaker at conferences and user groups.

There are no comments.

Leave a Reply