Sunday, March 02, 2014

PowerShell + SCCM 2012 R2 : Adding Roles & Client Settings (Device & User)

Post #3 in the PowerShell with ConfigMgr 2012 series.

Trying to do the things mentioned in this post --> @Windows-Noob

Before I begin, I had an interesting discovery.
While trying out the Cmdlets in the ConfigurationManager Module, I had been facing a lot of issues....like in the Discovery Post few weeks ago was not able to use the -ActiveDirectoryContainer parameter. So had to resolve to WMI way.

When I was trying out things mentioned in this post with PowerShell I faced a lot of Errors and asked around, finally was able to get a workaround.

I have ConfigMgr 12 R2 Preview installed on the server and the Eval version is out. So I downloaded the ConfigMgr 12 R2 Eval version and just did a re-install of the ConfigMgr Admin Console on one of my machines.

Now the downside of this is the GUI won't connect to the Site Server because of the version mismatch but the PowerShell module works fine (this is what I was after). I still have old ConfigMgr Admin Console installed on the Site Server so it's just a workaround until I build my Lab again.

Step 1. Add the Application Catalog Web Service Point [LogFile : awebsvcMSI.log and Application Catalog Website Point Roles [LogFile : awebsctl.log]


Well I found out that the ConfigurationModule has two cmdlets Add-CMApplicationCatalogWebServicePoint and Add-CMApplicationCatalogWebsitePoint exactly for this task. So the code is below :


Step 2 : Configure Custom Client Device Settings


Now as per the Windows-Noob guide we will be adding the Custom Device Client setting and customizing the  Client Policy, Computer Agent and Software Updates. There are already cmdlets by the name New-CMClientSetting which can create Custom (Device/User) Client setting. Once this is done we can customize the settings using the Set-CMClientSetting cmdlet.

If you browse to the online help page for the Set-CMClientSetting page then you will notice that it applies to SCCM 2012 R2 and that to customize each setting we have a parameter set for the cmdlet, this will be evident from below screenshot:



Now walkthrough the Code :

#First create the New Client settings 

New-CMClientSetting -Name "Custom Client Device Settings" -Type Device -Description "Custom Client settings: following Windows-Noob --> DexterPOSH"

The above expression will create a new Device Client Settings:



Now start configuring various settings under these new Device Client Settings:

#Now start configuring the Client Policy, Computer Agent (skippingSoftware Updates setting for now)
Set-CMClientSetting -Name "Custom Client Device Settings" -PolicyPollingInterval 5  -EnableUserPolicyPolling $true -EnableUserPolicyOnInternet $false


# 2. Configure the Computer Agent
Set-CMClientSetting -Name "Custom Client Device Settings" -PowerShellExecutionPolicy Bypass -InitialReminderHoursInterval 48 -InterimReminderHoursInterval 4 -FinalReminderMinutesInterval 15  -PortalUrl "http://dexsccm.dexter.com/CMApplicationCatalog/" -AddPortalToTrustedSiteList $true -AllowPortalToHaveElevatedTrust $true -BrandingTitle "Dexter's LAB" -InstallRestriction AllUsers -DisplayNewProgramNotification $true


Now once you run above cmdlet then you can see the changes reflecting in the console too:



Now you can go an verify individual settings you configured..in below screenshot is the Client Policy settings:




Skipping the Software Updates settings for now, not yet configured it in my Lab.


Step 3 : Deploy our Custom Device Client Settings


To deploy our Client settings we would be using : Start-CMClientSettingDeployment cmdlet.
Read the help of this and you will come to know that you need to supply the client settings specify by Name, Id or Object which you want to deploy to a Collection (specify Name, Id or Object)

Notice that before this the deployment tab for the settings is empty:


Now run the below cmdlet and see wonders happen:
Start-CMClientSettingDeployment -ClientSettingName "Custom Client Device Settings" -CollectionName "All Systems"


See the changes reflect in the ConfigMgr console (hit refresh a couple of times)




Step 4 : Configure Custom Client User Settings (WMI Way)



I wanted to do this using WMI/CIM just for fun.....as I want to know what's happening in which class. So I started playing around figuring things.

First we need to get the class we want to work with it's SMS_ClientSettings WMI Class. Now we have to create a instance of it and pass to it require properties while doing so...for creating Client User Settings we have to pass the Type = 2.


#create the new instance of the Class pass to it relevant properties like Name, Type , Priority, Description
$ClientUserSetting = New-CimInstance -ClassName SMS_ClientSettings -Property @{Name="Custom Client User Settings";Type=2;Priority=2;Description="Custom Client User Settings -- WMI Way"} -Namespace root/sms/site_DEX -ComputerName DexSCCM -verbose


#Now we need to add the User Device Affinity to the class we created as one of the AgentConfgurations

$ClientUserSetting.AgentConfigurations += New-CimInstance -ClassName SMS_TargetingAgentConfig -Property @{AgentID=10;AllowUserAffinity=1} -Namespace root/sms/Site_DEX -ComputerName DexSCCM -Verbose

#Now once done set back the property to the ConfigMgr Server 

Set-CimInstance -InputObject $ClientUserSetting 
#deploy the above settings to the Collection
Start-CMClientSettingDeployment -ClientSettingName "Custom Client User Settings" -CollectionName "All Systems"


I tried using Set-CMClientSetting cmdlet to set the above User Device Affinity Settings but it behaved rather oddly...So I went for the WMI way as now I know by sure that the Cmdlets shipped with Configuration Manager may have bugs but the WMI way is the one which will bail you out at the end.

Finally, Have created a Gist for all the cmdlets used above.
That's it for today's post.

2 comments:

  1. This is excellent, I dont suppose you have a backwards script to this that will extract what the clients settings are currently configured as?

    ReplyDelete
  2. Fetching the client settings should be easy...Use Get-CMClientSetting cmdlet or just use Get-CIMInstance with the appropriate class names to get the existing ones.

    ReplyDelete