diff --git a/.vscode/settings.json b/.vscode/settings.json index e4607a3f..daca553c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -11,5 +11,11 @@ "powershell.codeFormatting.preset": "Custom", "files.trimTrailingWhitespace": true, "files.insertFinalNewline": true, - "powershell.scriptAnalysis.settingsPath": ".vscode\\analyzersettings.psd1" + "powershell.scriptAnalysis.settingsPath": ".vscode\\analyzersettings.psd1", + "markdownlint.config": { + "MD028": false, + "MD025": { + "front_matter_title": "" + } + } } diff --git a/CHANGELOG.md b/CHANGELOG.md index be82713e..e3f3fbb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added CMEmailNotificationComponent - Added CMGroupDiscovery Resource - Added CMSoftwareUpdatePointComponent resource +- Added CMClientSettings resource +- Added CMClientSettingsBits resource +- Added CMClientSettingsClientCache resource +- Added CMClientSettingsClientPolicy resource +- Added CMClientSettingsCloudService resource +- Added CMClientSettingsCompliance resource +- Added CMClientSettingsComputerAgent resource +- Added CMClientSettingsDelivery resource +- Added CMClientSettingsHardware resource +- Added CMClientSettingsMetered resource +- Added CMClientSettingsPower resource +- Added CMClientSettingsRemoteTools resource +- Added CMClientSettingsSoftwareCenter resource +- Added CMClientSettingsSoftwareDeployment resource +- Added CMClientSettingsSoftwareInventory resource +- Added CMClientSettingsSoftwareMetering resource +- Added CMClientSettingsSoftwareUpdate resource +- Added CMClientSettingsStateMessaging resource +- Added CMClientSettingsUserDeviceAffinity resource ### Fixed diff --git a/README.md b/README.md index 4b769446..3e6c37c4 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,44 @@ Please check out common DSC Community [contributing guidelines](https://dsccommu Group Discovery method. - **CMSoftwareUpdatePointComponent**: Provides a resource for modifying the Software Update Point Component settings in Configuration Manager. +- **CMClientSettings**: Provides a resource for creating, modifying, or + removing the client policies. +- **CMClientSettingsBits**: Provides a resource for modifying the + client policy settings for Bits settings. +- **CMClientSettingsClientCache**: Provides a resource for modifying the + client policy settings for Client Cache settings. +- **CMClientSettingsClientPolicy**: Provides a resource for modifying the + client policy settings for Client Policy settings. +- **CMClientSettingsCloudService**: Provides a resource for modifying the + client policy settings for Cloud Service settings. +- **CMClientSettingsCompliance**: Provides a resource for modifying the + client policy settings for Compliance settings. +- **CMClientSettingsComputerAgent**: Provides a resource for modifying the + client policy settings for Computer Agent settings. +- **CMClientSettingsDelivery**: Provides a resource for modifying the + client policy settings for Delivery settings. +- **CMClientSettingsHardware**: Provides a resource for modifying the + client policy settings for Hardware settings. +- **CMClientSettingsMetered**: Provides a resource for modifying the + client policy settings for Metered settings. +- **CMClientSettingsPower**: Provides a resource for modifying the + client policy settings for Power settings. +- **CMClientSettingsRemoteTools**: Provides a resource for modifying the + client policy settings for Remote Tools settings. +- **CMClientSettingsSoftwareCenter**: Provides a resource for modifying the + client policy settings for Software Center. +- **CMClientSettingsSoftwareDeployment**: Provides a resource for modifying the + client policy settings for Software Deployment settings. +- **CMClientSettingsSoftwareInventory**: Provides a resource for modifying the + client policy settings for Software Inventory settings. +- **CMClientSettingsSoftwareUpdate**: Provides a resource for modifying the + client policy setting for Software Updates settings. +- **CMClientSettingsSoftwareMetering**: Provides a resource for modifying the + client policy settings for Software Metering settings. +- **CMClientSettingsStateMessaging**: Provides a resource for modifying the + client policy settings for State Messaging settings. +- **CMClientSettingsUserDeviceAffinity**: Provides a resource for modifying the + client policy settings for User Device Affinity settings. ### xSccmPreReqs @@ -1523,6 +1561,592 @@ you are using apply and auto correct. - [CMSoftwareUpdatePointComponent_Match](Source\Examples\Resources\CMSoftwareUpdatePointComponent\CMSoftwareUpdatePointComponent_Match.ps1) - [CMSoftwareUpdatePointComponent_TopLevel](Source\Examples\Resources\CMSoftwareUpdatePointComponent\CMSoftwareUpdatePointComponent_TopLevel.ps1) +### CMClientSettings + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[String] Type** _(Required)_: Specifies the type of client policy. + - Values include: { Device | User } +- **[String] Description** _(Write)_: Specifies the description of the client policy. +- **[String] SecurityScopes[]** _(Write)_: Specifies an array of Security Scopes + to match. +- **[String] SecurityScopesToInclude[]** _(Write)_: Specifies an array of Security + Scopes to include. +- **[String] SecurityScopesToExclude[]** _(Write)_: Specifies an array of Security + Scopes to exclude. +- **[String] Ensure** _(Write)_: Specifies if the client policy is present or absent. + - Values include: { Present | Absent } + +#### CMClientSettings Examples + +- [CMClientSettings](Source\Examples\Resources\CMClientSettings\CMClientSettings.ps1) + +### CMClientSettingsBits + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[Boolean] EnableBitsMaxBandwidth** _(Required)_: Specifies if limit the + maximum network bandwidth for BITS background transfers is enabled or disabled. +- **[Uint32] MaxBandwidthBeginHr** _(Write)_: Specifies the throttling window + start time, use 0 for 12 a.m. and 23 for 11 p.m.. + - Values Range: 0 - 23 +- **[Uint32] MaxBandwidthEndHr** _(Write)_: Specifies the throttling window end + time, use 0 for 12 a.m. and 23 for 11 p.m.. + - Values Range: 0 - 23 +- **[UInt32] MaxTransferRateOnSchedule** _(Write)_: Specifies the maximum transfer + rate during throttling window in Kbps. + - Values Range: 1 - 9999 +- **[Boolean] EnableDownloadOffSchedule** _(Write)_: Specifies if BITS downloads + are allowed outside the throttling window. +- **[UInt32] MaxTransferRateOffSchedule** _(Write)_: Specifies the maximum transfer + rate outside the throttling window in Kbps. + - Values Range: 1- 999999 +- **[String] ClientSettingStatus** _(Read)_: Specifies if the client settings policy + exists. +- **[String] ClientType** _(Read)_: Specifies the type of client policy setting. + +#### CMClientSettingsBits Examples + +- [CMClientSettingsBits](Source\Examples\Resources\CMClientSettingsBits\CMClientSettingsBits.ps1) + +### CMClientSettingsClientCache + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[Boolean] ConfigureBranchCache** _(Write)_: Specifies if configure branch cache + policy is enabled or disabled. +- **[Boolean] EnableBranchCache** _(Write)_: Specifies if branch cache is enabled + or disabled. +- **[UInt32] MaxBranchCacheSizePercent** _(Write)_: Specifies the percentage of disk + size maximum branch cache size. +- **[Boolean] ConfigureCacheSize** _(Write)_: Specifies if client cache size is + enabled or disabled. +- **[UInt32] MaxCacheSize** _(Write)_: Specifies the maximum cache size by MB. +- **[UInt32] MaxCacheSizePercent** _(Write)_: Specifies the maximum cache size percentage. +- **[Boolean] EnableSuperPeer** _(Write)_: Specifies is peer cache source is enabled + or disabled. +- **[UInt32] BroadcastPort** _(Write)_: Specifies the port for initial network broadcast. +- **[UInt32] DownloadPort** _(Write)_: Specifies the port for content download from + peers. +- **[String] ClientSettingStatus** _(Read)_: Specifies if the client settings policy + exists. +- **[String] ClientType** _(Read)_: Specifies the type of client policy setting. + +#### CMClientSettingsClientCache Examples + +- [CMClientSettingsClientCache](Source\Examples\Resources\CMClientSettingsClientCache\CMClientSettingsClientCache.ps1) + +### CMClientSettingsClientPolicy + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[UInt32] PolicyPollingMins** _(Write)_: Specifies client policy interval in minutes. +- **[Boolean] EnableUserPolicy** _(Write)_: Specifies if user policy on clients is + enabled or disabled. +- **[Boolean] EnableUserPolicyOnInternet** _(Write)_: Specifies if user policy + request from internet clients is enabled or disabled. +- **[Boolean] EnableUserPolicyOnTS** _(Write)_: Specifies the maximum cache size + by MB. +- **[String] ClientSettingStatus** _(Read)_: Specifies if the client settings policy + exists. +- **[String] ClientType** _(Read)_: Specifies the type of client policy setting. + +#### CMClientSettingsClientPolicy Examples + +- [CMClientSettingsClientPolicy](Source\Examples\Resources\CMClientSettingsClientPolicy\CMClientSettingsClientPolicy.ps1) + +### CMClientSettingsCloudService + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[Boolean] AllowCloudDistributionPoint** _(Write)_: Specifies if allow access + to cloud distribution point is enabled or disabled. +- **[Boolean] AutoAzureADJoin** _(Write)_: Specifies whether to automatically + register new Windows 10 domain joined devices with Azure Active Directory. +- **[Boolean] AllowCloudManagementGateway** _(Write)_: Specifies if allow access + to cloud management gateway is enabled or disabled. +- **[String] ClientSettingStatus** _(Read)_: Specifies if the client settings policy + exists. +- **[String] ClientType** _(Read)_: Specifies the type of client policy setting. + +#### CMClientSettingsCloudService Examples + +- [CMClientSettingsCloudService](Source\Examples\Resources\CMClientSettingsCloudService\CMClientSettingsCloudService.ps1) + +### CMClientSettingsCompliance + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[Boolean] Enable** _(Required)_: Specifies if compliance evaluation on + clients is enabled or disabled. +- **[Boolean] EnableUserDataAndProfile** _(Write)_: Specifies if user data and + profiles are enabled or disabled. +- **[String] Start** _(Write)_: Specifies the start date and start time for the + compliance evaluation schedule Month/Day/Year, example 1/1/2020 02:00. +- **[String] ScheduleType** _(Write)_: Specifies the schedule type for the + compliance evaluation schedule. + - Values include: { MonthlyByDay | MonthlyByWeek | Weekly | Days | Hours } +- **[UInt32] RecurInterval** _(Write)_: Specifies how often the ScheduleType is run. +- **[String] MonthlyWeekOrder** _(Write)_: Specifies week order for MonthlyByWeek + schedule type. + - Values include: { First | Second | Third | Fourth | Last } +- **[String] DayOfWeek** _(Write)_: Specifies the day of week name for MonthlyByWeek + and Weekly schedules. + - Values include: { Sunday | Monday | Tuesday | Wednesday | Thursday | Friday + | Saturday } +- **[UInt32] DayOfMonth** _(Write)_: Specifies the day number for MonthlyByDay schedules. + - Values Range: 0 - 31 +- **[String] ClientSettingStatus** _(Read)_: Specifies if the client settings policy + exists. +- **[String] ClientType** _(Read)_: Specifies the type of client policy setting. + +#### CMClientSettingsCompliance Examples + +- [CMClientSettingsCompliance](Source\Examples\Resources\CMClientSettingsCompliance\CMClientSettingsCompliance.ps1) + +### CMClientSettingsComputerAgent + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[UInt32] InitialReminderHr** _(Write)_: Specifies reminder, in hours, for + deployment deadlines greater than 24 hours. + - Values Range: 1 - 999 +- **[UInt32] InterimReminderHr** _(Write)_: Specifies reminder, in hours, for deployment + deadlines less than 24 hours. + - Values Range: 1 - 24 +- **[UInt32] FinalReminderMins** _(Write)_: Specifies reminder, in minutes, for + deployment deadlines less than 1 hours. + - Values Range: 5 - 25 +- **[String] BrandingTitle** _(Write)_: Specifies the organizational name + displayed in software center. +- **[Boolean] UseNewSoftwareCenter** _(Write)_: Specifies if the new software center + is enabled or disabled. +- **[Boolean] EnableHealthAttestation** _(Write)_: Specifies if communication with + the Health Attestation service is enabled or disabled. +- **[Boolean] UseOnPremisesHealthAttestation** _(Write)_: Specifies if the on-premises + health service is enabled or disabled. +- **[String] InstallRestriction** _(Write)_: Specifies the install permissions. + - Values include: { AllUsers | OnlyAdministrators | OnlyAdministratorsAndPrimaryUsers | + NoUsers } +- **[String] SuspendBitLocker** _(Write)_: Specifies the suspend BitLocker PIN + entry on restart. + - Values include: { Never | Always } +- **[String] EnableThirdPartyOrchestration** _(Write)_: Specifies if additional + software manages the deployment of applications and updates. + - Values include: { No | Yes } +- **[String] PowerShellExecutionPolicy** _(Write)_: Specifies powershell execution + policy settings. + - Values include: { AllSigned | Bypass | Restricted } +- **[Boolean] DisplayNewProgramNotification** _(Write)_: Specifies if notifications + are shown for new deployments. +- **[String] ClientSettingStatus** _(Read)_: Specifies if the client settings policy + exists. +- **[String] ClientType** _(Read)_: Specifies the type of client policy setting. + +#### CMClientSettingsComputerAgent Examples + +- [CMClientSettingsComputerAgent](Source\Examples\Resources\CMClientSettingsComputerAgent\CMClientSettingsComputerAgent.ps1) + +### CMClientSettingsDelivery + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[Boolean] Enable** _(Write)_: Specifies if use Configuration Manager + Boundary Groups for Delivery Optimization Group ID is enabled or disabled. +- **[String] ClientSettingStatus** _(Read)_: Specifies if the client settings policy + exists. +- **[String] ClientType** _(Read)_: Specifies the type of client policy setting. + +#### CMClientSettingsDelivery Examples + +- [CMClientSettingsDelivery](Source\Examples\Resources\CMClientSettingsDelivery\CMClientSettingsDelivery.ps1) + +### CMClientSettingsHardware + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[Boolean] Enable** _(Required)_: Specifies if hardware inventory for + clients is enabled or disabled. +- **[UInt32] MaxRandomDelayMins** _(Write)_: Specifies the maximum random delay + in minutes. +- **[String] Start** _(Write)_: Specifies the start date and start time for the + hardware inventory schedule Month/Day/Year, example 1/1/2020 02:00. +- **[String] ScheduleType** _(Write)_: Specifies the schedule type for the + hardware inventory schedule. + - Values include: { MonthlyByDay | MonthlyByWeek | Weekly | Days | Hours } +- **[UInt32] RecurInterval** _(Write)_: Specifies how often the ScheduleType is run. +- **[String] MonthlyWeekOrder** _(Write)_: Specifies week order for MonthlyByWeek + schedule type. + - Values include: { First | Second | Third | Fourth | Last } +- **[String] DayOfWeek** _(Write)_: Specifies the day of week name for MonthlyByWeek + and Weekly schedules. + - Values include: { Sunday | Monday | Tuesday | Wednesday | Thursday | Friday + | Saturday } +- **[UInt32] DayOfMonth** _(Write)_: Specifies the day number for MonthlyByDay schedules. + - Values Range: 0 - 31 +- **[String] CollectMifFile** _(Write)_:Specifies the collected MIF files. + - Values include: { None | CollectNoIdMifFile | CollectIdMifFile + | CollectIdMifAndNoIdMifFile } +- **[UInt32] MaxThirdPartyMifSize** _(Write)_: Specifies the maximum custom MIF + file size in KB. +- **[String] ClientSettingStatus** _(Read)_: Specifies if the client settings policy + exists. +- **[String] ClientType** _(Read)_: Specifies the type of client policy setting. + +#### CMClientSettingsHardware Examples + +- [CMClientSettingsHardware](Source\Examples\Resources\CMClientSettingsHardware\CMClientSettingsHardware.ps1) + +### CMClientSettingsMetered + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[String] MeteredNetworkUsage** _(Write)_: Specifies setting for client + communication on a metered internet connection. + - Values include: { Allow | Limit | Block } +- **[String] ClientSettingStatus** _(Read)_: Specifies if the client settings policy + exists. +- **[String] ClientType** _(Read)_: Specifies the type of client policy setting. + +#### CMClientSettingsMetered Examples + +- [CMClientSettingsMetered](Source\Examples\Resources\CMClientSettingsMetered\CMClientSettingsMetered.ps1) + +### CMClientSettingsPower + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[Boolean] Enable** _(Write)_: Specifies if power management plan is to be used. +- **[Boolean] AllowUserToOptOutFromPowerPlan** _(Write)_: Specifies if users are + allowed to out out from the power plan. +- **[String] NetworkWakeUpOption** _(Write)_: Specifies if network wake up is + not configured, enabled or disabled. + - Values include: { NotConfigured | Enabled | Disabled } +- **[Boolean] EnableWakeUpProxy** _(Write)_: Specifies if the wake up proxy + will be enabled or disabled. +- **[UInt32] WakeupProxyPort** _(Write)_: Specifies the wake up proxy port. +- **[UInt32] WakeOnLanPort** _(Write)_: Specifies the wake on lan port. +- **[String] FirewallExceptionForWakeupProxy[]** _(Write)_: Specifies the which + firewall states will be configured for wakeup proxy. + - Values include: { None | Domain | Private | Public } +- **[String] WakeupProxyDirectAccessPrefix[]** _(Write)_: Specifies the IPV6 + direct access prefix for the wake up proxy. +- **[String] ClientSettingStatus** _(Read)_: Specifies if the client settings policy + exists. +- **[String] ClientType** _(Read)_: Specifies the type of client policy setting. + +#### CMClientSettingsPower Examples + +- [CMClientSettingsPower](Source\Examples\Resources\CMClientSettingsPower\CMClientSettingsPower.ps1) + +### CMClientSettingsRemoteTools + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[String] FirewallExceptionProfile[]** _(Write)_: Specifies if the firewall + exceptions profiles for Remote Tools. + - Values include: { Domain | Private | Public } +- **[Boolean] AllowClientChange** _(Write)_: Specifies if users can change policy + or notifications settings in software center. +- **[Boolean] AllowUnattendedComputer** _(Write)_: Specifies if allow remote control + of an unattended computer is enabled or disabled. +- **[Boolean] PromptUserForPermission** _(Write)_: Specifies if users are prompted + for remote control permissions. +- **[Boolean] PromptUserForClipboardPermission** _(Write)_: Specifies if users are + prompted for permission to transfer content from share clipboard. +- **[Boolean] GrantPermissionToLocalAdministrator** _(Write)_: Specifies if remote + control permissions are granted to the local administrators group. +- **[String] AccessLevel** _(Write)_: Specifies the access level allowed. + - Values include: { NoAccess | ViewOnly | FullControl } +- **[String] PermittedViewer[]** _(Write)_: Specifies the permitted viewers for + remote control and remote assistance. +- **[Boolean] ShowNotificationIconOnTaskbar** _(Write)_: Specifies if session + notifications are shown on the taskbar. +- **[Boolean] ShowSessionConnectionBar** _(Write)_: Specifies if the session + connection bar is shown. +- **[String] AudibleSignal** _(Write)_: Specifies if sound is played on the client. + - Values include: { PlayNoSound | PlaySoundAtBeginAndEnd | + PlaySoundRepeatedly } +- **[Boolean] ManageUnsolicitedRemoteAssistance** _(Write)_: Specifies if unsolicited + remote assistance settings are managed. +- **[Boolean] ManageSolicitedRemoteAssistance** _(Write)_: Specifies if solicited + remote assistance settings are managed. +- **[String] RemoteAssistanceAccessLevel** _(Write)_: Specifies the level of + access for remote assistance. + - Values include: { None | RemoteViewing | FullControl } +- **[Boolean] ManageRemoteDesktopSetting** _(Write)_: Specifies if remote desktop + settings are managed. +- **[Boolean] AllowPermittedViewer** _(Write)_: Specifies if permitted viewers are + allowed to connect by using remote desktop connection. +- **[Boolean] RequireAuthentication** _(Write)_: Specifies network level required + authentication on computers that run Vista or later versions. +- **[String] ClientSettingStatus** _(Read)_: Specifies if the client settings policy + exists. +- **[String] ClientType** _(Read)_: Specifies the type of client policy setting. +- **[String] RemoteToolsStatus** _(Read)_: Specifies if the Remote Tools settings + is enabled or disabled. + +#### CMClientSettingsRemoteTools Examples + +- [CMClientSettingsRemoteTools](Source\Examples\Resources\CMClientSettingsRemoteTools\CMClientSettingsRemoteTools.ps1) + +### CMClientSettingsSoftwareCenter + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[Boolean] EnableCustomize** _(Required)_: Specifies if custom software center + is to be used. +- **[String] CompanyName** _(Write)_: Specifies the company name to be used in + software center. +- **[String] ColorScheme** _(Write)_: Specifies in hex format the color to be + used in software center. +- **[Boolean] HideApplicationCatalogLink** _(Write)_: Specifies if application + catalog link is hidden. +- **[Boolean] HideInstalledApplication** _(Write)_: Specifies if installed + applications are hidden. +- **[Boolean] HideUnapprovedApplication** _(Write)_: Specifies if unapproved + applications are hidden. +- **[Boolean] EnableApplicationsTab** _(Write)_: Specifies if application tab is + visible. +- **[Boolean] EnableUpdatesTab** _(Write)_: Specifies if updates tab is visible. +- **[Boolean] EnableOperatingSystemsTab** _(Write)_: Specifies if operating system + tab is visible. +- **[Boolean] EnableStatusTab** _(Write)_: Specifies if status tab is visible. +- **[Boolean] EnableComplianceTab** _(Write)_: Specifies if compliance tab is visible. +- **[Boolean] EnableOptionsTab** _(Write)_: Specifies if options tab is visible. +- **[String] ClientSettingStatus** _(Read)_: Specifies if the client settings policy + exists. +- **[String] ClientType** _(Read)_: Specifies the type of client policy setting. +- **[String] PortalType** _(Read)_: Specifies the portal type selected. + +#### CMClientSettingsSoftwareCenter Examples + +- [CMClientSettingsSoftwareCenter](Source\Examples\Resources\CMClientSettingsSoftwareCenter\CMClientSettingsSoftwareCenter.ps1) + +### CMClientSettingsSoftwareDeployment + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[String] Start** _(Write)_:Specifies the start date and start time for the + software deployment schedule Month/Day/Year, example 1/1/2020 02:00. +- **[String] ScheduleType** _(Write)_: Specifies the schedule type for the + software deployment schedule. + - Values include: { MonthlyByDay | MonthlyByWeek | Weekly | Days | Hours } +- **[UInt32] RecurInterval** _(Write)_: Specifies how often the ScheduleType is run. +- **[String] MonthlyWeekOrder** _(Write)_: Specifies week order for MonthlyByWeek + schedule type. + - Values include: { First | Second | Third | Fourth | Last } +- **[String] DayOfWeek** _(Write)_: Specifies the day of week name for MonthlyByWeek + and Weekly schedules. + - Values include: { Sunday | Monday | Tuesday | Wednesday | Thursday | Friday + | Saturday } +- **[UInt32] DayOfMonth** _(Write)_: Specifies the day number for MonthlyByDay schedules. + - Values Range: 0 - 31 +- **[String] ClientSettingStatus** _(Read)_: Specifies if the client settings policy + exists. +- **[String] ClientType** _(Read)_: Specifies the type of client policy setting. + +#### CMClientSettingsSoftwareDeployment Examples + +- [CMClientSettingsSoftwareDeployment](Source\Examples\Resources\CMClientSettingsSoftwareDeployment\CMClientSettingsSoftwareDeployment.ps1) + +### CMClientSettingsSoftwareInventory + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[Boolean] Enable** _(Required)_: Specifies if software inventory on clients + is enabled or disabled. +- **[String] ReportOption** _(Key)_: Specify reporting inventory details level. + - Values include: { ProductOnly | FileOnly | FullDetail } +- **[String] Start** _(Write)_:Specifies the start date and start time for the + software inventory schedule Month/Day/Year, example 1/1/2020 02:00. +- **[String] ScheduleType** _(Write)_: Specifies the schedule type for the + software inventory schedule. + - Values include: { MonthlyByDay | MonthlyByWeek | Weekly | Days | Hours } +- **[UInt32] RecurInterval** _(Write)_: Specifies how often the ScheduleType is run. +- **[String] MonthlyWeekOrder** _(Write)_: Specifies week order for MonthlyByWeek + schedule type. + - Values include: { First | Second | Third | Fourth | Last } +- **[String] DayOfWeek** _(Write)_: Specifies the day of week name for MonthlyByWeek + and Weekly schedules. + - Values include: { Sunday | Monday | Tuesday | Wednesday | Thursday | Friday + | Saturday } +- **[UInt32] DayOfMonth** _(Write)_: Specifies the day number for MonthlyByDay schedules. + - Values Range: 0 - 31 +- **[String] ClientSettingStatus** _(Read)_: Specifies if the client settings policy + exists. +- **[String] ClientType** _(Read)_: Specifies the type of client policy setting. + +#### CMClientSettingsSoftwareInventory Examples + +- [CMClientSettingsSoftwareInventory](Source\Examples\Resources\CMClientSettingsSoftwareInventory\CMClientSettingsSoftwareInventory.ps1) + +### CMClientSettingsSoftwareMetering + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[Boolean] Enable** _(Required)_: Specifies if software metering on clients + is enabled or disabled. +- **[String] Start** _(Write)_:Specifies the start date and start time for the + software metering schedule Month/Day/Year, example 1/1/2020 02:00. +- **[String] ScheduleType** _(Write)_: Specifies the schedule type for the + software metering schedule. + - Values include: { MonthlyByDay | MonthlyByWeek | Weekly | Days | Hours } +- **[UInt32] RecurInterval** _(Write)_: Specifies how often the ScheduleType is run. +- **[String] MonthlyWeekOrder** _(Write)_: Specifies week order for MonthlyByWeek + schedule type. + - Values include: { First | Second | Third | Fourth | Last } +- **[String] DayOfWeek** _(Write)_: Specifies the day of week name for MonthlyByWeek + and Weekly schedules. + - Values include: { Sunday | Monday | Tuesday | Wednesday | Thursday | Friday + | Saturday } +- **[UInt32] DayOfMonth** _(Write)_: Specifies the day number for MonthlyByDay schedules. + - Values Range: 0 - 31 +- **[String] ClientSettingStatus** _(Read)_: Specifies if the client settings policy + exists. +- **[String] ClientType** _(Read)_: Specifies the type of client policy setting. + +#### CMClientSettingsSoftwareMetering Examples + +- [CMClientSettingsSoftwareMetering](Source\Examples\Resources\CMClientSettingsSoftwareMetering\CMClientSettingsSoftwareMetering.ps1) + +### CMClientSettingsSoftwareUpdate + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[Boolean] Enable** _(Required)_: Specifies if software updates on clients + is enabled or disabled. +- **[String] ScanStart** _(Write)_:Specifies the start date and start time for the + software update scan schedule Month/Day/Year, example 1/1/2020 02:00. +- **[String] ScanScheduleType** _(Write)_: Specifies the schedule type for the + software updates scan schedule. + - Values include: { MonthlyByDay | MonthlyByWeek | Weekly | Days | Hours } +- **[UInt32] ScanRecurInterval** _(Write)_: Specifies how often the scan ScheduleType + is run. +- **[String] ScanMonthlyWeekOrder** _(Write)_: Specifies week order for MonthlyByWeek + scan schedule type. + - Values include: { First | Second | Third | Fourth | Last } +- **[String] ScanDayOfWeek** _(Write)_: Specifies the day of week name for MonthlyByWeek + and Weekly scan schedules. + - Values include: { Sunday | Monday | Tuesday | Wednesday | Thursday | Friday + | Saturday } +- **[UInt32] ScanDayOfMonth** _(Write)_: Specifies the day number for MonthlyByDay + scan schedules. + - Values Range: 0 - 31 +- **[String] EvalStart** _(Write)_:Specifies the start date and start time for the + software update eval schedule Month/Day/Year, example 1/1/2020 02:00. +- **[String] EvalScheduleType** _(Write)_: Specifies the schedule type for the + software updates eval schedule. + - Values include: { MonthlyByDay | MonthlyByWeek | Weekly | Days | Hours } +- **[UInt32] EvalRecurInterval** _(Write)_: Specifies how often the eval ScheduleType + is run. +- **[String] EvalMonthlyWeekOrder** _(Write)_: Specifies week order for MonthlyByWeek + eval schedule type. + - Values include: { First | Second | Third | Fourth | Last } +- **[String] EvalDayOfWeek** _(Write)_: Specifies the day of week name for MonthlyByWeek + and Weekly eval schedules. + - Values include: { Sunday | Monday | Tuesday | Wednesday | Thursday | Friday + | Saturday } +- **[UInt32] EvalDayOfMonth** _(Write)_: Specifies the day number for MonthlyByDay + eval schedules. + - Values Range: 0 - 31 +- **[Boolean] EnforceMandatory** _(Write)_: Specifies if any software update + deployment deadline is reached to install all deployments with dealing coming + within a specific time period. +- **[String] TimeUnit** _(Write)_: Specifies the unit of time, hours or days + time frame to install pending software updates. + - Values include: { Hours | Days } +- **[UInt32] BatchingTimeOut** _(Write)_: Specifies the time within TimeUnit to + install the depending updates. +- **[Boolean] EnableDeltaDownload** _(Write)_: Specifies if clients are allowed to + download delta content when available. +- **[UInt32] DeltaDownloadPort** _(Write)_: Specifies the port that clients will + use to receive requests for delta content. +- **[Boolean] Office365ManagementType** _(Write)_: Specifies the management of the + Office 365 client. + - Values include: { NotConfigured | Yes | No } +- **[Boolean] EnableThirdPartyUpdates** _(Write)_: Specifies if third party updates + is enabled or disabled. +- **[String] ClientSettingStatus** _(Read)_: Specifies if the client settings policy + exists. +- **[String] ClientType** _(Read)_: Specifies the type of client policy setting. + +#### CMClientSettingsSoftwareUpdate Examples + +- [CMClientSettingsSoftwareUpdate](Source\Examples\Resources\CMClientSettingsSoftwareUpdate\CMClientSettingsSoftwareUpdate.ps1) + +### CMClientSettingsStateMessaging + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[UInt32] ReportingCycleMins** _(Write)_: Specifies the state message reporting + cycle in minutes. +- **[String] ClientSettingStatus** _(Read)_: Specifies if the client settings policy + exists. +- **[String] ClientType** _(Read)_: Specifies the type of client policy setting. + +#### CMClientSettingsStateMessaging Examples + +- [CMClientSettingsStateMessaging](Source\Examples\Resources\CMClientSettingsStateMessaging\CMClientSettingsStateMessaging.ps1) + +### CMClientSettingsUserDeviceAffinity + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] ClientSettingName** _(Key)_: Specifies which client settings policy + to modify. +- **[UInt32] LogOnThresholdMins** _(Write)_: Specifies if user device affinity + usage threshold in minutes. +- **[UInt32] UsageThresholdDays** _(Write)_: Specifies if user device affinity + usage threshold in days. +- **[Boolean] AutoApproveAffinity** _(Write)_: Specifies allowing automatic + configure user device affinity from usage data. +- **[Boolean] AllowUserAffinity** _(Write)_: Specifies allowing users to define + their primary device. +- **[String] ClientSettingStatus** _(Read)_: Specifies if the client settings policy + exists. +- **[String] ClientType** _(Read)_: Specifies the type of client policy setting. + +#### CMClientSettingsUserDeviceAffinity Examples + +- [CMClientSettingsUserDeviceAffinity](Source\Examples\Resources\CMClientSettingsUserDeviceAffinity\CMClientSettingsUserDeviceAffinity.ps1) + ## ReverseDsc Most organizations using this module already have an existing Configuration Manager @@ -1570,6 +2194,25 @@ all of the modules and specify if it is currently supported by ReverseDSC. and will not populate or gather the boundaries within the group. - DSC_CMClientPushSettings: Fully Supported - DSC_CMClientStatusSettings: Fully Supported +- DSC_CMClientSettings : Fully Supported +- DSC_CMClientSettingsBits : Fully Supported +- DSC_CMClientSettingsClientCache : Fully Supported +- DSC_CMClientSettingsClientPolicy : Fully Supported +- DSC_CMClientSettingsCloudService : Fully Supported +- DSC_CMClientSettingsCompliance : Fully Supported +- DSC_CMClientSettingsComputerAgent : Fully Supported +- DSC_CMClientSettingsDelivery : Fully Supported +- DSC_CMClientSettingsHardware : Fully Supported +- DSC_CMClientSettingsMetered : Fully Supported +- DSC_CMClientSettingsPower : Fully Supported +- DSC_CMClientSettingsRemoteTools : Fully Supported +- DSC_CMClientSettingsSoftwareCenter : Fully Supported +- DSC_CMClientSettingsSoftwareDeployment : Fully Supported +- DSC_CMClientSettingsSoftwareInventory : Fully Supported +- DSC_CMClientSettingsSoftwareMetering : Fully Supported +- DSC_CMClientSettingsSoftwareUpdate : Fully Supported +- DSC_CMClientSettingsStateMessaging : Fully Supported +- DSC_CMClientSettingsUserDeviceAffinity : Fully Supported - DSC_CMCollectionMembershipEvaluationComponent: Fully Supported - DSC_CMCollections: Fully Supported - DSC_CMDistributionGroup: Fully Supported @@ -1629,7 +2272,13 @@ After importing the module, Set-ConfigMgrCBDscReverse will be available. NetworkDiscovery|PullDistributionPoint|PxeDistributionPoint|GroupDiscovery| ReportingServicesPoint|SecurityScopes|ServiceConnection|SiteMaintenance| SiteSystemServer|SoftwareDistributionComponent|SoftwareUpdatePoint|SoftwareupdatePointComponent| - StatusReportingComponent|SystemDiscovery|UserDiscovery|ConfigFileOnly } + StatusReportingComponent|SystemDiscovery|UserDiscovery|ConfigFileOnly|ClientSettings| + ClientSettingsBits|ClientSettingsClientCache|ClientSettingsClientPolicy|ClientSettingsCloudService| + ClientSettingsCompliance|ClientSettingsComputerAgent|ClientSettingsDelivery|ClientSettingsHardware| + ClientSettingsMetered|ClientSettingsPower|ClientSettingsRemoteTools|ClientSettingsSoftwareCenter| + ClientSettingsSoftwareDeployment|ClientSettingsSoftwareInventory|ClientSettingsSoftwareMetering| + ClientSettingsSoftwareUpdate|ClientSettingsStateMessaging| + ClientSettingsUserDeviceAffinity } - **[String] Exclude** _(Write)_: Specifies which resources will be excluded from being evaluated. Only evaluated when Include = 'All' - Values include: { Accounts|AdministrativeUser|AssetIntelligencePoint|BoundaryGroups| @@ -1639,7 +2288,13 @@ After importing the module, Set-ConfigMgrCBDscReverse will be available. NetworkDiscovery|PullDistributionPoint|PxeDistributionPoint|GroupDiscovery| ReportingServicesPoint|SecurityScopes|ServiceConnection|SiteMaintenance| SiteSystemServer|SoftwareDistributionComponent|SoftwareUpdatePoint|SoftwareupdatePointComponent| - StatusReportingComponent|SystemDiscovery|UserDiscovery } + StatusReportingComponent|SystemDiscovery|UserDiscovery|ClientSettings| + ClientSettingsBits|ClientSettingsClientCache|ClientSettingsClientPolicy|ClientSettingsCloudService| + ClientSettingsCompliance|ClientSettingsComputerAgent|ClientSettingsDelivery|ClientSettingsHardware| + ClientSettingsMetered|ClientSettingsPower|ClientSettingsRemoteTools|ClientSettingsSoftwareCenter| + ClientSettingsSoftwareDeployment|ClientSettingsSoftwareInventory|ClientSettingsSoftwareMetering| + ClientSettingsSoftwareUpdate|ClientSettingsStateMessaging| + ClientSettingsUserDeviceAffinity } - **[String] DataFile** _(Write)_: Specifies where the data file will be saved. Filename must end with .psd1. Not specifying DataFile the output will be displayed in the output screen only if Include does not equal ConfigFileOnly. diff --git a/source/ConfigMgrCBDsc.psd1 b/source/ConfigMgrCBDsc.psd1 index 81a3ce89..490cef74 100644 --- a/source/ConfigMgrCBDsc.psd1 +++ b/source/ConfigMgrCBDsc.psd1 @@ -82,6 +82,25 @@ 'CMEmailNotificationComponent' 'CMGroupDiscovery' 'CMSoftwareUpdatePointComponent' + 'CMClientSettings' + 'CMClientSettingsBits' + 'CMClientSettingsClientCache' + 'CMClientSettingsClientPolicy' + 'CMClientSettingsCloudService' + 'CMClientSettingsCompliance' + 'CMClientSettingsComputerAgent' + 'CMClientSettingsDelivery' + 'CMClientSettingsHardware' + 'CMClientSettingsMetered' + 'CMClientSettingsPower' + 'CMClientSettingsRemoteTools' + 'CMClientSettingsSoftwareCenter' + 'CMClientSettingsSoftwareDeployment' + 'CMClientSettingsSoftwareInventory' + 'CMClientSettingsSoftwareMetering' + 'CMClientSettingsSoftwareUpdate' + 'CMClientSettingsStateMessaging' + 'CMClientSettingsUserDeviceAffinity' ) <# @@ -100,7 +119,11 @@ 'ServiceConnectionPoint','NetworkDiscovery','ReportingServicePoint','SystemDiscovery','PXEDistributionPoint','PullDistributionPoint', 'SiteMaintenance','AdministrativeUser','DistributionGroup','SiteSystemServer','StatusReportingComponent','CollectionMembershipEvaluationComponent', 'DistributionPointGroupMembers','SecurityScopes','UserDiscovery','SecurityRoles','ClientPushSettings','SoftwareDistributionComponent', - 'MaintenanceWindows','FileReplication','EmailNotificationComponent','CMGroupDiscovery','SoftwareUpdatePointComponent') + 'MaintenanceWindows','FileReplication','EmailNotificationComponent','CMGroupDiscovery','SoftwareUpdatePointComponent','ClientSettings', + 'ClientSettingsBits','ClientSettingsClientCache','ClientSettingsClientPolicy','ClientSettingsCompliance','ClientSettingsComputerAgent', + 'ClientSettingsDelivery','ClientSettingsHardware','ClientSettingsMetered','ClientSettingsPower','ClientSettingsRemoteTools', + 'ClientSettingsSoftwareCenter','ClientSettingsSoftwareDeployment','ClientSettingsSoftwareInventory','ClientSettingsSoftwareMetering', + 'ClientSettingsSoftwareUpdate','ClientSettingsStateMessaging','ClientSettingsUserDeviceAffinity') # A URL to the license for this module. LicenseUri = 'https://github.com/dsccommunity/ConfigMgrCBDsc/blob/master/LICENSE' diff --git a/source/DSCResources/DSC_CMClientSettings/DSC_CMClientSettings.psm1 b/source/DSCResources/DSC_CMClientSettings/DSC_CMClientSettings.psm1 new file mode 100644 index 00000000..e9370721 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettings/DSC_CMClientSettings.psm1 @@ -0,0 +1,460 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Type + Specifies the client type, Device or User. + Not Used in Get. +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [ValidateSet('Device','User')] + [String] + $Type + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + if ($clientSetting.Type -ne 0) + { + $descript = $clientSetting.Description + $clientType = @('Device','User')[$clientSetting.Type - 1] + [array]$scopes = $clientSetting.SecuredScopeNames + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + Description = $descript + Type = $clientType + SecurityScopes = $scopes + Ensure = $status + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Type + Specifies the client type, Device or User. + + .Parameter Description + Specifies the description of the client policy. + + .Parameter SecurityScopes + Specifies an array of Security Scopes to match. + + .Parameter SecurityScopesToInclude + Specifies an array of Security Scopes to include. + + .Parameter SecurityScopesToExclude + Specifies an array of Security Scopes to exclude. + + .Parameter Ensure + Specifies if the client policy is present or absent. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [ValidateSet('Device','User')] + [String] + $Type, + + [Parameter()] + [String] + $Description, + + [Parameter()] + [String[]] + $SecurityScopes, + + [Parameter()] + [String[]] + $SecurityScopesToInclude, + + [Parameter()] + [String[]] + $SecurityScopesToExclude, + + [Parameter()] + [ValidateSet('Present','Absent')] + [String] + $Ensure = 'Present' + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName -Type $Type + + try + { + if ($state.Ensure -ne 'Absent' -and $state.Type -ne $Type) + { + throw ($script:localizedData.TypeMisMatch -f $ClientSettingName) + } + elseif ($Ensure -eq 'Present') + { + if ($PSBoundParameters.ContainsKey('SecurityScopes')) + { + if ($PSBoundParameters.ContainsKey('SecurityScopesToInclude') -or + $PSBoundParameters.ContainsKey('SecurityScopesToExclude')) + { + Write-Warning -Message $script:localizedData.ParamIgnoreScopes + } + } + elseif (-not $PSBoundParameters.ContainsKey('SecurityScopes') -and + $PSBoundParameters.ContainsKey('SecurityScopesToInclude') -and + $PSBoundParameters.ContainsKey('SecurityScopesToExclude')) + { + foreach ($item in $SecurityScopesToInclude) + { + if ($SecurityScopesToExclude -contains $item) + { + throw ($script:localizedData.ScopeInEx -f $item) + } + } + } + elseif (-not $PSBoundParameters.ContainsKey('SecurityScopes') -and + -not $PSBoundParameters.ContainsKey('SecurityScopesToInclude') -and + $PSBoundParameters.ContainsKey('SecurityScopesToExclude')) + { + if ($state.SecurityScopes.Count -eq $SecurityScopesToExclude.Count) + { + $excludeAll = Compare-Object -ReferenceObject $state.SecurityScopes -DifferenceObject $SecurityScopesToExclude + if ([string]::IsNullOrEmpty($excludeAll)) + { + throw ($script:localizedData.ScopeExcludeAll) + } + } + } + + if ($state.Ensure -eq 'Absent') + { + if ($PSBoundParameters.ContainsKey('Description')) + { + $newParams = @{ + Name = $ClientSettingName + Type = $Type + Description = $Description + } + } + else + { + $newParams = @{ + Name = $ClientSettingName + Type = $Type + } + } + + New-CMClientSetting @newParams + $newClient = $true + } + + if ($newClient -ne $true -and $PSBoundParameters.ContainsKey('Description') -and $Description -ne $state.Description) + { + Set-CMClientSetting -Name $ClientSettingName -Description $Description + } + + if ($SecurityScopes -or $SecurityScopesToInclude -or $SecurityScopesToExclude) + { + if ($newClient -eq $true) + { + [array]$updateState = $state.SecurityScopes + $updateState += @('Default') + } + else + { + $updateState = $state.SecurityScopes + } + + $scopeArray = @{ + Match = $SecurityScopes + Include = $SecurityScopesToInclude + Exclude = $SecurityScopesToExclude + CurrentState = $updateState + } + + $scopeCompare = Compare-MultipleCompares @scopeArray + + if ($scopeCompare.Missing -or $scopeCompare.Remove) + { + $clientObject = Get-CMClientSetting -Name $ClientSettingName + } + + if ($scopeCompare.Missing) + { + foreach ($add in $scopeCompare.Missing) + { + if (Get-CMSecurityScope -Name $add) + { + Write-Verbose -Message ($script:localizedData.AddScope -f $add, $ClientSettingName) + Add-CMObjectSecurityScope -Name $add -InputObject $clientObject + } + else + { + $errorMsg += ($script:localizedData.SecurityScopeMissing -f $add) + } + } + } + + if ($scopeCompare.Remove) + { + foreach ($remove in $scopeCompare.Remove) + { + Write-Verbose -Message ($script:localizedData.RemoveScope -f $remove, $ClientSettingName) + Remove-CMObjectSecurityScope -Name $remove -InputObject $clientObject + } + } + } + } + elseif ($state.Ensure -eq 'Present') + { + Write-Verbose -Message ($script:localizedData.SetAbsent -f $ClientSettingName) + Remove-CMClientSetting -Name $ClientSettingName + } + + if ($errorMsg) + { + throw ($errorMsg | Out-String) + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Type + Specifies the client type, Device or User. + + .Parameter Description + Specifies the description of the client policy. + + .Parameter SecurityScopes + Specifies an array of Security Scopes to match. + + .Parameter SecurityScopesToInclude + Specifies an array of Security Scopes to include. + + .Parameter SecurityScopesToExclude + Specifies an array of Security Scopes to exclude. + + .Parameter Ensure + Specifies if the client policy is present or absent. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [ValidateSet('Device','User')] + [String] + $Type, + + [Parameter()] + [String] + $Description, + + [Parameter()] + [String[]] + $SecurityScopes, + + [Parameter()] + [String[]] + $SecurityScopesToInclude, + + [Parameter()] + [String[]] + $SecurityScopesToExclude, + + [Parameter()] + [ValidateSet('Present','Absent')] + [String] + $Ensure = 'Present' + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName -Type $Type + $result = $true + + if ($state.Ensure -ne 'Absent' -and $state.Type -ne $Type) + { + Write-Warning -Message ($script:localizedData.TypeMisMatch -f $ClientSettingName) + $result = $false + } + elseif ($Ensure -eq 'Present') + { + $defaultValues = @('Type','Description','Ensure') + + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = $defaultValues + } + + $result = Test-DscParameterState @testParams -TurnOffTypeChecking -Verbose + + if ($PSBoundParameters.ContainsKey('SecurityScopes')) + { + if ($PSBoundParameters.ContainsKey('SecurityScopesToInclude') -or + $PSBoundParameters.ContainsKey('SecurityScopesToExclude')) + { + Write-Warning -Message $script:localizedData.ParamIgnoreScopes + } + } + elseif (-not $PSBoundParameters.ContainsKey('SecurityScopes') -and + $PSBoundParameters.ContainsKey('SecurityScopesToInclude') -and + $PSBoundParameters.ContainsKey('SecurityScopesToExclude')) + { + foreach ($item in $SecurityScopesToInclude) + { + if ($SecurityScopesToExclude -contains $item) + { + Write-Warning -Message ($script:localizedData.ScopeInEx -f $item) + $badInput = $true + } + } + } + elseif (-not $PSBoundParameters.ContainsKey('SecurityScopes') -and + -not $PSBoundParameters.ContainsKey('SecurityScopesToInclude') -and + $PSBoundParameters.ContainsKey('SecurityScopesToExclude')) + { + if ($state.SecurityScopes.Count -eq $SecurityScopesToExclude.Count) + { + $excludeAll = Compare-Object -ReferenceObject $state.SecurityScopes -DifferenceObject $SecurityScopesToExclude + if ([string]::IsNullOrEmpty($excludeAll)) + { + Write-Warning -Message ($script:localizedData.ScopeExcludeAll) + $bardInput = $true + } + } + } + + if ($SecurityScopes -or $SecurityScopesToInclude -or $SecurityScopesToExclude) + { + $scopeArray = @{ + Match = $SecurityScopes + Include = $SecurityScopesToInclude + Exclude = $SecurityScopesToExclude + CurrentState = $state.SecurityScopes + } + + $scopeCompare = Compare-MultipleCompares @scopeArray + + if ($scopeCompare.Missing) + { + Write-Verbose -Message ($script:localizedData.ScopeMissing -f ($scopeCompare.Missing | Out-String)) + $result = $false + } + + if ($scopeCompare.Remove) + { + Write-Verbose -Message ($script:localizedData.ScopeRemove -f ($scopeCompare.Remove | Out-String)) + $result = $false + } + } + } + elseif ($state.Ensure -eq 'Present') + { + Write-Verbose -Message ($script:localizedData.AbsentMsg -f $ClientSettingName) + $result = $false + } + + if ($result -eq $false -or $badInput -eq $true) + { + $finalResult = $false + } + else + { + $finalResult = $true + } + + Write-Verbose -Message ($script:localizedData.TestState -f $finalResult) + Set-Location -Path "$env:temp" + return $finalResult +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettings/DSC_CMClientSettings.schema.mof b/source/DSCResources/DSC_CMClientSettings/DSC_CMClientSettings.schema.mof new file mode 100644 index 00000000..6685f416 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettings/DSC_CMClientSettings.schema.mof @@ -0,0 +1,12 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettings")] +class DSC_CMClientSettings : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Required, Description("Specifies the type of client policy."), ValueMap{"Device","User"}, Values{"Device","User"}] String Type; + [Write, Description("Specifies the description of the client policy.")] String Description; + [Write, Description("Specifies an array of Security Scopes to match.")] String SecurityScopes[]; + [Write, Description("Specifies an array of Security Scopes to include.")] String SecurityScopesToInclude[]; + [Write, Description("Specifies an array of Security Scopes to exclude.")] String SecurityScopesToExclude[]; + [Write, Description("Specifies if the client policy is present or absent."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; +}; diff --git a/source/DSCResources/DSC_CMClientSettings/en-US/DSC_CMClientSettings.strings.psd1 b/source/DSCResources/DSC_CMClientSettings/en-US/DSC_CMClientSettings.strings.psd1 new file mode 100644 index 00000000..dc4370bd --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettings/en-US/DSC_CMClientSettings.strings.psd1 @@ -0,0 +1,15 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy settings. + TestState = Test-TargetResource compliance check returned: {0}. + TypeMisMatch = The {0} client setting already exists as a different type. + AbsentMsg = NOT MATCH: {0} current state is present and expected absent. + SetAbsent = Removing {0} client setting policy. + ParamIgnoreScopes = SecurityScopes was specifed, ignoring SecurityScopesToInclude and SecurityScopesToExclude. + ScopeInEx = SecurityScopesToInclude and SecurityScopesToExclude contain to same entry {0}, remove from one of the arrays. + ScopeMissing = NOT MATCH: Client Settings Policy expected the following Scopes: {0}. + ScopeRemove = NOT MATCH: Client Settings Policy expected the following Scopes to be absent: {0}. + AddScope = Adding Security Scope {0} to {1}. + RemoveScope = Removing Security Scope {0} from {1}. + ScopeExcludeAll = Client Settings Policy must have at least 1 Security Scope assigned, SecurityScopesToExclude is currently set to remove all Security Scopes. + SecurityScopeMissing = The Security Scope specified does not exist: {0}. +'@ diff --git a/source/DSCResources/DSC_CMClientSettingsBits/DSC_CMClientSettingsBits.psm1 b/source/DSCResources/DSC_CMClientSettingsBits/DSC_CMClientSettingsBits.psm1 new file mode 100644 index 00000000..050502d9 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsBits/DSC_CMClientSettingsBits.psm1 @@ -0,0 +1,371 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER EnableBitsMaxBandwidth + Specifies if limit the maximum network bandwidth for BITS background transfers is enabled or disabled. + Not used in GET. +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $EnableBitsMaxBandwidth + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + $type = @('Default','Device','User')[$clientSetting.Type] + $settings = Get-CMClientSetting -Name $ClientSettingName -Setting BackgroundIntelligentTransfer + + if ($settings) + { + $bitsEnabled = [System.Convert]::ToBoolean($settings.EnableBitsMaxBandwidth) + $beginHour = $settings.MaxBandwidthValidFrom + $endHour = $settings.MaxBandwidthValidTo + $transOnSchedule = $settings.MaxTransferRateOnSchedule + $transOffSchedule = $settings.MaxTransferRateOffSchedule + $enableOfSchedule = [System.Convert]::ToBoolean($settings.EnableDownloadOffSchedule) + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + EnableBitsMaxBandwidth = $bitsEnabled + MaxBandwidthBeginHr = $beginHour + MaxBandwidthEndHr = $endHour + MaxTransferRateOnSchedule = $transOnSchedule + EnableDownloadOffSchedule = $enableOfSchedule + MaxTransferRateOffSchedule = $transOffSchedule + ClientSettingStatus = $status + ClientType = $type + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER EnableBitsMaxBandwidth + Specifies if limit the maximum network bandwidth for BITS background transfers is enabled or disabled. + + .PARAMETER MaxBandwidthBeginHr + Specifies the throttling window start time, use 0 for 12 a.m. and 23 for 11 p.m.. + + .PARAMETER MaxBandwidthEndHr + Specifies the throttling window end time, use 0 for 12 a.m. and 23 for 11 p.m.. + + .PARAMETER MaxTransferRateOnSchedule + Specifies the maximum transfer rate during throttling window in Kbps. + + .PARAMETER EnableDownloadOffSchedule + Specifies if BITS downloads are allowed outside the throttling window. + + .PARAMETER MaxTransferRateOffSchedule + Specifies the maximum transfer rate outside the throttling window in Kbps. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $EnableBitsMaxBandwidth, + + [Parameter()] + [ValidateRange(0,23)] + [UInt32] + $MaxBandwidthBeginHr, + + [Parameter()] + [ValidateRange(0,23)] + [UInt32] + $MaxBandwidthEndHr, + + [Parameter()] + [ValidateRange(1,9999)] + [UInt32] + $MaxTransferRateOnSchedule, + + [Parameter()] + [Boolean] + $EnableDownloadOffSchedule, + + [Parameter()] + [ValidateRange(1,999999)] + [UInt32] + $MaxTransferRateOffSchedule + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName -EnableBitsMaxBandwidth $EnableBitsMaxBandwidth + + try + { + if ($state.ClientSettingStatus -eq 'Absent') + { + throw ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + } + + if ($state.ClientType -eq 'User') + { + throw $script:localizedData.WrongClientType + } + + if ($EnableBitsMaxBandwidth -eq $true) + { + if (($MaxTransferRateOffSchedule) -and ($PSBoundParameters.ContainsKey('EnableDownloadOffSchedule') -and + $EnableDownloadOffSchedule -eq $false)) + { + Write-Warning -Message $script:localizedData.MaxOffBits + $defaultValues = @('EnableBitsMaxBandwidth','MaxBandwidthBeginHr','MaxBandwidthEndHr','MaxTransferRateOnSchedule', + 'EnableDownloadOffSchedule') + } + else + { + $defaultValues = @('EnableBitsMaxBandwidth','MaxBandwidthBeginHr','MaxBandwidthEndHr','MaxTransferRateOnSchedule', + 'EnableDownloadOffSchedule','MaxTransferRateOffSchedule') + } + + foreach ($param in $PSBoundParameters.GetEnumerator()) + { + if ($defaultValues -contains $param.Key) + { + if ($param.Value -ne $state[$param.Key]) + { + Write-Verbose -Message ($script:localizedData.SettingValue -f $param.Key, $param.Value) + $buildingParams += @{ + $param.Key = $param.Value + } + } + } + } + } + elseif ($state.EnableBitsMaxBandwidth -eq $true) + { + if ($PSBoundParameters.ContainsKey('MaxBandwidthBeginHr') -or + $PSBoundParameters.ContainsKey('MaxBandwidthEndHr') -or + $PSBoundParameters.ContainsKey('MaxTransferRateOnSchedule') -or + $PSBoundParameters.ContainsKey('EnableDownloadOffSchedule') -or + $PSBoundParameters.ContainsKey('MaxTransferRateOffSchedule')) + { + Write-Warning -Message $script:localizedData.DisabledExtraParams + } + + Write-Verbose -Message ($script:localizedData.SettingEnable -f $state.EnableBitsMaxBandwidth, $EnableBitsMaxBandwidth) + + $buildingParams = @{ + EnableBitsMaxBandwidth = $false + } + } + + if ($buildingParams) + { + if ($state.ClientType -eq 'Default') + { + Set-CMClientSettingBackgroundIntelligentTransfer -DefaultSetting @buildingParams + } + else + { + Set-CMClientSettingBackgroundIntelligentTransfer -Name $ClientSettingName @buildingParams + } + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER EnableBitsMaxBandwidth + Specifies if limit the maximum network bandwidth for BITS background transfers is enabled or disabled. + + .PARAMETER MaxBandwidthBeginHr + Specifies the throttling window start time, use 0 for 12 a.m. and 23 for 11 p.m.. + + .PARAMETER MaxBandwidthEndHr + Specifies the throttling window end time, use 0 for 12 a.m. and 23 for 11 p.m.. + + .PARAMETER MaxTransferRateOnSchedule + Specifies the maximum transfer rate during throttling window in Kbps. + + .PARAMETER EnableDownloadOffSchedule + Specifies if BITS downloads are allowed outside the throttling window. + + .PARAMETER MaxTransferRateOffSchedule + Specifies the maximum transfer rate outside the throttling window in Kbps. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $EnableBitsMaxBandwidth, + + [Parameter()] + [ValidateRange(0,23)] + [UInt32] + $MaxBandwidthBeginHr, + + [Parameter()] + [ValidateRange(0,23)] + [UInt32] + $MaxBandwidthEndHr, + + [Parameter()] + [ValidateRange(1,9999)] + [UInt32] + $MaxTransferRateOnSchedule, + + [Parameter()] + [Boolean] + $EnableDownloadOffSchedule, + + [Parameter()] + [ValidateRange(1,999999)] + [UInt32] + $MaxTransferRateOffSchedule + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName -EnableBitsMaxBandwidth $EnableBitsMaxBandwidth + $result = $true + + if ($state.ClientSettingStatus -eq 'Absent') + { + Write-Warning -Message ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + $result = $false + } + elseif ($state.ClientType -eq 'User') + { + Write-Warning -Message $script:localizedData.WrongClientType + $result = $false + } + else + { + if ($EnableBitsMaxBandwidth -eq $true) + { + if (($MaxTransferRateOffSchedule) -and ($PSBoundParameters.ContainsKey('EnableDownloadOffSchedule') -and + $EnableDownloadOffSchedule -eq $false)) + { + Write-Warning -Message $script:localizedData.MaxOffBits + $defaultValues = @('EnableBitsMaxBandwidth','MaxBandwidthBeginHr','MaxBandwidthEndHr','MaxTransferRateOnSchedule', + 'EnableDownloadOffSchedule') + } + else + { + $defaultValues = @('EnableBitsMaxBandwidth','MaxBandwidthBeginHr','MaxBandwidthEndHr','MaxTransferRateOnSchedule', + 'EnableDownloadOffSchedule','MaxTransferRateOffSchedule') + } + + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = $defaultValues + } + + $result = Test-DscParameterState @testParams -TurnOffTypeChecking -Verbose + } + elseif ($state.EnableBitsMaxBandwidth -eq $true) + { + if ($PSBoundParameters.ContainsKey('MaxBandwidthBeginHr') -or + $PSBoundParameters.ContainsKey('MaxBandwidthEndHr') -or + $PSBoundParameters.ContainsKey('MaxTransferRateOnSchedule') -or + $PSBoundParameters.ContainsKey('EnableDownloadOffSchedule') -or + $PSBoundParameters.ContainsKey('MaxTransferRateOffSchedule')) + { + Write-Warning -Message $script:localizedData.DisabledExtraParams + } + + Write-Verbose -Message ($script:localizedData.SettingEnable -f $state.EnableBitsMaxBandwidth, $EnableBitsMaxBandwidth) + $result = $false + } + } + + Write-Verbose -Message ($script:localizedData.TestState -f $result) + Set-Location -Path "$env:temp" + return $result +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettingsBits/DSC_CMClientSettingsBits.schema.mof b/source/DSCResources/DSC_CMClientSettingsBits/DSC_CMClientSettingsBits.schema.mof new file mode 100644 index 00000000..b5f4b205 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsBits/DSC_CMClientSettingsBits.schema.mof @@ -0,0 +1,14 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettingsBits")] +class DSC_CMClientSettingsBits : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Required, Description("Specifies if limit the maximum network bandwidth for BITS background transfers is enabled or disabled.")] Boolean EnableBitsMaxBandwidth; + [Write, Description("Specifies the throttling window start time, use 0 for 12 a.m. and 23 for 11 p.m..")] UInt32 MaxBandwidthBeginHr; + [Write, Description("Specifies the throttling window end time, use 0 for 12 a.m. and 23 for 11 p.m..")] UInt32 MaxBandwidthEndHr; + [Write, Description("Specifies the maximum transfer rate during throttling window in Kbps.")] UInt32 MaxTransferRateOnSchedule; + [Write, Description("Specifies if BITS downloads are allowed outside the throttling window.")] Boolean EnableDownloadOffSchedule; + [Write, Description("Specifies the maximum transfer rate outside the throttling window in Kbps.")] UInt32 MaxTransferRateOffSchedule; + [Read, Description("Specifies if the client settings policy exists.")] String ClientSettingStatus; + [Read, Description("Specifies the type of client policy setting.")] String ClientType; +}; diff --git a/source/DSCResources/DSC_CMClientSettingsBits/en-US/DSC_CMClientSettingsBits.strings.psd1 b/source/DSCResources/DSC_CMClientSettingsBits/en-US/DSC_CMClientSettingsBits.strings.psd1 new file mode 100644 index 00000000..5f256767 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsBits/en-US/DSC_CMClientSettingsBits.strings.psd1 @@ -0,0 +1,10 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy for bits settings. + ClientPolicySetting = Client Policy setting {0} does not exist, and will need to be created prior to making client setting changes. + TestState = Test-TargetResource compliance check returned: {0}. + SettingEnable = NOT MATCH: EnableBitsMaxBandwidth is currently set to {0}, expected {1}. + SettingValue = Setting value: {0} to {1}. + WrongClientType = Client Settings for Bits only applies to Default and Device Client settings. + MaxOffBits = MaxTransferRateOffSchedule is specified, this setting can not be set unless EnableDownloadOffSchedule is set to true, ignoring setting. + DisabledExtraParams = Setting EnableBitsMaxBandwidth to disabled, ignoring all other parameters specified. +'@ diff --git a/source/DSCResources/DSC_CMClientSettingsClientCache/DSC_CMClientSettingsClientCache.psm1 b/source/DSCResources/DSC_CMClientSettingsClientCache/DSC_CMClientSettingsClientCache.psm1 new file mode 100644 index 00000000..8274a8f1 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsClientCache/DSC_CMClientSettingsClientCache.psm1 @@ -0,0 +1,405 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + $type = @('Default','Device','User')[$clientSetting.Type] + $settings = Get-CMClientSetting -Name $ClientSettingName -Setting ClientCache + + if ($settings) + { + $configBranchCache = [System.Convert]::ToBoolean($settings.ConfigureBranchCache) + $branchCache = [System.Convert]::ToBoolean($settings.BranchCacheEnabled) + $cacheSize = $settings.MaxBranchCacheSizePercent + $configCacheSize = [System.Convert]::ToBoolean($settings.ConfigureCacheSize) + $maxCacheSize = $settings.MaxCacheSizeMB + $maxCacheSizePer = $settings.MaxCacheSizePercent + $superPeer = [System.Convert]::ToBoolean($settings.CanBeSuperPeer) + $broadPort = $settings.BroadcastPort + $httpPort = $settings.HttpPort + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + ConfigureBranchCache = $configBranchCache + EnableBranchCache = $branchCache + MaxBranchCacheSizePercent = $cacheSize + ConfigureCacheSize = $configCacheSize + MaxCacheSize = $maxCacheSize + MaxCacheSizePercent = $maxCacheSizePer + EnableSuperPeer = $superPeer + BroadcastPort = $broadPort + DownloadPort = $httpPort + ClientSettingStatus = $status + ClientType = $type + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER ConfigureBranchCache + Specifies if configure branch cache policy is enabled or disabled. + + .PARAMETER EnableBranchCache + Specifies if branch cache is enabled or disabled. + + .PARAMETER MaxBranchCacheSizePercent + Specifies the percentage of disk size maximum branch cache size. + + .PARAMETER ConfigureCacheSize + Specifies if client cache size is enabled or disabled. + + .PARAMETER MaxCacheSize + Specifies the maximum cache size by MB. + + .PARAMETER MaxCacheSizePercent + Specifies the maximum cache size percentage. + + .PARAMETER EnableSuperPeer + Specifies is peer cache source is enabled or disabled. + + .PARAMETER BroadcastPort + Specifies the port for initial network broadcast. + + .PARAMETER DownloadPort + Specifies the port for content download from peers. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [Boolean] + $ConfigureBranchCache, + + [Parameter()] + [Boolean] + $EnableBranchCache, + + [Parameter()] + [ValidateRange(1,100)] + [UInt32] + $MaxBranchCacheSizePercent, + + [Parameter()] + [Boolean] + $ConfigureCacheSize, + + [Parameter()] + [ValidateRange(1,1048576)] + [UInt32] + $MaxCacheSize, + + [Parameter()] + [ValidateRange(1,100)] + [UInt32] + $MaxCacheSizePercent, + + [Parameter()] + [Boolean] + $EnableSuperPeer, + + [Parameter()] + [UInt32] + $BroadcastPort, + + [Parameter()] + [UInt32] + $DownloadPort + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + + try + { + if ($state.ClientSettingStatus -eq 'Absent') + { + throw ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + } + + if ($state.ClientType -eq 'User') + { + throw $script:localizedData.WrongClientType + } + + if (($ConfigureBranchCache -eq $false) -and ($PSBoundParameters.ContainsKey('EnableBranchCache') -or $PSBoundParameters.ContainsKey('MaxBranchCacheSizePercent'))) + { + throw $script:localizedData.DisabledBranchwithMax + } + + if (($ConfigureCacheSize -eq $false) -and ($PSBoundParameters.ContainsKey('MaxCacheSize') -or $PSBoundParameters.ContainsKey('MaxCacheSizePercent'))) + { + throw $script:localizedData.ConfigCacheFalseSize + } + + if (($EnableSuperPeer -eq $false) -and ($PSBoundParameters.ContainsKey('BroadcastPort') -or $PSBoundParameters.ContainsKey('DownloadPort'))) + { + throw $script:localizedData.DisableSuperBroad + } + + if ($PSBoundParameters.ContainsKey('MaxCacheSizePercent') -and $ConfigureBranchCache -ne $true) + { + throw $script:localizedData.BranchMaxCache + } + + $defaultValues = @('ConfigureBranchCache','ConfigureCacheSize','EnableSuperPeer','EnableBranchCache','MaxBranchCacheSizePercent','MaxCacheSize','MaxCacheSizePercent', + 'BroadcastPort','DownloadPort') + + foreach ($param in $PSBoundParameters.GetEnumerator()) + { + if ($defaultValues -contains $param.Key) + { + if ($param.Value -ne $state[$param.Key]) + { + Write-Verbose -Message ($script:localizedData.SettingValue -f $param.Key, $param.Value) + $buildingParams += @{ + $param.Key = $param.Value + } + } + } + } + + if ($buildingParams) + { + if ($state.ClientType -eq 'Default') + { + Set-CMClientSettingClientCache -DefaultSetting @buildingParams + } + else + { + Set-CMClientSettingClientCache -Name $ClientSettingName @buildingParams + } + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER ConfigureBranchCache + Specifies if configure branch cache policy is enabled or disabled. + + .PARAMETER EnableBranchCache + Specifies if branch cache is enabled or disabled. + + .PARAMETER MaxBranchCacheSizePercent + Specifies the percentage of disk size maximum branch cache size. + + .PARAMETER ConfigureCacheSize + Specifies if client cache size is enabled or disabled. + + .PARAMETER MaxCacheSize + Specifies the maximum cache size by MB. + + .PARAMETER MaxCacheSizePercent + Specifies the maximum cache size percentage. + + .PARAMETER EnableSuperPeer + Specifies is peer cache source is enabled or disabled. + + .PARAMETER BroadcastPort + Specifies the port for initial network broadcast. + + .PARAMETER DownloadPort + Specifies the port for content download from peers. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [Boolean] + $ConfigureBranchCache, + + [Parameter()] + [Boolean] + $EnableBranchCache, + + [Parameter()] + [ValidateRange(1,100)] + [UInt32] + $MaxBranchCacheSizePercent, + + [Parameter()] + [Boolean] + $ConfigureCacheSize, + + [Parameter()] + [ValidateRange(1,1048576)] + [UInt32] + $MaxCacheSize, + + [Parameter()] + [ValidateRange(1,100)] + [UInt32] + $MaxCacheSizePercent, + + [Parameter()] + [Boolean] + $EnableSuperPeer, + + [Parameter()] + [UInt32] + $BroadcastPort, + + [Parameter()] + [UInt32] + $DownloadPort + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + $result = $true + + if ($state.ClientSettingStatus -eq 'Absent') + { + Write-Warning -Message ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + $result = $false + } + elseif ($state.ClientType -eq 'User') + { + Write-Warning -Message $script:localizedData.WrongClientType + $result = $false + } + else + { + $defaultValues = @('ConfigureBranchCache','ConfigureCacheSize','EnableSuperPeer','EnableBranchCache','MaxBranchCacheSizePercent','MaxCacheSize','MaxCacheSizePercent', + 'BroadcastPort','DownloadPort') + + if (($ConfigureBranchCache -eq $false) -and ($PSBoundParameters.ContainsKey('EnableBranchCache') -or $PSBoundParameters.ContainsKey('MaxBranchCacheSizePercent'))) + { + Write-Warning -Message $script:localizedData.DisabledBranchwithMax + $badInput = $true + } + + if (($ConfigureCacheSize -eq $false) -and ($PSBoundParameters.ContainsKey('MaxCacheSize') -or $PSBoundParameters.ContainsKey('MaxCacheSizePercent'))) + { + Write-Warning -Message $script:localizedData.ConfigCacheFalseSize + $badInput = $true + } + + if (($EnableSuperPeer -eq $false) -and ($PSBoundParameters.ContainsKey('BroadcastPort') -or $PSBoundParameters.ContainsKey('DownloadPort'))) + { + Write-Warning -Message $script:localizedData.DisableSuperBroad + $badInput = $true + } + + if ($PSBoundParameters.ContainsKey('MaxCacheSizePercent') -and $ConfigureBranchCache -ne $true) + { + Write-Warning -Message $script:localizedData.BranchMaxCache + $badInput = $true + } + + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = $defaultValues + } + + $result = Test-DscParameterState @testParams -TurnOffTypeChecking -Verbose + } + + if ($result -eq $false -or $badInput -eq $true) + { + $result = $false + } + else + { + $result = $true + } + + Write-Verbose -Message ($script:localizedData.TestState -f $result) + Set-Location -Path "$env:temp" + return $result +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettingsClientCache/DSC_CMClientSettingsClientCache.schema.mof b/source/DSCResources/DSC_CMClientSettingsClientCache/DSC_CMClientSettingsClientCache.schema.mof new file mode 100644 index 00000000..110d7383 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsClientCache/DSC_CMClientSettingsClientCache.schema.mof @@ -0,0 +1,17 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettingsClientCache")] +class DSC_CMClientSettingsClientCache : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Write, Description("Specifies if configure branch cache policy is enabled or disabled.")] Boolean ConfigureBranchCache; + [Write, Description("Specifies if branch cache is enabled or disabled.")] Boolean EnableBranchCache; + [Write, Description("Specifies the percentage of disk size maximum branch cache size.")] UInt32 MaxBranchCacheSizePercent; + [Write, Description("Specifies if client cache size is enabled or disabled.")] Boolean ConfigureCacheSize; + [Write, Description("Specifies the maximum cache size by MB.")] UInt32 MaxCacheSize; + [Write, Description("Specifies the maximum cache size percentage.")] UInt32 MaxCacheSizePercent; + [Write, Description("Specifies is peer cache source is enabled or disabled.")] Boolean EnableSuperPeer; + [Write, Description("Specifies the port for initial network broadcast.")] UInt32 BroadcastPort; + [Write, Description("Specifies the port for content download from peers.")] UInt32 DownloadPort; + [Read, Description("Specifies if the client settings policy exists.")] String ClientSettingStatus; + [Read, Description("Specifies the type of client policy setting.")] String ClientType; +}; diff --git a/source/DSCResources/DSC_CMClientSettingsClientCache/en-US/DSC_CMClientSettingsClientCache.strings.psd1 b/source/DSCResources/DSC_CMClientSettingsClientCache/en-US/DSC_CMClientSettingsClientCache.strings.psd1 new file mode 100644 index 00000000..ca9d528a --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsClientCache/en-US/DSC_CMClientSettingsClientCache.strings.psd1 @@ -0,0 +1,11 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy for client cache settings. + ClientPolicySetting = Client Policy setting {0} does not exist, and will need to be created prior to making client setting changes. + TestState = Test-TargetResource compliance check returned: {0}. + SettingValue = Setting value: {0} to {1}. + DisabledBranchwithMax = When trying to set EnableBranchCache or MaxBranchCacheSizePercent, ConfigurureBranchCache must be set to true. + ConfigCacheFalseSize = When trying to set MaxCacheSize or MaxCacheSizePercent, ConfigureCacheSize must be set to true. + DisableSuperBroad = When trying to set BroadcastPort or DownloadPort, EnableSuperPeer must be set to true. + BranchMaxCache = When setting MaxCacheSizePercent, ConfigureBranchCache must be set to true. + WrongClientType = Client Settings for Client Cache only applies to Default and Device Client settings. +'@ diff --git a/source/DSCResources/DSC_CMClientSettingsClientPolicy/DSC_CMClientSettingsClientPolicy.psm1 b/source/DSCResources/DSC_CMClientSettingsClientPolicy/DSC_CMClientSettingsClientPolicy.psm1 new file mode 100644 index 00000000..b041ed97 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsClientPolicy/DSC_CMClientSettingsClientPolicy.psm1 @@ -0,0 +1,266 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + $type = @('Default','Device','User')[$clientSetting.Type] + $settings = Get-CMClientSetting -Name $ClientSettingName -Setting ClientPolicy + + if ($settings) + { + $timeout = $settings.PolicyRequestAssignmentTimeout + $userPolicy = [System.Convert]::ToBoolean($settings.PolicyEnableUserPolicyPolling) + $internetUser = [System.Convert]::ToBoolean($settings.PolicyEnableUserPolicyOnInternet) + $multiUser = [System.Convert]::ToBoolean($settings.PolicyEnableUserPolicyOnTS) + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + PolicyPollingMins = $timeout + EnableUserPolicy = $userPolicy + EnableUserPolicyOnInternet = $internetUser + EnableUserPolicyOnTS = $multiUser + ClientSettingStatus = $status + ClientType = $type + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER PolicyPollingMins + Specifies client policy interval in minutes. + + .PARAMETER EnableUserPolicy + Specifies if user policy on clients is enabled or disabled. + + .PARAMETER EnableUserPolicyOnInternet + Specifies if user policy request from internet clients is enabled or disabled. + + .PARAMETER EnableUserPolicyOnTS + Specifies if user policy for multiple sessions is enabled or disabled. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [ValidateRange(3,1440)] + [UInt32] + $PolicyPollingMins, + + [Parameter()] + [Boolean] + $EnableUserPolicy, + + [Parameter()] + [Boolean] + $EnableUserPolicyOnInternet, + + [Parameter()] + [Boolean] + $EnableUserPolicyOnTS + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + + try + { + if ($state.ClientSettingStatus -eq 'Absent') + { + throw ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + } + + if ($state.ClientType -eq 'User') + { + throw $script:localizedData.WrongClientType + } + + $defaultValues = @('PolicyPollingMins','EnableUserPolicy','EnableUserPolicyOnInternet','EnableUserPolicyOnTS') + + foreach ($param in $PSBoundParameters.GetEnumerator()) + { + if ($defaultValues -contains $param.Key) + { + if ($param.Value -ne $state[$param.Key]) + { + Write-Verbose -Message ($script:localizedData.SettingValue -f $param.Key, $param.Value) + $buildingParams += @{ + $param.Key = $param.Value + } + } + } + } + + if ($buildingParams) + { + if ($state.ClientType -eq 'Default') + { + Set-CMClientSettingClientPolicy -DefaultSetting @buildingParams + } + else + { + Set-CMClientSettingClientPolicy -Name $ClientSettingName @buildingParams + } + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER PolicyPollingMins + Specifies client policy interval in minutes. + + .PARAMETER EnableUserPolicy + Specifies if user policy on clients is enabled or disabled. + + .PARAMETER EnableUserPolicyOnInternet + Specifies if user policy request from internet clients is enabled or disabled. + + .PARAMETER EnableUserPolicyOnTS + Specifies if user policy for multiple sessions is enabled or disabled. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [ValidateRange(3,1440)] + [UInt32] + $PolicyPollingMins, + + [Parameter()] + [Boolean] + $EnableUserPolicy, + + [Parameter()] + [Boolean] + $EnableUserPolicyOnInternet, + + [Parameter()] + [Boolean] + $EnableUserPolicyOnTS + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + $result = $true + + if ($state.ClientSettingStatus -eq 'Absent') + { + Write-Warning -Message ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + $result = $false + } + elseif ($state.ClientType -eq 'User') + { + Write-Warning -Message $script:localizedData.WrongClientType + $result = $false + } + else + { + $defaultValues = @('PolicyPollingMins','EnableUserPolicy','EnableUserPolicyOnInternet','EnableUserPolicyOnTS') + + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = $defaultValues + } + + $result = Test-DscParameterState @testParams -TurnOffTypeChecking -Verbose + } + + Write-Verbose -Message ($script:localizedData.TestState -f $result) + Set-Location -Path "$env:temp" + return $result +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettingsClientPolicy/DSC_CMClientSettingsClientPolicy.schema.mof b/source/DSCResources/DSC_CMClientSettingsClientPolicy/DSC_CMClientSettingsClientPolicy.schema.mof new file mode 100644 index 00000000..dadb9264 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsClientPolicy/DSC_CMClientSettingsClientPolicy.schema.mof @@ -0,0 +1,12 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettingsClientPolicy")] +class DSC_CMClientSettingsClientPolicy : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Write, Description("Specifies client policy interval in minutes.")] UInt32 PolicyPollingMins; + [Write, Description("Specifies if user policy on clients is enabled or disabled.")] Boolean EnableUserPolicy; + [Write, Description("Specifies if user policy request from internet clients is enabled or disabled.")] Boolean EnableUserPolicyOnInternet; + [Write, Description("Specifies if user policy for multiple sessions is enabled or disabled.")] Boolean EnableUserPolicyOnTS; + [Read, Description("Specifies if the client settings policy exists.")] String ClientSettingStatus; + [Read, Description("Specifies the type of client policy setting.")] String ClientType; +}; diff --git a/source/DSCResources/DSC_CMClientSettingsClientPolicy/en-US/DSC_CMClientSettingsClientPolicy.strings.psd1 b/source/DSCResources/DSC_CMClientSettingsClientPolicy/en-US/DSC_CMClientSettingsClientPolicy.strings.psd1 new file mode 100644 index 00000000..bf37ebeb --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsClientPolicy/en-US/DSC_CMClientSettingsClientPolicy.strings.psd1 @@ -0,0 +1,7 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy for client policy settings. + ClientPolicySetting = Client Policy Setting {0} does not exist, and will need to be created prior to making client setting changes. + TestState = Test-TargetResource compliance check returned: {0}. + SettingValue = Setting value: {0} to {1}. + WrongClientType = Client Settings for Client Policy settings only applies to Default and Device Client settings. +'@ diff --git a/source/DSCResources/DSC_CMClientSettingsCloudService/DSC_CMClientSettingsCloudService.psm1 b/source/DSCResources/DSC_CMClientSettingsCloudService/DSC_CMClientSettingsCloudService.psm1 new file mode 100644 index 00000000..043c3663 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsCloudService/DSC_CMClientSettingsCloudService.psm1 @@ -0,0 +1,264 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + $type = @('Default','Device','User')[$clientSetting.Type] + $settings = Get-CMClientSetting -Name $ClientSettingName -Setting Cloud + + if ($settings) + { + $cdp = [System.Convert]::ToBoolean($settings.AllowCloudDP) + $autoAZJoin = [System.Convert]::ToBoolean($settings.AutoAADJoin) + $cmg = [System.Convert]::ToBoolean($settings.AllowCMG) + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + AllowCloudDistributionPoint = $cdp + AutoAzureADJoin = $autoAZJoin + AllowCloudManagementGateway = $cmg + ClientSettingStatus = $status + ClientType = $type + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER AllowCloudDistributionPoint + Specifies if allow access to cloud distribution point is enabled or disabled. + + .PARAMETER AutoAzureADJoin + Specifies whether to automatically register new Windows 10 domain joined devices with + Azure Active Directory. + + .PARAMETER AllowCloudManagementGateway + Specifies if allow access to cloud management gateway is enabled or disabled. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [Boolean] + $AllowCloudDistributionPoint, + + [Parameter()] + [Boolean] + $AutoAzureADJoin, + + [Parameter()] + [Boolean] + $AllowCloudManagementGateway + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + + try + { + if ($state.ClientSettingStatus -eq 'Absent') + { + throw ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + } + + if ($state.ClientType -eq 'User') + { + $defaultValues = @('AllowCloudDistributionPoint') + if ($PSBoundParameters.ContainsKey('AutoAzureADJoin') -or + $PSBoundParameters.ContainsKey('AllowCloudManagementGateway')) + { + Write-Warning -Message $script:localizedData.DeviceSettings + } + } + else + { + $defaultValues = @('AllowCloudDistributionPoint','AutoAzureADJoin','AllowCloudManagementGateway') + } + + foreach ($param in $PSBoundParameters.GetEnumerator()) + { + if ($defaultValues -contains $param.Key) + { + if ($param.Value -ne $state[$param.Key]) + { + Write-Verbose -Message ($script:localizedData.SettingValue -f $param.Key, $param.Value) + $buildingParams += @{ + $param.Key = $param.Value + } + } + } + } + + if ($buildingParams) + { + if ($state.ClientType -eq 'Default') + { + Set-CMClientSettingCloudService -DefaultSetting @buildingParams + } + else + { + Set-CMClientSettingCloudService -Name $ClientSettingName @buildingParams + } + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER AllowCloudDistributionPoint + Specifies if allow access to cloud distribution point is enabled or disabled. + + .PARAMETER AutoAzureADJoin + Specifies whether to automatically register new Windows 10 domain joined devices with + Azure Active Directory. + + .PARAMETER AllowCloudManagementGateway + Specifies if allow access to cloud management gateway is enabled or disabled. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [Boolean] + $AllowCloudDistributionPoint, + + [Parameter()] + [Boolean] + $AutoAzureADJoin, + + [Parameter()] + [Boolean] + $AllowCloudManagementGateway + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + $result = $true + + if ($state.ClientSettingStatus -eq 'Absent') + { + Write-Warning -Message ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + $result = $false + } + else + { + if ($state.ClientType -eq 'User') + { + $defaultValues = @('AllowCloudDistributionPoint') + if ($PSBoundParameters.ContainsKey('AutoAzureADJoin') -or + $PSBoundParameters.ContainsKey('AllowCloudManagementGateway')) + { + Write-Warning -Message $script:localizedData.DeviceSettings + } + } + else + { + $defaultValues = @('AllowCloudDistributionPoint','AutoAzureADJoin','AllowCloudManagementGateway') + } + + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = $defaultValues + } + + $result = Test-DscParameterState @testParams -TurnOffTypeChecking -Verbose + } + + Write-Verbose -Message ($script:localizedData.TestState -f $result) + Set-Location -Path "$env:temp" + return $result +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettingsCloudService/DSC_CMClientSettingsCloudService.schema.mof b/source/DSCResources/DSC_CMClientSettingsCloudService/DSC_CMClientSettingsCloudService.schema.mof new file mode 100644 index 00000000..e8eebbfc --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsCloudService/DSC_CMClientSettingsCloudService.schema.mof @@ -0,0 +1,11 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettingsCloudService")] +class DSC_CMClientSettingsCloudService : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Write, Description("Specifies if allow access to cloud distribution point is enabled or disabled.")] Boolean AllowCloudDistributionPoint; + [Write, Description("Specifies whether to automatically register new Windows 10 domain joined devices with Azure Active Directory.")] Boolean AutoAzureADJoin; + [Write, Description("Specifies if allow access to cloud management gateway is enabled or disabled.")] Boolean AllowCloudManagementGateway; + [Read, Description("Specifies if the client settings policy exists.")] String ClientSettingStatus; + [Read, Description("Specifies the type of client policy setting.")] String ClientType; +}; diff --git a/source/DSCResources/DSC_CMClientSettingsCloudService/en-US/DSC_CMClientSettingsCloudService.strings.psd1 b/source/DSCResources/DSC_CMClientSettingsCloudService/en-US/DSC_CMClientSettingsCloudService.strings.psd1 new file mode 100644 index 00000000..b14b0bcf --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsCloudService/en-US/DSC_CMClientSettingsCloudService.strings.psd1 @@ -0,0 +1,7 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy for cloud services settings. + ClientPolicySetting = Client Policy Setting {0} does not exist, and will need to be created prior to making client setting changes. + TestState = Test-TargetResource compliance check returned: {0}. + SettingValue = Setting value: {0} to {1}. + DeviceSettings = AutoAzureADJoin and AllowCloudManagementGateway are default or device client policies, ignoring settings as client policy specified is User only settings. +'@ diff --git a/source/DSCResources/DSC_CMClientSettingsCompliance/DSC_CMClientSettingsCompliance.psm1 b/source/DSCResources/DSC_CMClientSettingsCompliance/DSC_CMClientSettingsCompliance.psm1 new file mode 100644 index 00000000..a10d9b9f --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsCompliance/DSC_CMClientSettingsCompliance.psm1 @@ -0,0 +1,470 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Enable + Specifies if compliance evaluation on clients is enabled or disabled. + Not used in Get +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $Enable + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + $type = @('Default','Device','User')[$clientSetting.Type] + $settings = Get-CMClientSetting -Name $ClientSettingName -Setting ComplianceSettings + + if ($settings) + { + $enabled = [System.Convert]::ToBoolean($settings.Enabled) + $userState = [System.Convert]::ToBoolean($settings.EnableUserStateManagement) + + if ($type -eq 'Default') + { + $schedule = Get-CMSchedule -ScheduleString $settings.EvaluationSchedule + } + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + Enable = $enabled + EnableUserDataAndProfile = $userState + Start = $schedule.Start + ScheduleType = $schedule.ScheduleType + DayOfWeek = $schedule.DayofWeek + MonthlyWeekOrder = $schedule.WeekOrder + DayofMonth = $schedule.MonthDay + RecurInterval = $schedule.RecurInterval + ClientSettingStatus = $status + ClientType = $type + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Enable + Specifies if compliance evaluation on clients is enabled or disabled. + + .Parameter EnableUserDataAndProfile + Specifies if user data and profiles are enabled or disabled. + + .PARAMETER Start + Specifies the start date and start time for the compliance evaluation schedule Month/Day/Year, example 1/1/2020 02:00. + + .PARAMETER ScheduleType + Specifies the schedule type for the compliance evaluation schedule. + + .PARAMETER RecurInterval + Specifies how often the ScheduleType is run. + + .PARAMETER MonthlyByWeek + Specifies week order for MonthlyByWeek schedule type. + + .PARAMETER DayOfWeek + Specifies the day of week name for MonthlyByWeek and Weekly schedules. + + .PARAMETER DayOfMonth + Specifies the day number for MonthlyByDay schedules. + Note specifying 0 sets the schedule to run the last day of the month. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $Enable, + + [Parameter()] + [Boolean] + $EnableUserDataAndProfile, + + [Parameter()] + [String] + $Start, + + [Parameter()] + [ValidateSet('MonthlyByDay','MonthlyByWeek','Weekly','Days','Hours','Minutes','None')] + [String] + $ScheduleType, + + [Parameter()] + [UInt32] + $RecurInterval, + + [Parameter()] + [ValidateSet('First','Second','Third','Fourth','Last')] + [String] + $MonthlyWeekOrder, + + [Parameter()] + [ValidateSet('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')] + [String] + $DayOfWeek, + + [Parameter()] + [ValidateRange(0,31)] + [UInt32] + $DayOfMonth + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName -Enable $Enable + $schedResult = $true + + try + { + if ($state.ClientSettingStatus -eq 'Absent') + { + throw ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + } + + if ($state.ClientType -eq 'User') + { + throw $script:localizedData.WrongClientType + } + + if ($Enable -eq $true) + { + if (($state.ClientType -eq 'Default' -and -not $PSBoundParameters.ContainsKey('ScheduleType')) -and ($PSBoundParameters.ContainsKey('Start') -or + $PSBoundParameters.ContainsKey('RecurInterval') -or $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('DayOfWeek') -or $PSBoundParameters.ContainsKey('DayOfMonth'))) + { + throw $script:localizedData.RequiredSchedule + } + + if (($state.ClientType -ne 'Default') -and ($PSBoundParameters.ContainsKey('ScheduleType') -or + $PSBoundParameters.ContainsKey('Start') -or + $PSBoundParameters.ContainsKey('RecurInterval') -or + $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('DayOfWeek') -or + $PSBoundParameters.ContainsKey('DayOfMonth'))) + { + Write-Warning -Message $script:localizedData.ScheduleDefault + } + + $defaultValues = @('Enable','EnableUserDataAndProfile') + + foreach ($param in $PSBoundParameters.GetEnumerator()) + { + if ($defaultValues -contains $param.Key) + { + if ($param.Value -ne $state[$param.Key]) + { + Write-Verbose -Message ($script:localizedData.SettingValue -f $param.Key, $param.Value) + $buildingParams += @{ + $param.Key = $param.Value + } + } + } + } + + if ($ScheduleType -and $state.ClientType -eq 'Default') + { + $valuesToValidate = @('ScheduleType','RecurInterval','MonthlyWeekOrder','DayOfWeek','DayOfMonth','Start') + foreach ($item in $valuesToValidate) + { + if ($PSBoundParameters.ContainsKey($item)) + { + $scheduleCheck += @{ + $item = $PSBoundParameters[$item] + } + } + } + + $schedResult = Test-CMSchedule @scheduleCheck -State $state + } + + if ($schedResult -eq $false) + { + $sched = Set-CMSchedule @scheduleCheck + $newSchedule = New-CMSchedule @sched + + Write-Verbose -Message $script:localizedData.NewSchedule + $buildingParams += @{ + Schedule = $newSchedule + } + } + } + elseif ($state.Enable -eq $true) + { + if ($PSBoundParameters.ContainsKey('EnableUserDataAndProfile') -or $PSBoundParameters.ContainsKey('Start') -or + $PSBoundParameters.ContainsKey('ScheduleType') -or $PSBoundParameters.ContainsKey('RecurInterval') -or + $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or $PSBoundParameters.ContainsKey('DayOfWeek') -or + $PSBoundParameters.ContainsKey('DayOfMonth')) + { + Write-Warning -Message $script:localizedData.EnableFalse + } + + $buildingParams = @{ + Enable = $false + } + } + + if ($buildingParams) + { + if ($state.ClientType -eq 'Default') + { + Set-CMClientSettingComplianceSetting -DefaultSetting @buildingParams + } + else + { + Set-CMClientSettingComplianceSetting -Name $ClientSettingName @buildingParams + } + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Enable + Specifies if compliance evaluation on clients is enabled or disabled. + + .Parameter EnableUserDataAndProfile + Specifies if user data and profiles are enabled or disabled. + + .PARAMETER Start + Specifies the start date and start time for the compliance evaluation schedule Month/Day/Year, example 1/1/2020 02:00. + + .PARAMETER ScheduleType + Specifies the schedule type for the compliance evaluation schedule. + + .PARAMETER RecurInterval + Specifies how often the ScheduleType is run. + + .PARAMETER MonthlyByWeek + Specifies week order for MonthlyByWeek schedule type. + + .PARAMETER DayOfWeek + Specifies the day of week name for MonthlyByWeek and Weekly schedules. + + .PARAMETER DayOfMonth + Specifies the day number for MonthlyByDay schedules. + Note specifying 0 sets the schedule to run the last day of the month. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $Enable, + + [Parameter()] + [Boolean] + $EnableUserDataAndProfile, + + [Parameter()] + [String] + $Start, + + [Parameter()] + [ValidateSet('MonthlyByDay','MonthlyByWeek','Weekly','Days','Hours','Minutes','None')] + [String] + $ScheduleType, + + [Parameter()] + [UInt32] + $RecurInterval, + + [Parameter()] + [ValidateSet('First','Second','Third','Fourth','Last')] + [String] + $MonthlyWeekOrder, + + [Parameter()] + [ValidateSet('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')] + [String] + $DayOfWeek, + + [Parameter()] + [ValidateRange(0,31)] + [UInt32] + $DayOfMonth + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName -Enable $Enable + $result = $true + $schedResult = $true + + if ($state.ClientSettingStatus -eq 'Absent') + { + Write-Warning -Message ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + $result = $false + } + elseif ($state.ClientType -eq 'User') + { + Write-Warning -Message $script:localizedData.WrongClientType + $result = $false + } + else + { + if ($Enable -eq $true) + { + if (($state.ClientType -eq 'Default' -and -not $PSBoundParameters.ContainsKey('ScheduleType')) -and ($PSBoundParameters.ContainsKey('Start') -or + $PSBoundParameters.ContainsKey('RecurInterval') -or $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('DayOfWeek') -or $PSBoundParameters.ContainsKey('DayOfMonth'))) + { + Write-Warning -Message $script:localizedData.RequiredSchedule + $badInput = $true + } + + if (($state.ClientType -ne 'Default') -and ($PSBoundParameters.ContainsKey('ScheduleType') -or + $PSBoundParameters.ContainsKey('Start') -or + $PSBoundParameters.ContainsKey('RecurInterval') -or + $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('DayOfWeek') -or + $PSBoundParameters.ContainsKey('DayOfMonth'))) + { + Write-Warning -Message $script:localizedData.ScheduleDefault + } + + $defaultValues = @('Enable','EnableUserDataAndProfile') + + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = $defaultValues + } + + $result = Test-DscParameterState @testParams -TurnOffTypeChecking -Verbose + + if ($ScheduleType -and $state.ClientType -eq 'Default') + { + $valuesToValidate = @('ScheduleType','RecurInterval','MonthlyWeekOrder','DayOfWeek','DayOfMonth','Start') + foreach ($item in $valuesToValidate) + { + if ($PSBoundParameters.ContainsKey($item)) + { + $scheduleCheck += @{ + $item = $PSBoundParameters[$item] + } + } + } + + $schedResult = Test-CMSchedule @scheduleCheck -State $state + } + } + else + { + if ($PSBoundParameters.ContainsKey('EnableUserDataAndProfile') -or $PSBoundParameters.ContainsKey('Start') -or + $PSBoundParameters.ContainsKey('ScheduleType') -or $PSBoundParameters.ContainsKey('RecurInterval') -or + $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or $PSBoundParameters.ContainsKey('DayOfWeek') -or + $PSBoundParameters.ContainsKey('DayOfMonth')) + { + Write-Warning -Message $script:localizedData.EnableFalse + } + + if ($state.Enable -eq $true) + { + Write-Verbose -Message $script:localizedData.TestDisabled + $result = $false + } + } + } + + if ($result -eq $false -or $schedResult -eq $false -or $badInput -eq $true) + { + $return = $false + } + else + { + $return = $true + } + + Write-Verbose -Message ($script:localizedData.TestState -f $return) + Set-Location -Path "$env:temp" + return $return +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettingsCompliance/DSC_CMClientSettingsCompliance.schema.mof b/source/DSCResources/DSC_CMClientSettingsCompliance/DSC_CMClientSettingsCompliance.schema.mof new file mode 100644 index 00000000..97b0b0ac --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsCompliance/DSC_CMClientSettingsCompliance.schema.mof @@ -0,0 +1,16 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettingsCompliance")] +class DSC_CMClientSettingsCompliance : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Required, Description("Specifies if compliance evaluation on clients is enabled or disabled.")] Boolean Enable; + [Write, Description("Specifies if user data and profiles are enabled or disabled.")] Boolean EnableUserDataAndProfile; + [Write, Description("Specifies the start date and start time for the compliance evaluation schedule Month/Day/Year, example 1/1/2020 02:00.")] String Start; + [Write, Description("Specifies the schedule type for the compliance evaluation schedule."), ValueMap{"MonthlyByDay","MonthlyByWeek","Weekly","Days","Hours","Minutes","None"}, Values{"MonthlyByDay","MonthlyByWeek","Weekly","Days","Hours","Minutes","None"}] String ScheduleType; + [Write, Description("Specifies how often the ScheduleType is run.")] UInt32 RecurInterval; + [Write, Description("Specifies week order for MonthlyByWeek schedule type."), ValueMap{"First","Second","Third","Fourth","Last"}, Values{"First","Second","Third","Fourth","Last"}] String MonthlyWeekOrder; + [Write, Description("Specifies the day of week name for MonthlyByWeek and Weekly schedules."), ValueMap{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}, Values{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}] String DayOfWeek; + [Write, Description("Specifies the day number for MonthlyByDay schedules.")] UInt32 DayOfMonth; + [Read, Description("Specifies if the client settings policy exists.")] String ClientSettingStatus; + [Read, Description("Specifies the type of client policy setting.")] String ClientType; +}; diff --git a/source/DSCResources/DSC_CMClientSettingsCompliance/en-US/DSC_CMClientSettingsCompliance.strings.psd1 b/source/DSCResources/DSC_CMClientSettingsCompliance/en-US/DSC_CMClientSettingsCompliance.strings.psd1 new file mode 100644 index 00000000..755ae1c6 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsCompliance/en-US/DSC_CMClientSettingsCompliance.strings.psd1 @@ -0,0 +1,12 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy for compliance settings. + ClientPolicySetting = Client Policy Setting {0} does not exist, and will need to be created prior to making client setting changes. + TestState = Test-TargetResource compliance check returned: {0}. + TestDisabled = Enabled currently is enabled and should be disabled. + SettingValue = Setting value: {0} to {1}. + NewSchedule = Modifying compliance evaluation schedule. + RequiredSchedule = In order to create a schedule you must specify ScheduleType. + ScheduleDefault = Schedule may only be specified when setting the default client, ignoring schedule. + WrongClientType = Client Settings for Compliance settings only applies to Default and Device client settings. + EnableFalse = In order to set a schedule or EnableUserDataAndProfile, Enable must be set to true, ignoring settings. +'@ diff --git a/source/DSCResources/DSC_CMClientSettingsComputerAgent/DSC_CMClientSettingsComputerAgent.psm1 b/source/DSCResources/DSC_CMClientSettingsComputerAgent/DSC_CMClientSettingsComputerAgent.psm1 new file mode 100644 index 00000000..184a70fa --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsComputerAgent/DSC_CMClientSettingsComputerAgent.psm1 @@ -0,0 +1,437 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + $type = @('Default','Device','User')[$clientSetting.Type] + $settings = Get-CMClientSetting -Name $ClientSettingName -Setting ComputerAgent + + if ($settings) + { + $initialReminder = $settings.ReminderInterval + $interimReminder = $settings.DayReminderInterval + $finalReminder = $settings.HourReminderInterval + $titleBranding = $settings.BrandingTitle + $useSoftCenter = [System.Convert]::ToBoolean($settings.UseNewSoftwareCenter) + $healthAttest = [System.Convert]::ToBoolean($settings.EnableHealthAttestation) + $onPremHealth = [System.Convert]::ToBoolean($settings.UseOnPremHAService) + $install = [UInt32]$settings.InstallRestriction + $restrictInstall = @('AllUsers','OnlyAdministrators','','OnlyAdministratorsAndPrimaryUsers','NoUsers')[$settings.InstallRestriction] + $bitLocker = @('Never','Always')[$settings.SuspendBitLocker] + $thirdParty = @('No','Yes')[$settings.EnableThirdPartyOrchestration] + $psExecut = @('AllSigned','Bypass','Restricted')[$settings.PowerShellExecutionPolicy] + $notification = [System.Convert]::ToBoolean($settings.DisplayNewProgramNotification) + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + InitialReminderHr = $initialReminder + InterimReminderHr = $interimReminder + FinalReminderMins = $finalReminder + BrandingTitle = $titleBranding + UseNewSoftwareCenter = $useSoftCenter + EnableHealthAttestation = $healthAttest + UseOnPremisesHealthAttestation = $onPremHealth + InstallRestriction = $restrictInstall + SuspendBitLocker = $bitLocker + EnableThirdPartyOrchestration = $thirdParty + PowerShellExecutionPolicy = $psExecut + DisplayNewProgramNotification = $notification + ClientSettingStatus = $status + ClientType = $type + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER InitialReminderHr + Specifies reminder, in hours, for deployment deadlines greater than 24 hours. + + .PARAMETER InterimReminderHr + Specifies reminder, in hours, for deployment deadlines less than 24 hours. + + .PARAMETER FinalReminderMins + Specifies reminder, in minutes, for deployment deadlines less than 1 hours. + + .PARAMETER BrandingTitle + Specifies the organizational name displayed in software center. + + .PARAMETER UseNewSoftwareCenter + Specifies if new software center is enabled or disabled. + + .PARAMETER EnableHealthAttestation + Specifies if communication with the Health Attestation service is enabled or disabled. + + .PARAMETER UseOnPremisesHealthAttestation + Specifies if the on-premises health service is enabled or disabled. + + .PARAMETER InstallRestriction + Specifies the install permissions. + + .PARAMETER SuspendBitLocker + Specifies the suspend BitLocker PIN entry on restart. + + .PARAMETER EnableThirdPartyOrchestration + Specifies if additional software manages the deployment of applications and updates. + + .PARAMETER PowerShellExecutionPolicy + Specifies powershell execution policy settings. + + .PARAMETER DisplayNewProgramNotification + Specifies if notifications are shown for new deployments. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [ValidateRange(1,999)] + [UInt32] + $InitialReminderHr, + + [Parameter()] + [ValidateRange(1,24)] + [UInt32] + $InterimReminderHr, + + [Parameter()] + [ValidateRange(5,25)] + [UInt32] + $FinalReminderMins, + + [Parameter()] + [String] + $BrandingTitle, + + [Parameter()] + [Boolean] + $UseNewSoftwareCenter, + + [Parameter()] + [Boolean] + $EnableHealthAttestation, + + [Parameter()] + [Boolean] + $UseOnPremisesHealthAttestation, + + [Parameter()] + [ValidateSet('AllUsers','OnlyAdministrators','OnlyAdministratorsAndPrimaryUsers','NoUsers')] + [String] + $InstallRestriction, + + [Parameter()] + [ValidateSet('Never','Always')] + [String] + $SuspendBitLocker, + + [Parameter()] + [ValidateSet('No','Yes')] + [String] + $EnableThirdPartyOrchestration, + + [Parameter()] + [ValidateSet('AllSigned','Bypass','Restricted')] + [String] + $PowerShellExecutionPolicy, + + [Parameter()] + [Boolean] + $DisplayNewProgramNotification + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + + try + { + if ($state.ClientSettingStatus -eq 'Absent') + { + throw ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + } + + if ($state.ClientType -eq 'User') + { + throw $script:localizedData.WrongClientType + } + + if ($PSBoundParameters.ContainsKey('UseOnPremisesHealthAttestation') -and $EnableHealthAttestation -ne $true) + { + Write-Warning -Message $script:localizedData.HealthAttestMsg + $defaultValues = @('InitialReminderHr','InterimReminderHr','FinalReminderMins','BrandingTitle','UseNewSoftwareCenter','EnableHealthAttestation', + 'InstallRestriction','SuspendBitLocker','EnableThirdPartyOrchestration','PowerShellExecutionPolicy','DisplayNewProgramNotification') + } + else + { + $defaultValues = @('InitialReminderHr','InterimReminderHr','FinalReminderMins','BrandingTitle','UseNewSoftwareCenter','EnableHealthAttestation', + 'UseOnPremisesHealthAttestation','InstallRestriction','SuspendBitLocker','EnableThirdPartyOrchestration','PowerShellExecutionPolicy', + 'DisplayNewProgramNotification') + } + + foreach ($param in $PSBoundParameters.GetEnumerator()) + { + if ($defaultValues -contains $param.Key) + { + if ($param.Value -ne $state[$param.Key]) + { + Write-Verbose -Message ($script:localizedData.SettingValue -f $param.Key, $param.Value) + $buildingParams += @{ + $param.Key = $param.Value + } + } + } + } + + if ($buildingParams) + { + if ($buildingParams.ContainsKey('UseOnPremisesHealthAttestation') -and + -not $buildingParams.ContainsKey('EnableHealthAttestation')) + { + $buildingParams += @{ + EnableHealthAttestation = $EnableHealthAttestation + } + } + + if ($state.ClientType -eq 'Default') + { + Set-CMClientSettingComputerAgent -DefaultSetting @buildingParams + } + else + { + Set-CMClientSettingComputerAgent -Name $ClientSettingName @buildingParams + } + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER InitialReminderHr + Specifies reminder, in hours, for deployment deadlines greater than 24 hours. + + .PARAMETER InterimReminderHr + Specifies reminder, in hours, for deployment deadlines less than 24 hours. + + .PARAMETER FinalReminderMins + Specifies reminder, in minutes, for deployment deadlines less than 1 hours. + + .PARAMETER BrandingTitle + Specifies the organizational name displayed in software center. + + .PARAMETER UseNewSoftwareCenter + Specifies if new software center is enabled or disabled. + + .PARAMETER EnableHealthAttestation + Specifies if communication with the Health Attestation service is enabled or disabled. + + .PARAMETER UseOnPremisesHealthAttestation + Specifies if the on-premises health service is enabled or disabled. + + .PARAMETER InstallRestriction + Specifies the install permissions. + + .PARAMETER SuspendBitLocker + Specifies the suspend BitLocker PIN entry on restart. + + .PARAMETER EnableThirdPartyOrchestration + Specifies if additional software manages the deployment of applications and updates. + + .PARAMETER PowerShellExecutionPolicy + Specifies powershell execution policy settings. + + .PARAMETER DisplayNewProgramNotification + Specifies if notifications are shown for new deployments. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [ValidateRange(1,999)] + [UInt32] + $InitialReminderHr, + + [Parameter()] + [ValidateRange(1,24)] + [UInt32] + $InterimReminderHr, + + [Parameter()] + [ValidateRange(5,25)] + [UInt32] + $FinalReminderMins, + + [Parameter()] + [String] + $BrandingTitle, + + [Parameter()] + [Boolean] + $UseNewSoftwareCenter, + + [Parameter()] + [Boolean] + $EnableHealthAttestation, + + [Parameter()] + [Boolean] + $UseOnPremisesHealthAttestation, + + [Parameter()] + [ValidateSet('AllUsers','OnlyAdministrators','OnlyAdministratorsAndPrimaryUsers','NoUsers')] + [String] + $InstallRestriction, + + [Parameter()] + [ValidateSet('Never','Always')] + [String] + $SuspendBitLocker, + + [Parameter()] + [ValidateSet('No','Yes')] + [String] + $EnableThirdPartyOrchestration, + + [Parameter()] + [ValidateSet('AllSigned','Bypass','Restricted')] + [String] + $PowerShellExecutionPolicy, + + [Parameter()] + [Boolean] + $DisplayNewProgramNotification + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + $result = $true + + if ($state.ClientSettingStatus -eq 'Absent') + { + Write-Warning -Message ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + $result = $false + } + elseif ($state.ClientType -eq 'User') + { + Write-Warning -Message $script:localizedData.WrongClientType + $result = $false + } + else + { + if ($PSBoundParameters.ContainsKey('UseOnPremisesHealthAttestation') -and $EnableHealthAttestation -ne $true) + { + Write-Warning -Message $script:localizedData.HealthAttestMsg + $defaultValues = @('InitialReminderHr','InterimReminderHr','FinalReminderMins','BrandingTitle','UseNewSoftwareCenter','EnableHealthAttestation', + 'InstallRestriction','SuspendBitLocker','EnableThirdPartyOrchestration','PowerShellExecutionPolicy','DisplayNewProgramNotification') + } + else + { + $defaultValues = @('InitialReminderHr','InterimReminderHr','FinalReminderMins','BrandingTitle','UseNewSoftwareCenter','EnableHealthAttestation', + 'UseOnPremisesHealthAttestation','InstallRestriction','SuspendBitLocker','EnableThirdPartyOrchestration','PowerShellExecutionPolicy', + 'DisplayNewProgramNotification') + } + + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = $defaultValues + } + + $result = Test-DscParameterState @testParams -TurnOffTypeChecking -Verbose + } + + Write-Verbose -Message ($script:localizedData.TestState -f $result) + Set-Location -Path "$env:temp" + return $result +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettingsComputerAgent/DSC_CMClientSettingsComputerAgent.schema.mof b/source/DSCResources/DSC_CMClientSettingsComputerAgent/DSC_CMClientSettingsComputerAgent.schema.mof new file mode 100644 index 00000000..e51c0725 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsComputerAgent/DSC_CMClientSettingsComputerAgent.schema.mof @@ -0,0 +1,20 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettingsComputerAgent")] +class DSC_CMClientSettingsComputerAgent : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Write, Description("Specifies reminder, in hours, for deployment deadlines greater than 24 hours.")] UInt32 InitialReminderHr; + [Write, Description("Specifies reminder, in hours, for deployment deadlines less than 24 hours.")] UInt32 InterimReminderHr; + [Write, Description("Specifies reminder, in minutes, for deployment deadlines less than 1 hours.")] UInt32 FinalReminderMins; + [Write, Description("Specifies the organizational name displayed in software center.")] String BrandingTitle; + [Write, Description("Specifies if the new software center is enabled or disabled.")] Boolean UseNewSoftwareCenter; + [Write, Description("Specifies if communication with the Health Attestation service is enabled or disabled.")] Boolean EnableHealthAttestation; + [Write, Description("Specifies if the on-premises health service is enabled or disabled.")] Boolean UseOnPremisesHealthAttestation; + [Write, Description("Specifies the install permissions."), ValueMap{"AllUsers","OnlyAdministrators","OnlyAdministratorsAndPrimaryUsers","NoUsers"}, Values{"AllUsers","OnlyAdministrators","OnlyAdministratorsAndPrimaryUsers","NoUsers"}] String InstallRestriction; + [Write, Description("Specifies the suspend BitLocker PIN entry on restart."), ValueMap{"Never","Always"}, Values{"Never","Always"}] String SuspendBitLocker; + [Write, Description("Specifies if additional software manages the deployment of applications and updates."), ValueMap{"No","Yes"}, Values{"No","Yes"}] String EnableThirdPartyOrchestration; + [Write, Description("Specifies powershell execution policy settings."), ValueMap{"AllSigned","Bypass","Restricted"}, Values{"AllSigned","Bypass","Restricted"}] String PowerShellExecutionPolicy; + [Write, Description("Specifies if notifications are shown for new deployments.")] Boolean DisplayNewProgramNotification; + [Read, Description("Specifies if the client settings policy exists.")] String ClientSettingStatus; + [Read, Description("Specifies the type of client policy setting.")] String ClientType; +}; diff --git a/source/DSCResources/DSC_CMClientSettingsComputerAgent/en-US/DSC_CMClientSettingsComputerAgent.strings.psd1 b/source/DSCResources/DSC_CMClientSettingsComputerAgent/en-US/DSC_CMClientSettingsComputerAgent.strings.psd1 new file mode 100644 index 00000000..7c9b4ab5 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsComputerAgent/en-US/DSC_CMClientSettingsComputerAgent.strings.psd1 @@ -0,0 +1,8 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy for computer agent settings. + ClientPolicySetting = Client Policy setting {0} does not exist, and will need to be created prior to making client setting changes. + TestState = Test-TargetResource compliance check returned: {0}. + SettingValue = Setting value: {0} to {1}. + WrongClientType = Client Settings for software update only applies to Default and Device Client settings. + HealthAttestMsg = UseOnPremiseHealthAttestation can only be specified if EnableHeathAttestation is set to true, ignoring setting. +'@ diff --git a/source/DSCResources/DSC_CMClientSettingsDelivery/DSC_CMClientSettingsDelivery.psm1 b/source/DSCResources/DSC_CMClientSettingsDelivery/DSC_CMClientSettingsDelivery.psm1 new file mode 100644 index 00000000..7a6d41f2 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsDelivery/DSC_CMClientSettingsDelivery.psm1 @@ -0,0 +1,206 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + $type = @('Default','Device','User')[$clientSetting.Type] + $settings = Get-CMClientSetting -Name $ClientSettingName -Setting DeliveryOptimization + + if ($settings) + { + $deliveryOpt = [System.Convert]::ToBoolean($settings.EnableWindowsDO) + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + Enable = $deliveryOpt + ClientSettingStatus = $status + ClientType = $type + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER Enable + Specifies if use Configuration Manager Boundary Groups for Delivery Optimization Group ID is enabled or disabled. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [Boolean] + $Enable + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + + try + { + if ($state.ClientSettingStatus -eq 'Absent') + { + throw ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + } + + if ($state.ClientType -eq 'User') + { + throw $script:localizedData.WrongClientType + } + + if ($Enable -ne $state.Enable) + { + Write-Verbose -Message ($script:localizedData.SettingValue -f $state.Enable, $Enable) + $buildingParams += @{ + Enable = $Enable + } + } + + if ($buildingParams) + { + if ($state.ClientType -eq 'Default') + { + Set-CMClientSettingDeliveryOptimization -DefaultSetting @buildingParams + } + else + { + Set-CMClientSettingDeliveryOptimization -Name $ClientSettingName @buildingParams + } + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER Enable + Specifies if use Configuration Manager Boundary Groups for Delivery Optimization Group ID is enabled or disabled. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [Boolean] + $Enable + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + $result = $true + + if ($state.ClientSettingStatus -eq 'Absent') + { + Write-Warning -Message ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + $result = $false + } + elseif ($state.ClientType -eq 'User') + { + Write-Warning -Message $script:localizedData.WrongClientType + $result = $false + } + else + { + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = @('Enable') + } + + $result = Test-DscParameterState @testParams -TurnOffTypeChecking -Verbose + } + + Write-Verbose -Message ($script:localizedData.TestState -f $result) + Set-Location -Path "$env:temp" + return $result +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettingsDelivery/DSC_CMClientSettingsDelivery.schema.mof b/source/DSCResources/DSC_CMClientSettingsDelivery/DSC_CMClientSettingsDelivery.schema.mof new file mode 100644 index 00000000..64e7e64b --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsDelivery/DSC_CMClientSettingsDelivery.schema.mof @@ -0,0 +1,9 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettingsDelivery")] +class DSC_CMClientSettingsDelivery : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Write, Description("Specifies if use Configuration Manager Boundary Groups for Delivery Optimization Group ID is enabled or disabled.")] Boolean Enable; + [Read, Description("Specifies if the client settings policy exists.")] String ClientSettingStatus; + [Read, Description("Specifies the type of client policy setting.")] String ClientType; +}; diff --git a/source/DSCResources/DSC_CMClientSettingsDelivery/en-US/DSC_CMClientSettingsDelivery.strings.psd1 b/source/DSCResources/DSC_CMClientSettingsDelivery/en-US/DSC_CMClientSettingsDelivery.strings.psd1 new file mode 100644 index 00000000..8be64d7e --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsDelivery/en-US/DSC_CMClientSettingsDelivery.strings.psd1 @@ -0,0 +1,7 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy for delivery optimization settings. + ClientPolicySetting = Client Policy Setting {0} does not exist, and will need to be created prior to making client setting changes. + TestState = Test-TargetResource compliance check returned: {0}. + SettingValue = Setting Enable from: {0} to {1}. + WrongClientType = Client Settings for Delivery Optimization only applies to Default and Device Client settings. +'@ diff --git a/source/DSCResources/DSC_CMClientSettingsHardware/DSC_CMClientSettingsHardware.psm1 b/source/DSCResources/DSC_CMClientSettingsHardware/DSC_CMClientSettingsHardware.psm1 new file mode 100644 index 00000000..e9581a9d --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsHardware/DSC_CMClientSettingsHardware.psm1 @@ -0,0 +1,524 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Enable + Specifies if compliance evaluation on clients is enabled or disabled. + Not used in Get +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $Enable + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + $type = @('Default','Device','User')[$clientSetting.Type] + $settings = Get-CMClientSetting -Name $ClientSettingName -Setting HardwareInventory + + if ($settings) + { + $enabled = [System.Convert]::ToBoolean($settings.Enabled) + + if ($enabled -eq $true) + { + $randomDelay = $settings.MaxRandomDelayMinutes + $schedule = Get-CMSchedule -ScheduleString $settings.Schedule + + if ($type -eq 'Default') + { + $thirdParty = $settings.Max3rdPartyMIFSize + $mifFile = switch ($settings.MIFCollection) + { + '0' { 'None' } + '4' { 'CollectNoIdMifFile' } + '8' { 'CollectIdMifFile' } + '12' { 'CollectIdMifAndNoIdMifFile' } + } + } + } + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + Enable = $enabled + Start = $schedule.Start + ScheduleType = $schedule.ScheduleType + DayOfWeek = $schedule.DayofWeek + MonthlyWeekOrder = $schedule.WeekOrder + DayofMonth = $schedule.MonthDay + RecurInterval = $schedule.RecurInterval + MaxRandomDelayMins = $randomDelay + CollectMifFile = $mifFile + MaxThirdPartyMifSize = $thirdParty + ClientSettingStatus = $status + ClientType = $type + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Enable + Specifies if hardware inventory for clients is enabled or disabled. + + .Parameter MaxRandomDelayMins + Specifies the maximum random delay in minutes. + + .PARAMETER Start + Specifies the start date and start time for the hardware inventory schedule Month/Day/Year, example 1/1/2020 02:00. + + .PARAMETER ScheduleType + Specifies the schedule type for the hardware inventory schedule. + + .PARAMETER RecurInterval + Specifies how often the ScheduleType is run. + + .PARAMETER MonthlyByWeek + Specifies week order for MonthlyByWeek schedule type. + + .PARAMETER DayOfWeek + Specifies the day of week name for MonthlyByWeek and Weekly schedules. + + .PARAMETER DayOfMonth + Specifies the day number for MonthlyByDay schedules. + Note specifying 0 sets the schedule to run the last day of the month. + + .Parameter CollectMifFile + Specifies the collected MIF files. + + .Parameter MaxThirdPartyMifSize + Specifies the maximum custom MIF file size in KB. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $Enable, + + [Parameter()] + [ValidateRange(0,480)] + [UInt32] + $MaxRandomDelayMins, + + [Parameter()] + [String] + $Start, + + [Parameter()] + [ValidateSet('MonthlyByDay','MonthlyByWeek','Weekly','Days','Hours','Minutes','None')] + [String] + $ScheduleType, + + [Parameter()] + [UInt32] + $RecurInterval, + + [Parameter()] + [ValidateSet('First','Second','Third','Fourth','Last')] + [String] + $MonthlyWeekOrder, + + [Parameter()] + [ValidateSet('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')] + [String] + $DayOfWeek, + + [Parameter()] + [ValidateRange(0,31)] + [UInt32] + $DayOfMonth, + + [Parameter()] + [ValidateSet('None','CollectNoIdMifFile','CollectIdMifFile','CollectIdMifAndNoIdMifFile')] + [String] + $CollectMifFile, + + [Parameter()] + [ValidateRange(1,5120)] + [UInt32] + $MaxThirdPartyMifSize + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName -Enable $Enable + $schedResult = $true + + try + { + if ($state.ClientSettingStatus -eq 'Absent') + { + throw ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + } + + if ($state.ClientType -eq 'User') + { + throw $script:localizedData.WrongClientType + } + + if ($Enable -eq $true) + { + if ((-not $PSBoundParameters.ContainsKey('ScheduleType')) -and ($PSBoundParameters.ContainsKey('Start') -or + $PSBoundParameters.ContainsKey('RecurInterval') -or $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('DayOfWeek') -or $PSBoundParameters.ContainsKey('DayOfMonth'))) + { + throw $script:localizedData.RequiredSchedule + } + + if ($state.ClientType -eq 'Default') + { + $defaultValues = @('Enable','MaxRandomDelayMins','CollectMifFile','MaxThirdPartyMifSize') + } + else + { + if ($PSBoundParameters.ContainsKey('CollectMifFile') -or $PSBoundParameters.ContainsKey('MaxThirdPartyMifSize')) + { + Write-Warning -Message $script:localizedData.DeviceIgnore + } + + $defaultValues = @('Enable','MaxRandomDelayMins') + } + + foreach ($param in $PSBoundParameters.GetEnumerator()) + { + if ($defaultValues -contains $param.Key) + { + if ($param.Value -ne $state[$param.Key]) + { + Write-Verbose -Message ($script:localizedData.SettingValue -f $param.Key, $param.Value) + $buildingParams += @{ + $param.Key = $param.Value + } + } + } + } + + if ($ScheduleType) + { + $valuesToValidate = @('ScheduleType','RecurInterval','MonthlyWeekOrder','DayOfWeek','DayOfMonth','Start') + foreach ($item in $valuesToValidate) + { + if ($PSBoundParameters.ContainsKey($item)) + { + $scheduleCheck += @{ + $item = $PSBoundParameters[$item] + } + } + } + + $schedResult = Test-CMSchedule @scheduleCheck -State $state + } + + if ($schedResult -eq $false) + { + $sched = Set-CMSchedule @scheduleCheck + $newSchedule = New-CMSchedule @sched + + Write-Verbose -Message $script:localizedData.NewSchedule + $buildingParams += @{ + Schedule = $newSchedule + } + } + } + elseif ($state.Enable -eq $true) + { + if ($PSBoundParameters.ContainsKey('MaxRandomDelayMins') -or $PSBoundParameters.ContainsKey('Start') -or + $PSBoundParameters.ContainsKey('ScheduleType') -or $PSBoundParameters.ContainsKey('RecurInterval') -or + $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or $PSBoundParameters.ContainsKey('DayOfWeek') -or + $PSBoundParameters.ContainsKey('DayOfMonth') -or $PSBoundParameters.ContainsKey('CollectMifFile') -or + $PSBoundParameters.ContainsKey('MaxThirdPartyMifSize')) + { + Write-Warning -Message $script:localizedData.DisableIgnore + } + + $buildingParams = @{ + Enable = $false + } + } + + if ($buildingParams) + { + if ($state.ClientType -eq 'Default') + { + Set-CMClientSettingHardwareInventory -DefaultSetting @buildingParams + } + else + { + Set-CMClientSettingHardwareInventory -Name $ClientSettingName @buildingParams + } + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Enable + Specifies if hardware inventory for clients is enabled or disabled. + + .Parameter MaxRandomDelayMins + Specifies the maximum random delay in minutes. + + .PARAMETER Start + Specifies the start date and start time for the hardware inventory schedule Month/Day/Year, example 1/1/2020 02:00. + + .PARAMETER ScheduleType + Specifies the schedule type for the hardware inventory schedule. + + .PARAMETER RecurInterval + Specifies how often the ScheduleType is run. + + .PARAMETER MonthlyByWeek + Specifies week order for MonthlyByWeek schedule type. + + .PARAMETER DayOfWeek + Specifies the day of week name for MonthlyByWeek and Weekly schedules. + + .PARAMETER DayOfMonth + Specifies the day number for MonthlyByDay schedules. + Note specifying 0 sets the schedule to run the last day of the month. + + .Parameter CollectMifFile + Specifies the collected MIF files. + + .Parameter MaxThirdPartyMifSize + Specifies the maximum custom MIF file size in KB. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $Enable, + + [Parameter()] + [ValidateRange(0,480)] + [UInt32] + $MaxRandomDelayMins, + + [Parameter()] + [String] + $Start, + + [Parameter()] + [ValidateSet('MonthlyByDay','MonthlyByWeek','Weekly','Days','Hours','Minutes','None')] + [String] + $ScheduleType, + + [Parameter()] + [UInt32] + $RecurInterval, + + [Parameter()] + [ValidateSet('First','Second','Third','Fourth','Last')] + [String] + $MonthlyWeekOrder, + + [Parameter()] + [ValidateSet('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')] + [String] + $DayOfWeek, + + [Parameter()] + [ValidateRange(0,31)] + [UInt32] + $DayOfMonth, + + [Parameter()] + [ValidateSet('None','CollectNoIdMifFile','CollectIdMifFile','CollectIdMifAndNoIdMifFile')] + [String] + $CollectMifFile, + + [Parameter()] + [ValidateRange(1,5120)] + [UInt32] + $MaxThirdPartyMifSize + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName -Enable $Enable + $result = $true + $schedResult = $true + + if ($state.ClientSettingStatus -eq 'Absent') + { + Write-Warning -Message ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + $result = $false + } + elseif ($state.ClientType -eq 'User') + { + Write-Warning -Message $script:localizedData.WrongClientType + $result = $false + } + else + { + if ($Enable -eq $true) + { + if ((-not $PSBoundParameters.ContainsKey('ScheduleType')) -and ($PSBoundParameters.ContainsKey('Start') -or + $PSBoundParameters.ContainsKey('RecurInterval') -or $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('DayOfWeek') -or $PSBoundParameters.ContainsKey('DayOfMonth'))) + { + Write-Warning -Message $script:localizedData.RequiredSchedule + $badInput = $true + } + + if ($state.ClientType -eq 'Default') + { + $defaultValues = @('Enable','MaxRandomDelayMins','CollectMifFile','MaxThirdPartyMifSize') + } + else + { + if ($PSBoundParameters.ContainsKey('CollectMifFile') -or $PSBoundParameters.ContainsKey('MaxThirdPartyMifSize')) + { + Write-Warning -Message $script:localizedData.DeviceIgnore + } + + $defaultValues = @('Enable','MaxRandomDelayMins') + } + + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = $defaultValues + } + + $result = Test-DscParameterState @testParams -TurnOffTypeChecking -Verbose + + if ($ScheduleType) + { + $valuesToValidate = @('ScheduleType','RecurInterval','MonthlyWeekOrder','DayOfWeek','DayOfMonth','Start') + foreach ($item in $valuesToValidate) + { + if ($PSBoundParameters.ContainsKey($item)) + { + $scheduleCheck += @{ + $item = $PSBoundParameters[$item] + } + } + } + + $schedResult = Test-CMSchedule @scheduleCheck -State $state + } + } + else + { + if ($PSBoundParameters.ContainsKey('MaxRandomDelayMins') -or $PSBoundParameters.ContainsKey('Start') -or + $PSBoundParameters.ContainsKey('ScheduleType') -or $PSBoundParameters.ContainsKey('RecurInterval') -or + $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or $PSBoundParameters.ContainsKey('DayOfWeek') -or + $PSBoundParameters.ContainsKey('DayOfMonth') -or $PSBoundParameters.ContainsKey('CollectMifFile') -or + $PSBoundParameters.ContainsKey('MaxThirdPartyMifSize')) + { + Write-Warning -Message $script:localizedData.DisableIgnore + } + + if ($state.Enable -eq $true) + { + Write-Verbose -Message $script:localizedData.TestDisabled + $result = $false + } + } + } + + if ($result -eq $false -or $schedResult -eq $false -or $badInput -eq $true) + { + $return = $false + } + else + { + $return = $true + } + + Write-Verbose -Message ($script:localizedData.TestState -f $return) + Set-Location -Path "$env:temp" + return $return +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettingsHardware/DSC_CMClientSettingsHardware.schema.mof b/source/DSCResources/DSC_CMClientSettingsHardware/DSC_CMClientSettingsHardware.schema.mof new file mode 100644 index 00000000..d449a076 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsHardware/DSC_CMClientSettingsHardware.schema.mof @@ -0,0 +1,18 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettingsHardware")] +class DSC_CMClientSettingsHardware : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Required, Description("Specifies if hardware inventory for clients is enabled or disabled.")] Boolean Enable; + [Write, Description("Specifies the maximum random delay in minutes.")] UInt32 MaxRandomDelayMins; + [Write, Description("Specifies the start date and start time for the hardware inventory schedule Month/Day/Year, example 1/1/2020 02:00.")] String Start; + [Write, Description("Specifies the schedule type for the hardware inventory schedule."), ValueMap{"MonthlyByDay","MonthlyByWeek","Weekly","Days","Hours","Minutes","None"}, Values{"MonthlyByDay","MonthlyByWeek","Weekly","Days","Hours","Minutes","None"}] String ScheduleType; + [Write, Description("Specifies how often the ScheduleType is run.")] UInt32 RecurInterval; + [Write, Description("Specifies week order for MonthlyByWeek schedule type."), ValueMap{"First","Second","Third","Fourth","Last"}, Values{"First","Second","Third","Fourth","Last"}] String MonthlyWeekOrder; + [Write, Description("Specifies the day of week name for MonthlyByWeek and Weekly schedules."), ValueMap{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}, Values{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}] String DayOfWeek; + [Write, Description("Specifies the day number for MonthlyByDay schedules.")] UInt32 DayOfMonth; + [Write, Description("Specifies the collected MIF files."), ValueMap{"None","CollectNoIdMifFile","CollectIdMifFile","CollectIdMifAndNoIdMifFile"}, Values{"None","CollectNoIdMifFile","CollectIdMifFile","CollectIdMifAndNoIdMifFile"}] String CollectMifFile; + [Write, Description("Specifies the maximum custom MIF file size in KB.")] UInt32 MaxThirdPartyMifSize; + [Read, Description("Specifies if the client settings policy exists.")] String ClientSettingStatus; + [Read, Description("Specifies the type of client policy setting.")] String ClientType; +}; diff --git a/source/DSCResources/DSC_CMClientSettingsHardware/en-US/DSC_CMClientSettingsHardware.strings.psd1 b/source/DSCResources/DSC_CMClientSettingsHardware/en-US/DSC_CMClientSettingsHardware.strings.psd1 new file mode 100644 index 00000000..1e2f4b50 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsHardware/en-US/DSC_CMClientSettingsHardware.strings.psd1 @@ -0,0 +1,12 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy for hardware inventory. + ClientPolicySetting = Client Policy Setting {0} does not exist, and will need to be created prior to making client setting changes. + TestState = Test-TargetResource compliance check returned: {0}. + TestDisabled = Enabled currently is enabled and should be disabled. + SettingValue = Setting value: {0} to {1}. + NewSchedule = Modifying hardware inventory schedule. + RequiredSchedule = In order to create a schedule you must specify ScheduleType. + DeviceIgnore = CollectMifFile and MaxThirdPartyMifSize settings are only set in the Default Client Agent Settings, ignoring setting. + DisableIgnore = In order to set a schedule, MaxRandomDelayMins CollectMifFile, or MaxThirdPartyMifSize, Enable must be set to true, ignoring settings. + WrongClientType = Client Settings for Hardware Inventory only applies to Default and Device client settings. +'@ diff --git a/source/DSCResources/DSC_CMClientSettingsMetered/DSC_CMClientSettingsMetered.psm1 b/source/DSCResources/DSC_CMClientSettingsMetered/DSC_CMClientSettingsMetered.psm1 new file mode 100644 index 00000000..762889c0 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsMetered/DSC_CMClientSettingsMetered.psm1 @@ -0,0 +1,213 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + $type = @('Default','Device','User')[$clientSetting.Type] + $settings = Get-CMClientSetting -Name $ClientSettingName -Setting MeteredNetwork + + if ($settings) + { + $usage = switch ($settings.MeteredNetworkUsage) + { + '1' { 'Allow' } + '2' { 'Limit' } + '4' { 'Block' } + } + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + MeteredNetworkUsage = $usage + ClientSettingStatus = $status + ClientType = $type + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER MeteredNetworkUsage + Specifies setting for client communication on a metered internet connection. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [ValidateSet('Allow','Limit','Block')] + [String] + $MeteredNetworkUsage + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + + try + { + if ($state.ClientSettingStatus -eq 'Absent') + { + throw ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + } + + if ($state.ClientType -eq 'User') + { + throw $script:localizedData.WrongClientType + } + + if ($MeteredNetworkUsage -ne $state.MeteredNetworkUsage) + { + Write-Verbose -Message ($script:localizedData.SettingValue -f $state.MeteredNetworkUsage, $MeteredNetworkUsage) + $buildingParams += @{ + MeteredNetworkUsage = $MeteredNetworkUsage + } + } + + if ($buildingParams) + { + if ($state.ClientType -eq 'Default') + { + Set-CMClientSettingMeteredInternetConnection -DefaultSetting @buildingParams + } + else + { + Set-CMClientSettingMeteredInternetConnection -Name $ClientSettingName @buildingParams + } + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER MeteredNetworkUsage + Specifies setting for client communication on a metered internet connection. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [ValidateSet('Allow','Limit','Block')] + [String] + $MeteredNetworkUsage + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + $result = $true + + if ($state.ClientSettingStatus -eq 'Absent') + { + Write-Warning -Message ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + $result = $false + } + elseif ($state.ClientType -eq 'User') + { + Write-Warning -Message $script:localizedData.WrongClientType + $result = $false + } + else + { + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = @('MeteredNetworkUsage') + } + + $result = Test-DscParameterState @testParams -TurnOffTypeChecking -Verbose + } + + Write-Verbose -Message ($script:localizedData.TestState -f $result) + Set-Location -Path "$env:temp" + return $result +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettingsMetered/DSC_CMClientSettingsMetered.schema.mof b/source/DSCResources/DSC_CMClientSettingsMetered/DSC_CMClientSettingsMetered.schema.mof new file mode 100644 index 00000000..3bb29fdc --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsMetered/DSC_CMClientSettingsMetered.schema.mof @@ -0,0 +1,9 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettingsMetered")] +class DSC_CMClientSettingsMetered : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Write, Description("Specifies setting for client communication on a metered internet connection."), ValueMap{"Allow","Limit","Block"}, Values{"Allow","Limit","Block"}] String MeteredNetworkUsage; + [Read, Description("Specifies if the client settings policy exists.")] String ClientSettingStatus; + [Read, Description("Specifies the type of client policy setting.")] String ClientType; +}; diff --git a/source/DSCResources/DSC_CMClientSettingsMetered/en-US/DSC_CMClientSettingsMetered.strings.psd1 b/source/DSCResources/DSC_CMClientSettingsMetered/en-US/DSC_CMClientSettingsMetered.strings.psd1 new file mode 100644 index 00000000..5ae11f1f --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsMetered/en-US/DSC_CMClientSettingsMetered.strings.psd1 @@ -0,0 +1,7 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy for metered settings. + ClientPolicySetting = Client Policy Setting {0} does not exist, and will need to be created prior to making client setting changes. + TestState = Test-TargetResource compliance check returned: {0}. + SettingValue = Setting MeteredNetworkUsage from: {0} to {1}. + WrongClientType = Client Settings for Metered Connections only applies to Default and Device Client settings. +'@ diff --git a/source/DSCResources/DSC_CMClientSettingsPower/DSC_CMClientSettingsPower.psm1 b/source/DSCResources/DSC_CMClientSettingsPower/DSC_CMClientSettingsPower.psm1 new file mode 100644 index 00000000..25c1c6fd --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsPower/DSC_CMClientSettingsPower.psm1 @@ -0,0 +1,458 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + $type = @('Default','Device','User')[$clientSetting.Type] + $settings = Get-CMClientSetting -Name $ClientSettingName -Setting PowerManagement + + if ($settings) + { + $enabled = [System.Convert]::ToBoolean($settings.Enabled) + $userToOpt = [System.Convert]::ToBoolean($settings.AllowUserToOptOutFromPowerPlan) + $allowUp = @('NotConfigured','Enabled','Disabled')[$settings.AllowWakeup] + $wakeupProxy = [System.Convert]::ToBoolean($settings.EnableWakeupProxy) + [UInt32]$portInfo = $settings.Port + [UInt32]$wolPort = $settings.WolPort + $firewallSetting = @() + $firewallSetting += switch ($settings.WakeupProxyFirewallFlags) + { + 0 { 'None' } + 9 { 'Public' } + 10 { 'Private' } + 11 { 'Private','Public' } + 12 { 'Domain' } + 13 { 'Public','Domain' } + 14 { 'Domain','Private' } + 15 { 'Domain','Private','Public' } + } + + if ($settings.WakeupProxyDirectAccessPrefixList) + { + [array]$ipv6Prefixes = $settings.WakeupProxyDirectAccessPrefixList + } + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + Enable = $enabled + AllowUserToOptOutFromPowerPlan = $userToOpt + EnableWakeupProxy = $wakeupProxy + WakeupProxyPort = $portInfo + WakeOnLanPort = $wolPort + FirewallExceptionForWakeupProxy = $firewallSetting + WakeupProxyDirectAccessPrefix = $ipv6Prefixes + NetworkWakeupOption = $allowUp + ClientSettingStatus = $status + ClientType = $type + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Enable + Specifies if power management plan is to be used. + + .Parameter AllowUserToOptOutFromPowerPlan + Specifies if users are allowed to out out from the power plan. + + .PARAMETER NetworkWakeUpOption + Specifies if network wake up is enabled or disabled. + + .PARAMETER EnableWakeUpProxy + Specifies if the wake up proxy will be enabled or disabled. + + .PARAMETER WakeupProxyPort + Specifies the wake up proxy port. + + .PARAMETER WakeOnLanPort + Specifies the wake on lan port. + + .PARAMETER FirewallExceptionForWakeupProxy + Specifies the which firewall states will be configured for wakeup proxy. + + .PARAMETER WakeupProxyDirectAccessPrefix + Specifies the IPV6 direct access prefix for the wake up proxy. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [Boolean] + $Enable, + + [Parameter()] + [Boolean] + $AllowUserToOptOutFromPowerPlan, + + [Parameter()] + [ValidateSet('NotConfigured','Enabled','Disabled')] + [String] + $NetworkWakeUpOption, + + [Parameter()] + [Boolean] + $EnableWakeUpProxy, + + [Parameter()] + [UInt32] + $WakeupProxyPort, + + [Parameter()] + [UInt32] + $WakeOnLanPort, + + [Parameter()] + [ValidateSet('None','Domain','Private','Public')] + [String[]] + $FirewallExceptionForWakeupProxy, + + [Parameter()] + [String[]] + $WakeupProxyDirectAccessPrefix + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + + try + { + if ($state.ClientSettingStatus -eq 'Absent') + { + throw ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + } + + if ($state.ClientType -eq 'User') + { + throw $script:localizedData.WrongClientType + } + + if (($PSBoundParameters.ContainsKey('WakeOnLanPort')) -and + ($NetworkWakeUpOption -ne 'Enabled') -and + ($EnableWakeUpProxy -ne '$true')) + { + throw $script:localizedData.WakeOnLanMsg + } + + if (($EnableWakeUpProxy -ne $true) -and ($PSBoundParameters.ContainsKey('WakeupProxyPort') -or + $PSBoundParameters.ContainsKey('FirewallExceptionForWakeupProxy') -or + $PSBoundParameters.ContainsKey('WakeupProxyDirectAccessPrefix'))) + { + throw $script:localizedData.WakeOnProxyMsg + } + + if (($FirewallExceptionForWakeupProxy -and $FirewallExceptionForWakeupProxy -contains 'None') -and + ($FirewallExceptionForWakeupProxy -contains 'Domain' -or $FirewallExceptionForWakeupProxy -contains 'Public' -or + $FirewallExceptionForWakeupProxy -contains 'Private')) + { + throw $script:localizedData.FirewallMsg + } + + $defaultValues = @('Enable','AllowUserToOptOutFromPowerPlan','NetworkWakeUpOption','EnableWakeUpProxy', + 'WakeupProxyPort','WakeOnLanPort') + + foreach ($param in $PSBoundParameters.GetEnumerator()) + { + if ($defaultValues -contains $param.Key) + { + if ($param.Value -ne $state[$param.Key]) + { + Write-Verbose -Message ($script:localizedData.SettingValue -f $param.Key, $param.Value) + $buildingParams += @{ + $param.Key = $param.Value + } + } + } + } + + if ($PSBoundParameters.ContainsKey('FirewallExceptionForWakeupProxy')) + { + if (($state.FirewallExceptionForWakeupProxy) -and + ($FirewallExceptionForWakeupProxy.Count -eq $state.FirewallExceptionForWakeupProxy.Count)) + { + foreach ($item in $FirewallExceptionForWakeupProxy) + { + if (-not $($state.FirewallExceptionForWakeupProxy).Contains($item)) + { + $setFirewall = $true + } + } + } + else + { + $setFirewall = $true + } + + if ($setFirewall -eq $true) + { + Write-Verbose -Message ($script:localizedData.SetFirewall -f ($FirewallExceptionForWakeupProxy | Out-String)) + $buildingParams += @{ + FirewallExceptionForWakeupProxy = $FirewallExceptionForWakeupProxy + } + } + } + + if ($PSBoundParameters.ContainsKey('WakeupProxyDirectAccessPrefix')) + { + if (($state.WakeupProxyDirectAccessPrefix) -and + ($WakeupProxyDirectAccessPrefix.Count -eq $state.WakeupProxyDirectAccessPrefix.Count)) + { + foreach ($item in $WakeupProxyDirectAccessPrefix) + { + if (-not $($state.WakeupProxyDirectAccessPrefix).Contains($item)) + { + $setDirect = $true + } + } + } + else + { + $setDirect = $true + } + + if ($setDirect -eq $true) + { + $proxy = $WakeupProxyDirectAccessPrefix -Join ',' + Write-Verbose -Message ($script:localizedData.DirectProxy -f $proxy) + $buildingParams += @{ + WakeupProxyDirectAccessPrefix = $proxy + } + } + } + + if ($buildingParams) + { + if ($state.ClientType -eq 'Default') + { + Set-CMClientSettingPowerManagement -DefaultSetting @buildingParams + } + else + { + Set-CMClientSettingPowerManagement -Name $ClientSettingName @buildingParams + } + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Enable + Specifies if power management plan is to be used. + + .Parameter AllowUserToOptOutFromPowerPlan + Specifies if users are allowed to out out from the power plan. + + .PARAMETER NetworkWakeUpOption + Specifies if network wake up is enabled or disabled. + + .PARAMETER EnableWakeUpProxy + Specifies if the wake up proxy will be enabled or disabled. + + .PARAMETER WakeupProxyPort + Specifies the wake up proxy port. + + .PARAMETER WakeOnLanPort + Specifies the wake on lan port. + + .PARAMETER FirewallExceptionForWakeupProxy + Specifies the which firewall states will be configured for wakeup proxy. + + .PARAMETER WakeupProxyDirectAccessPrefix + Specifies the IPV6 direct access prefix for the wake up proxy. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [Boolean] + $Enable, + + [Parameter()] + [Boolean] + $AllowUserToOptOutFromPowerPlan, + + [Parameter()] + [ValidateSet('NotConfigured','Enabled','Disabled')] + [String] + $NetworkWakeUpOption, + + [Parameter()] + [Boolean] + $EnableWakeUpProxy, + + [Parameter()] + [UInt32] + $WakeupProxyPort, + + [Parameter()] + [UInt32] + $WakeOnLanPort, + + [Parameter()] + [ValidateSet('None','Domain','Private','Public')] + [String[]] + $FirewallExceptionForWakeupProxy, + + [Parameter()] + [String[]] + $WakeupProxyDirectAccessPrefix + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + $result = $true + + if ($state.ClientSettingStatus -eq 'Absent') + { + Write-Warning -Message ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + $result = $false + } + elseif ($state.ClientType -eq 'User') + { + Write-Warning -Message $script:localizedData.WrongClientType + $result = $false + } + else + { + if (($PSBoundParameters.ContainsKey('WakeOnLanPort')) -and + ($NetworkWakeUpOption -ne 'Enabled') -and + ($EnableWakeUpProxy -ne '$true')) + { + Write-Warning -Message $script:localizedData.WakeOnLanMsg + $badInput = $true + } + + if (($EnableWakeUpProxy -ne $true) -and ($PSBoundParameters.ContainsKey('WakeupProxyPort') -or + $PSBoundParameters.ContainsKey('FirewallExceptionForWakeupProxy') -or + $PSBoundParameters.ContainsKey('WakeupProxyDirectAccessPrefix'))) + { + Write-Warning -Message $script:localizedData.WakeOnProxyMsg + $badInput = $true + } + + if (($FirewallExceptionForWakeupProxy -and $FirewallExceptionForWakeupProxy -contains 'None') -and + ($FirewallExceptionForWakeupProxy -contains 'Domain' -or $FirewallExceptionForWakeupProxy -contains 'Public' -or + $FirewallExceptionForWakeupProxy -contains 'Private')) + { + Write-Warning -Message $script:localizedData.FirewallMsg + $badInput = $true + } + + $defaultValues = @('Enable','AllowUserToOptOutFromPowerPlan','NetworkWakeUpOption','EnableWakeUpProxy', + 'WakeupProxyPort','WakeOnLanPort','WakeupProxyDirectAccessPrefix','FirewallExceptionForWakeupProxy') + + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = $defaultValues + } + + $result = Test-DscParameterState @testParams -TurnOffTypeChecking -Verbose -SortArrayValues + } + + if ($result -eq $false -or $badInput -eq $true) + { + $return = $false + } + else + { + $return = $true + } + + Write-Verbose -Message ($script:localizedData.TestState -f $return) + Set-Location -Path "$env:temp" + return $return +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettingsPower/DSC_CMClientSettingsPower.schema.mof b/source/DSCResources/DSC_CMClientSettingsPower/DSC_CMClientSettingsPower.schema.mof new file mode 100644 index 00000000..73a4709b --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsPower/DSC_CMClientSettingsPower.schema.mof @@ -0,0 +1,16 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettingsPower")] +class DSC_CMClientSettingsPower : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Write, Description("Specifies if power management plan is to be used.")] Boolean Enable; + [Write, Description("Specifies if users are allowed to out out from the power plan.")] Boolean AllowUserToOptOutFromPowerPlan; + [Write, Description("Specifies if network wake up is not configured, enabled or disabled."), ValueMap{"NotConfigured","Enabled","Disabled"}, Values{"NotConfigured","Enabled","Disabled"}] String NetworkWakeUpOption; + [Write, Description("Specifies if the wake up proxy will be enabled or disabled.")] Boolean EnableWakeUpProxy; + [Write, Description("Specifies the wake up proxy port.")] UInt32 WakeupProxyPort; + [Write, Description("Specifies the wake on lan port.")] UInt32 WakeOnLanPort; + [Write, Description("Specifies the which firewall states will be configured for wakeup proxy."), ValueMap{"None","Domain","Private","Public"}, Values{"None","Domain","Private","Public"}] String FirewallExceptionForWakeupProxy[]; + [Write, Description("Specifies the IPV6 direct access prefix for the wake up proxy.")] String WakeupProxyDirectAccessPrefix[]; + [Read, Description("Specifies if the client settings policy exists.")] String ClientSettingStatus; + [Read, Description("Specifies the type of client policy setting.")] String ClientType; +}; diff --git a/source/DSCResources/DSC_CMClientSettingsPower/en-US/DSC_CMClientSettingsPower.strings.psd1 b/source/DSCResources/DSC_CMClientSettingsPower/en-US/DSC_CMClientSettingsPower.strings.psd1 new file mode 100644 index 00000000..fb6c1d56 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsPower/en-US/DSC_CMClientSettingsPower.strings.psd1 @@ -0,0 +1,12 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy for power management settings. + ClientPolicySetting = Client Policy Setting {0} does not exist, and will need to be created prior to making client setting changes. + TestState = Test-TargetResource compliance check returned: {0}. + SettingValue = Setting value: {0} to {1}. + WrongClientType = Client Settings for power management only applies to Default and Device Client settings. + WakeOnLanMsg = In order to set WakeOnLanPort you must specify NetworkWakeUpOption Enabled and also set EnableWakeUpProxy true. + WakeOnProxyMsg = In order to set WakeUpProxyPort, FirewallExceptionForWakeupProxy, or WakeupProxyDirectAccessPrefix, EnableWakeUpProxy must be set to $true. + FirewallMsg = When specifying FirewallExceptionForWakeupProxy and specifying None, you can not specify any other firewall exceptions. + SetFirewall = Setting FirewallExceptionForWakeupProxy to {0}. + DirectProxy = Setting WakeupProxyDirectAccessPrefix to {0}. +'@ diff --git a/source/DSCResources/DSC_CMClientSettingsRemoteTools/DSC_CMClientSettingsRemoteTools.psm1 b/source/DSCResources/DSC_CMClientSettingsRemoteTools/DSC_CMClientSettingsRemoteTools.psm1 new file mode 100644 index 00000000..ad46a70e --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsRemoteTools/DSC_CMClientSettingsRemoteTools.psm1 @@ -0,0 +1,655 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + $type = @('Default','Device','User')[$clientSetting.Type] + $settings = Get-CMClientSetting -Name $ClientSettingName -Setting RemoteTools + + if ($settings) + { + if ($settings.FirewallExceptionProfiles -eq 0) + { + $toolsStatus = 'Disabled' + } + else + { + $firewallSetting = @() + $firewallSetting += switch ($settings.FirewallExceptionProfiles) + { + 9 { 'Public' } + 10 { 'Private' } + 11 { 'Private','Public' } + 12 { 'Domain' } + 13 { 'Public','Domain' } + 14 { 'Domain','Private' } + 15 { 'Domain','Private','Public' } + } + + $clientChange = [System.Convert]::ToBoolean($settings.AllowClientChange) + $unattended = [System.Convert]::ToBoolean($settings.AllowRemCtrlToUnattended) + $permRequired = [System.Convert]::ToBoolean($settings.PermissionRequired) + $clipboard = [System.Convert]::ToBoolean($settings.ClipboardAccessPermissionRequired) + $localAdmin = [System.Convert]::ToBoolean($settings.AllowLocalAdminToDoRemoteControl) + $access = @('NoAccess','ViewOnly','FullControl')[[UInt32]$settings.AccessLevel] + $viewers = [array]$settings.PermittedViewers + $taskBar = [System.Convert]::ToBoolean($settings.RemCtrlTaskbarIcon) + $sessionBar = [System.Convert]::ToBoolean($settings.RemCtrlConnectionBar) + $audible = @('PlayNoSound','PlaySoundAtBeginAndEnd','PlaySoundRepeatedly')[[UInt32]$settings.AudibleSignal] + $unsolRemoteAssist = [System.Convert]::ToBoolean($settings.ManageRA) + $solRemoteAssist = [System.Convert]::ToBoolean($settings.EnforceRAandTSSettings) + $manageTS = [System.Convert]::ToBoolean($settings.ManageTS) + $enableTS = [System.Convert]::ToBoolean($settings.EnableTS) + $userAuth = [System.Convert]::ToBoolean($settings.TSUserAuthentication) + + if ($type -eq 'Default') + { + $mainSite = $clientSetting.SiteCode + $query = "Select * from SMS_SCI_ClientComp Where SiteCode = '$mainSite' AND ItemType = 'Client Component' AND FileType = 2 and ItemName='Remote Control'" + $cimQuery = (Get-CimInstance -Namespace root\SMS\Site_$SiteCode -Query $query -ErrorAction SilentlyContinue).Props + if ($cimQuery -ne $null) + { + $enableRA = ($cimQuery | Where-Object -FilterScript {$_.PropertyName -eq 'Enable RA'}).Value + $fullControl = ($cimQuery | Where-Object -FilterScript {$_.PropertyName -eq 'Allow RA Unsolicited Control'}).Value + if ($enableRA -eq 0) + { + $levels = 'None' + } + elseif ($fullcontrol -eq '1') + { + $levels = 'FullControl' + } + else + { + $levels = 'RemoteViewing' + } + } + } + else + { + $levels = $settings.RemoteAssistanceAccessLevel + } + + $toolsStatus = 'Enabled' + } + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + FirewallExceptionProfile = $firewallSetting + AllowClientChange = $clientChange + AllowUnattendedComputer = $unattended + PromptUserForPermission = $permRequired + PromptUserForClipboardPermission = $clipboard + GrantPermissionToLocalAdministrator = $localAdmin + AccessLevel = $access + PermittedViewer = $viewers + ShowNotificationIconOnTaskbar = $taskBar + ShowSessionConnectionBar = $sessionBar + AudibleSignal = $audible + ManageUnsolicitedRemoteAssistance = $unsolRemoteAssist + ManageSolicitedRemoteAssistance = $solRemoteAssist + RemoteAssistanceAccessLevel = $levels + ManageRemoteDesktopSetting = $manageTS + AllowPermittedViewer = $enableTS + RequireAuthentication = $userAuth + ClientSettingStatus = $status + ClientType = $type + RemoteToolsStatus = $toolsStatus + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter FirewallExceptionProfile + Specifies if the firewall exceptions profiles for Remote Tools. + + .Parameter AllowClientChange + Specifies if users can change policy or notifications settings in software center. + + .PARAMETER AllowUnattendedComputer + Specifies if allow remote control of an unattended computer is enabled or disabled. + + .PARAMETER PromptUserForPermission + Specifies if users are prompted for remote control permissions. + + .PARAMETER PromptUserForClipboardPermission + Specifies if users are prompted for permission to transfer content from share clipboard. + + .PARAMETER GrantPermissionToLocalAdministrator + Specifies if remote control permissions are granted to the local administrators group. + + .PARAMETER AccessLevel + Specifies the access level allowed. + + .PARAMETER PermittedViewer + Specifies the permitted viewers for remote control and remote assistance. + + .PARAMETER ShowNotificationIconOnTaskbar + Specifies if session notifications are shown on the taskbar. + + .PARAMETER ShowSessionConnectionBar + Specifies if the session connection bar is shown. + + .PARAMETER AudibleSignal + Specifies if sound is played on the client. + + .PARAMETER ManageUnsolicitedRemoteAssistance + Specifies if unsolicited remote assistance settings are managed. + + .PARAMETER ManageSolicitedRemoteAssistance + Specifies if solicited remote assistance settings are managed. + + .PARAMETER RemoteAssistanceAccessLevel + Specifies the level of access for remote assistance. + + .PARAMETER ManageRemoteDesktopSetting + Specifies if remote desktop settings are managed. + + .PARAMETER AllowPermittedViewer + Specifies if permitted viewers are allowed to connect by using remote desktop connection. + + .PARAMETER RequireAuthentication + Specifies network level required authentication on computers that run Vista or later versions. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [ValidateSet('Domain','Private','Public')] + [String[]] + $FirewallExceptionProfile, + + [Parameter()] + [Boolean] + $AllowClientChange, + + [Parameter()] + [Boolean] + $AllowUnattendedComputer, + + [Parameter()] + [Boolean] + $PromptUserForPermission, + + [Parameter()] + [Boolean] + $PromptUserForClipboardPermission, + + [Parameter()] + [Boolean] + $GrantPermissionToLocalAdministrator, + + [Parameter()] + [ValidateSet('NoAccess','ViewOnly','FullControl')] + [String] + $AccessLevel, + + [Parameter()] + [String[]] + $PermittedViewer, + + [Parameter()] + [Boolean] + $ShowNotificationIconOnTaskbar, + + [Parameter()] + [Boolean] + $ShowSessionConnectionBar, + + [Parameter()] + [ValidateSet('PlayNoSound','PlaySoundAtBeginAndEnd','PlaySoundRepeatedly')] + [String] + $AudibleSignal, + + [Parameter()] + [Boolean] + $ManageUnsolicitedRemoteAssistance, + + [Parameter()] + [Boolean] + $ManageSolicitedRemoteAssistance, + + [Parameter()] + [ValidateSet('None','RemoteViewing','FullControl')] + [String] + $RemoteAssistanceAccessLevel, + + [Parameter()] + [Boolean] + $ManageRemoteDesktopSetting, + + [Parameter()] + [Boolean] + $AllowPermittedViewer, + + [Parameter()] + [Boolean] + $RequireAuthentication + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + $schedResult = $true + + try + { + if ($state.ClientSettingStatus -eq 'Absent') + { + throw ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + } + + if ($state.ClientType -eq 'User') + { + throw $script:localizedData.WrongClientType + } + + if ($state.RemoteToolsStatus -eq 'Disabled') + { + throw $script:localizedData.RemoteToolsDisabled + } + + if ([string]::IsNullOrEmpty($state.RemoteToolsStatus) -and + -not $PSBoundParameters.ContainsKey('FirewallExceptionProfile')) + { + throw ($script:localizedData.MissingFirewall -f $ClientSettingName) + } + + $defaultValues = @('AllowClientChange','AllowUnattendedComputer','PromptUserForPermission', + 'PromptUserForClipboardPermission','GrantPermissionToLocalAdministrator','AccessLevel', + 'ShowNotificationIconOnTaskbar','ShowSessionConnectionBar','AudibleSignal','ManageUnsolicitedRemoteAssistance', + 'ManageSolicitedRemoteAssistance','RemoteAssistanceAccessLevel','ManageRemoteDesktopSetting') + + if (($PSBoundParameters.ContainsKey('AllowPermittedViewer') -or $PSBoundParameters.ContainsKey('RequireAuthentication')) -and + ($ManageRemoteDesktopSetting -ne $true)) + { + Write-Warning -Message $script:localizedData.ExtraSettings + } + elseif (($PSBoundParameters.ContainsKey('RequireAuthentication')) -and + (($PSBoundParameters.ContainsKey('AllowPermittedViewer') -and $AllowPermittedViewer -eq $false) -or + (-not $PSBoundParameters.ContainsKey('AllowPermittedViewer') -and $state.AllowPermittedViewer -eq $false))) + { + $defaultValues += @('AllowPermittedViewer') + Write-Warning -Message $script:localizedData.RequireAuth + } + else + { + $defaultValues += @('AllowPermittedViewer','RequireAuthentication') + } + + foreach ($param in $PSBoundParameters.GetEnumerator()) + { + if ($defaultValues -contains $param.Key) + { + if ($param.Value -ne $state[$param.Key]) + { + Write-Verbose -Message ($script:localizedData.SettingValue -f $param.Key, $param.Value) + $buildingParams += @{ + $param.Key = $param.Value + } + } + } + } + + if ($PSBoundParameters.ContainsKey('FirewallExceptionProfile')) + { + if (($state.FirewallExceptionProfile) -and + ($FirewallExceptionProfile.Count -eq $state.FirewallExceptionProfile.Count)) + { + foreach ($item in $FirewallExceptionProfile) + { + if (-not $($state.FirewallExceptionProfile).Contains($item)) + { + $setFirewall = $true + } + } + } + else + { + $setFirewall = $true + } + + if ($setFirewall -eq $true) + { + Write-Verbose -Message ($script:localizedData.SetFirewall -f ($FirewallExceptionForWakeupProxy | Out-String)) + $buildingParams += @{ + FirewallExceptionProfile = $FirewallExceptionProfile + } + } + } + + if ($PSBoundParameters.ContainsKey('PermittedViewer')) + { + if (($state.PermittedViewer) -and + ($PermittedViewer.Count -eq $state.PermittedViewer.Count)) + { + foreach ($item in $PermittedViewer) + { + if (-not $($state.PermittedViewer).Contains($item)) + { + $setViewer = $true + } + } + } + else + { + $setViewer = $true + } + + if ($setViewer -eq $true) + { + Write-Verbose -Message ($script:localizedData.SetPermittViewer -f ($PermittedViewer | Out-String)) + $buildingParams += @{ + PermittedViewer = $PermittedViewer + } + } + } + + if ($buildingParams) + { + if ($state.ClientType -eq 'Default') + { + Set-CMClientSettingRemoteTool -DefaultSetting @buildingParams + } + else + { + Set-CMClientSettingRemoteTool -Name $ClientSettingName @buildingParams + } + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter FirewallExceptionProfile + Specifies if the firewall exceptions profiles for Remote Tools. + + .Parameter AllowClientChange + Specifies if users can change policy or notifications settings in software center. + + .PARAMETER AllowUnattendedComputer + Specifies if allow remote control of an unattended computer is enabled or disabled. + + .PARAMETER PromptUserForPermission + Specifies if users are prompted for remote control permissions. + + .PARAMETER PromptUserForClipboardPermission + Specifies if users are prompted for permission to transfer content from share clipboard. + + .PARAMETER GrantPermissionToLocalAdministrator + Specifies if remote control permissions are granted to the local administrators group. + + .PARAMETER AccessLevel + Specifies the access level allowed. + + .PARAMETER PermittedViewer + Specifies the permitted viewers for remote control and remote assistance. + + .PARAMETER ShowNotificationIconOnTaskbar + Specifies if session notifications are shown on the taskbar. + + .PARAMETER ShowSessionConnectionBar + Specifies if the session connection bar is shown. + + .PARAMETER AudibleSignal + Specifies if sound is played on the client. + + .PARAMETER ManageUnsolicitedRemoteAssistance + Specifies if unsolicited remote assistance settings are managed. + + .PARAMETER ManageSolicitedRemoteAssistance + Specifies if solicited remote assistance settings are managed. + + .PARAMETER RemoteAssistanceAccessLevel + Specifies the level of access for remote assistance. + + .PARAMETER ManageRemoteDesktopSetting + Specifies if remote desktop settings are managed. + + .PARAMETER AllowPermittedViewer + Specifies if permitted viewers are allowed to connect by using remote desktop connection. + + .PARAMETER RequireAuthentication + Specifies network level required authentication on computers that run Windows Vista or later versions. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [ValidateSet('Domain','Private','Public')] + [String[]] + $FirewallExceptionProfile, + + [Parameter()] + [Boolean] + $AllowClientChange, + + [Parameter()] + [Boolean] + $AllowUnattendedComputer, + + [Parameter()] + [Boolean] + $PromptUserForPermission, + + [Parameter()] + [Boolean] + $PromptUserForClipboardPermission, + + [Parameter()] + [Boolean] + $GrantPermissionToLocalAdministrator, + + [Parameter()] + [ValidateSet('NoAccess','ViewOnly','FullControl')] + [String] + $AccessLevel, + + [Parameter()] + [String[]] + $PermittedViewer, + + [Parameter()] + [Boolean] + $ShowNotificationIconOnTaskbar, + + [Parameter()] + [Boolean] + $ShowSessionConnectionBar, + + [Parameter()] + [ValidateSet('PlayNoSound','PlaySoundAtBeginAndEnd','PlaySoundRepeatedly')] + [String] + $AudibleSignal, + + [Parameter()] + [Boolean] + $ManageUnsolicitedRemoteAssistance, + + [Parameter()] + [Boolean] + $ManageSolicitedRemoteAssistance, + + [Parameter()] + [ValidateSet('None','RemoteViewing','FullControl')] + [String] + $RemoteAssistanceAccessLevel, + + [Parameter()] + [Boolean] + $ManageRemoteDesktopSetting, + + [Parameter()] + [Boolean] + $AllowPermittedViewer, + + [Parameter()] + [Boolean] + $RequireAuthentication + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + $result = $true + $schedResult = $true + + if ($state.ClientSettingStatus -eq 'Absent') + { + Write-Warning -Message ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + $result = $false + } + elseif ($state.ClientType -eq 'User') + { + Write-Warning -Message $script:localizedData.WrongClientType + $result = $false + } + elseif ($state.RemoteToolsStatus -eq 'Disabled') + { + Write-Warning -Message $script:localizedData.RemoteToolsDisabled + $result = $false + } + elseif ([string]::IsNullOrEmpty($state.RemoteToolsStatus) -and + -not $PSBoundParameters.ContainsKey('FirewallExceptionProfile')) + { + Write-Warning -Message ($script:localizedData.MissingFirewall -f $ClientSettingName) + $result = $false + } + else + { + $defaultValues = @('AllowClientChange','AllowUnattendedComputer','PromptUserForPermission', + 'PromptUserForClipboardPermission','GrantPermissionToLocalAdministrator','AccessLevel', + 'ShowNotificationIconOnTaskbar','ShowSessionConnectionBar','AudibleSignal','ManageUnsolicitedRemoteAssistance', + 'ManageSolicitedRemoteAssistance','RemoteAssistanceAccessLevel','ManageRemoteDesktopSetting') + + if (($PSBoundParameters.ContainsKey('AllowPermittedViewer') -or $PSBoundParameters.ContainsKey('RequireAuthentication')) -and + ($ManageRemoteDesktopSetting -ne $true)) + { + Write-Warning -Message $script:localizedData.ExtraSettings + } + elseif (($PSBoundParameters.ContainsKey('RequireAuthentication')) -and + (($PSBoundParameters.ContainsKey('AllowPermittedViewer') -and $AllowPermittedViewer -eq $false) -or + (-not $PSBoundParameters.ContainsKey('AllowPermittedViewer') -and $state.AllowPermittedViewer -eq $false))) + { + $defaultValues += @('AllowPermittedViewer') + Write-Warning -Message $script:localizedData.RequireAuth + } + else + { + $defaultValues += @('AllowPermittedViewer','RequireAuthentication') + } + + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = $defaultValues + } + + $result = Test-DscParameterState @testParams -TurnOffTypeChecking -Verbose -SortArrayValues + } + + if ($result -eq $false -or $schedResult -eq $false -or $badInput -eq $true) + { + $return = $false + } + else + { + $return = $true + } + + Write-Verbose -Message ($script:localizedData.TestState -f $return) + Set-Location -Path "$env:temp" + return $return +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettingsRemoteTools/DSC_CMClientSettingsRemoteTools.schema.mof b/source/DSCResources/DSC_CMClientSettingsRemoteTools/DSC_CMClientSettingsRemoteTools.schema.mof new file mode 100644 index 00000000..fb333271 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsRemoteTools/DSC_CMClientSettingsRemoteTools.schema.mof @@ -0,0 +1,26 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettingsRemoteTools")] +class DSC_CMClientSettingsRemoteTools : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Write, Description("Specifies if the firewall exceptions profiles for Remote Tools."), ValueMap{"Domain","Private","Public"}, Values{"Domain","Private","Public"}] String FirewallExceptionProfile[]; + [Write, Description("Specifies if users can change policy or notifications settings in software center.")] Boolean AllowClientChange; + [Write, Description("Specifies if allow remote control of an unattended computer is enabled or disabled.")] Boolean AllowUnattendedComputer; + [Write, Description("Specifies if users are prompted for remote control permissions.")] Boolean PromptUserForPermission; + [Write, Description("Specifies if users are prompted for permission to transfer content from share clipboard.")] Boolean PromptUserForClipboardPermission; + [Write, Description("Specifies if remote control permissions are granted to the local administrators group.")] Boolean GrantPermissionToLocalAdministrator; + [Write, Description("Specifies the access level allowed."), ValueMap{"NoAccess","ViewOnly","FullControl"}, Values{"NoAccess","ViewOnly","FullControl"}] String AccessLevel; + [Write, Description("Specifies the permitted viewers for remote control and remote assistance.")] String PermittedViewer[]; + [Write, Description("Specifies if session notifications are shown on the taskbar.")] Boolean ShowNotificationIconOnTaskbar; + [Write, Description("Specifies if the session connection bar is shown.")] Boolean ShowSessionConnectionBar; + [Write, Description("Specifies if sound is played on the client."), ValueMap{"PlayNoSound","PlaySoundAtBeginAndEnd","PlaySoundRepeatedly"}, Values{"PlayNoSound","PlaySoundAtBeginAndEnd","PlaySoundRepeatedly"}] String AudibleSignal; + [Write, Description("Specifies if unsolicited remote assistance settings are managed.")] Boolean ManageUnsolicitedRemoteAssistance; + [Write, Description("Specifies if solicited remote assistance settings are managed.")] Boolean ManageSolicitedRemoteAssistance; + [Write, Description("Specifies the level of access for remote assistance."), ValueMap{"None","RemoteViewing","FullControl"}, Values{"None","RemoteViewing","FullControl"}] String RemoteAssistanceAccessLevel; + [Write, Description("Specifies if remote desktop settings are managed.")] Boolean ManageRemoteDesktopSetting; + [Write, Description("Specifies if permitted viewers are allowed to connect by using remote desktop connection.")] Boolean AllowPermittedViewer; + [Write, Description("Specifies network level required authentication on computers that run Vista or later versions.")] Boolean RequireAuthentication; + [Read, Description("Specifies if the client settings policy exists.")] String ClientSettingStatus; + [Read, Description("Specifies the type of client policy setting.")] String ClientType; + [Read, Description("Specifies if the Remote Tools settings is enabled or disabled.")] String RemoteToolsStatus; +}; diff --git a/source/DSCResources/DSC_CMClientSettingsRemoteTools/en-US/DSC_CMClientSettingsRemoteTools.strings.psd1 b/source/DSCResources/DSC_CMClientSettingsRemoteTools/en-US/DSC_CMClientSettingsRemoteTools.strings.psd1 new file mode 100644 index 00000000..508254a7 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsRemoteTools/en-US/DSC_CMClientSettingsRemoteTools.strings.psd1 @@ -0,0 +1,13 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy for remote tools settings. + ClientPolicySetting = Client Policy Setting {0} does not exist, and will need to be created prior to making client setting changes. + TestState = Test-TargetResource compliance check returned: {0}. + SettingValue = Setting value: {0} to {1}. + WrongClientType = Client Settings for remote tools only applies to Default and Device Client settings. + RemoteToolsDisabled = Remote tools is currenly disabled and must be enabled to set settings for Remote Tools. + ExtraSettings = AllowPermittedViewer or RequireAuthentication was specified, these settings can only be set when ManageRemoteDesktopSetting is set to true, ignoring settings. + SetFirewall = Setting FirewallExceptionProfile to {0}. + SetPermittViewer = Setting PermittedViewer to {0}. + MissingFirewall = ClientSettingName: {0}, is currently not configured. FirewallExceptionProfile must be specified to configure additional settings. + RequireAuth = AllowPermittedViewer is currently or a desired state of false, to modify RequireAuthenication, AllowPermittedViewer must be set to true, ignoring setting. +'@ diff --git a/source/DSCResources/DSC_CMClientSettingsSoftwareCenter/DSC_CMClientSettingsSoftwareCenter.psm1 b/source/DSCResources/DSC_CMClientSettingsSoftwareCenter/DSC_CMClientSettingsSoftwareCenter.psm1 new file mode 100644 index 00000000..d64fc9f8 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsSoftwareCenter/DSC_CMClientSettingsSoftwareCenter.psm1 @@ -0,0 +1,573 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter EnableCustomize + Specifies if custom software center is to be used. + Not Used in Get. +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $EnableCustomize + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + $type = @('Default','Device','User')[$clientSetting.Type] + $settings = Get-CMClientSetting -Name $ClientSettingName -Setting SoftwareCenter + + if ($settings) + { + $portal = @('Software Center','Company Portal')[$settings.SC_UserPortal] + + if ($portal -eq 'Software Center') + { + if ($settings.SC_Old_Branding -eq 0) + { + $customize = $false + } + else + { + $customize = $true + } + + if ($customize -eq $true) + { + $xml = [xml]$settings.SettingsXml + + if ($xml) + { + $orgName = $xml.settings.'brand-orgname' + $color = $xml.settings.'brand-color' + $hideApp = [System.Convert]::ToBoolean($xml.settings.'application-catalog-link-hidden') + $hideInstalled = [System.Convert]::ToBoolean($xml.settings.'software-list'.'installed-applications-hidden') + $hideUnapproved = [System.Convert]::ToBoolean($xml.settings.'software-list'.'unapproved-applications-hidden') + $validateTab = $xml.settings.'tab-visibility'.tab + + foreach ($item in $validateTab) + { + switch ($item.Name) + { + 'AvailableSoftware' { $softwareTab = [System.Convert]::ToBoolean($item.visible) } + 'Updates' { $updateTab = [System.Convert]::ToBoolean($item.visible) } + 'OSD' { $osTab = [System.Convert]::ToBoolean($item.visible) } + 'InstallationStatus' { $statusTab = [System.Convert]::ToBoolean($item.visible) } + 'Compliance' { $comTab = [System.Convert]::ToBoolean($item.visible) } + 'Options' { $opsTab = [System.Convert]::ToBoolean($item.visible) } + } + } + } + } + } + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + EnableCustomize = $customize + CompanyName = $orgName + ColorScheme = $color + HideApplicationCatalogLink = $hideApp + HideInstalledApplication = $hideInstalled + HideUnapprovedApplication = $hideUnapproved + EnableApplicationsTab = $softwareTab + EnableUpdatesTab = $updateTab + EnableOperatingSystemsTab = $osTab + EnableStatusTab = $statusTab + EnableComplianceTab = $comTab + EnableOptionsTab = $opsTab + ClientSettingStatus = $status + ClientType = $type + PortalType = $portal + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter EnableCustomize + Specifies if custom software center is to be used. + + .Parameter CompanyName + Specifies the company name to be used in software center. + + .PARAMETER ColorScheme + Specifies in hex format the color to be used in software center. + + .PARAMETER HideApplicationCatalogLink + Specifies if application catalog link is hidden. + + .PARAMETER HideInstalledApplication + Specifies if installed applications are hidden. + + .PARAMETER HideUnapprovedApplication + Specifies if unapproved applications are hidden. + + .PARAMETER EnableApplicationsTab + Specifies if application tab is visible. + + .PARAMETER EnableUpdatesTab + Specifies if updates tab is visible. + + .PARAMETER EnableOperatingSystemsTab + Specifies if operating system tab is visible. + + .PARAMETER EnableStatusTab + Specifies if status tab is visible. + + .PARAMETER EnableComplianceTab + Specifies if compliance tab is visible. + + .PARAMETER EnableOptionsTab + Specifies if options tab is visible. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $EnableCustomize, + + [Parameter()] + [String] + $CompanyName, + + [Parameter()] + [String] + $ColorScheme, + + [Parameter()] + [Boolean] + $HideApplicationCatalogLink, + + [Parameter()] + [Boolean] + $HideInstalledApplication, + + [Parameter()] + [Boolean] + $HideUnapprovedApplication, + + [Parameter()] + [Boolean] + $EnableApplicationsTab, + + [Parameter()] + [Boolean] + $EnableUpdatesTab, + + [Parameter()] + [Boolean] + $EnableOperatingSystemsTab, + + [Parameter()] + [Boolean] + $EnableStatusTab, + + [Parameter()] + [Boolean] + $EnableComplianceTab, + + [Parameter()] + [Boolean] + $EnableOptionsTab + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName -EnableCustomize $EnableCustomize + $schedResult = $true + + try + { + if ($state.ClientSettingStatus -eq 'Absent') + { + throw ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + } + + if ($state.ClientType -eq 'User') + { + throw $script:localizedData.WrongClientType + } + + if ($state.PortalType -eq 'Company Portal') + { + throw $script:localizedData.CompanyPortalMsg + } + + if ($EnableCustomize -eq $true) + { + if ($PSBoundParameters.ContainsKey('ColorScheme')) + { + $regexPrefix = '^(#|0x)?[0-9,a-f]*$' + + if ($ColorScheme.Length -ne 7 -or $ColorScheme.SubString(0,1) -ne '#' -or + $ColorScheme -notmatch $regexPrefix) + { + throw ($script:localizedData.ColorSchemeErrorMsg -f $ColorScheme) + } + } + + $tabsCheck = @('EnableApplicationsTab','EnableUpdatesTab','EnableOperatingSystemsTab','EnableStatusTab', + 'EnableComplianceTab','EnableOptionsTab') + + foreach ($item in $tabsCheck) + { + if ($PSBoundParameters.ContainsKey($item)) + { + $itemValue = Get-Variable -Name $item + $arrayOfTabs += @{ + $item = $itemValue.Value + } + } + else + { + if ([string]::IsNullOrEmpty($state.$item) -or $state.$item -eq $true) + { + $arrayOfTabs += @{ + $item = $true + } + } + else + { + $arrayOfTabs += @{ + $item = $false + } + } + } + } + + if ($arrayOfTabs.Values -notcontains $true) + { + throw $script:localizedData.TabsDisabled + } + + $defaultValues = @('EnableCustomize','CompanyName','ColorScheme','HideApplicationCatalogLink', + 'HideInstalledApplication','HideUnapprovedApplication','EnableApplicationsTab', + 'EnableUpdatesTab','EnableOperatingSystemsTab','EnableStatusTab', + 'EnableComplianceTab','EnableOptionsTab') + + foreach ($param in $PSBoundParameters.GetEnumerator()) + { + if ($defaultValues -contains $param.Key) + { + if ($param.Value -ne $state[$param.Key]) + { + Write-Verbose -Message ($script:localizedData.SettingValue -f $param.Key, $param.Value) + $buildingParams += @{ + $param.Key = $param.Value + } + } + } + } + } + elseif ($state.EnableCustomize -eq $true) + { + if ($PSBoundParameters.Keys.Count -ge 4) + { + Write-Warning -Message $script:localizedData.DisableIgnore + } + + Write-Verbose -Message $script:localizedData.TestDisabled + + $buildingParams += @{ + EnableCustomize = $EnableCustomize + } + } + + if ($buildingParams) + { + if ($state.ClientType -eq 'Default') + { + Set-CMClientSettingSoftwareCenter -DefaultSetting @buildingParams + } + else + { + Set-CMClientSettingSoftwareCenter -Name $ClientSettingName @buildingParams + } + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter EnableCustomize + Specifies if custom software center is to be used. + + .Parameter CompanyName + Specifies the company name to be used in software center. + + .PARAMETER ColorScheme + Specifies in hex format the color to be used in software center. + + .PARAMETER HideApplicationCatalogLink + Specifies if application catalog link is hidden. + + .PARAMETER HideInstalledApplication + Specifies if installed applications are hidden. + + .PARAMETER HideUnapprovedApplication + Specifies if unapproved applications are hidden. + + .PARAMETER EnableApplicationsTab + Specifies if application tab is visible. + + .PARAMETER EnableUpdatesTab + Specifies if updates tab is visible. + + .PARAMETER EnableOperatingSystemsTab + Specifies if operating system tab is visible. + + .PARAMETER EnableStatusTab + Specifies if status tab is visible. + + .PARAMETER EnableComplianceTab + Specifies if compliance tab is visible. + + .PARAMETER EnableOptionsTab + Specifies if options tab is visible. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $EnableCustomize, + + [Parameter()] + [String] + $CompanyName, + + [Parameter()] + [String] + $ColorScheme, + + [Parameter()] + [Boolean] + $HideApplicationCatalogLink, + + [Parameter()] + [Boolean] + $HideInstalledApplication, + + [Parameter()] + [Boolean] + $HideUnapprovedApplication, + + [Parameter()] + [Boolean] + $EnableApplicationsTab, + + [Parameter()] + [Boolean] + $EnableUpdatesTab, + + [Parameter()] + [Boolean] + $EnableOperatingSystemsTab, + + [Parameter()] + [Boolean] + $EnableStatusTab, + + [Parameter()] + [Boolean] + $EnableComplianceTab, + + [Parameter()] + [Boolean] + $EnableOptionsTab + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName -EnableCustomize $EnableCustomize + $result = $true + + if ($state.ClientSettingStatus -eq 'Absent') + { + Write-Warning -Message ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + $result = $false + } + elseif ($state.PortalType -eq 'Company Portal') + { + Write-Warning -Message $script:localizedData.CompanyPortalMsg + $result = $false + } + elseif ($state.ClientType -eq 'User') + { + Write-Warning -Message $script:localizedData.WrongClientType + $result = $false + } + elseif ($EnableCustomize -eq $true) + { + if ($PSBoundParameters.ContainsKey('ColorScheme')) + { + $regexPrefix = '^(#|0x)?[0-9,a-f]*$' + + if ($ColorScheme.Length -ne 7 -or $ColorScheme.SubString(0,1) -ne '#' -or + $ColorScheme -notmatch $regexPrefix) + { + Write-Warning -Message ($script:localizedData.ColorSchemeErrorMsg -f $ColorScheme) + $badInput = $true + } + } + + $tabsCheck = @('EnableApplicationsTab','EnableUpdatesTab','EnableOperatingSystemsTab','EnableStatusTab', + 'EnableComplianceTab','EnableOptionsTab') + + foreach ($item in $tabsCheck) + { + if ($PSBoundParameters.ContainsKey($item)) + { + $itemValue = Get-Variable -Name $item + $arrayOfTabs += @{ + $item = $itemValue.Value + } + } + else + { + if ([string]::IsNullOrEmpty($state.$item) -or $state.$item -eq $true) + { + $arrayOfTabs += @{ + $item = $true + } + } + else + { + $arrayOfTabs += @{ + $item = $false + } + } + } + } + + if ($arrayOfTabs.Values -notcontains $true) + { + Write-Warning -Message $script:localizedData.TabsDisabled + } + + $defaultValues = @('EnableCustomize','CompanyName','ColorScheme','HideApplicationCatalogLink', + 'HideInstalledApplication','HideUnapprovedApplication','EnableApplicationsTab', + 'EnableUpdatesTab','EnableOperatingSystemsTab','EnableStatusTab', + 'EnableComplianceTab','EnableOptionsTab') + + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = $defaultValues + } + + $result = Test-DscParameterState @testParams -TurnOffTypeChecking -Verbose + } + elseif ($state.EnableCustomize -eq $true) + { + if ($PSBoundParameters.Keys.Count -ge 4) + { + Write-Warning -Message $script:localizedData.DisableIgnore + } + + Write-Verbose -Message $script:localizedData.TestDisabled + $result = $false + } + + if ($result -eq $false -or $badInput -eq $true) + { + $return = $false + } + else + { + $return = $true + } + + Write-Verbose -Message ($script:localizedData.TestState -f $return) + Set-Location -Path "$env:temp" + return $return +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettingsSoftwareCenter/DSC_CMClientSettingsSoftwareCenter.schema.mof b/source/DSCResources/DSC_CMClientSettingsSoftwareCenter/DSC_CMClientSettingsSoftwareCenter.schema.mof new file mode 100644 index 00000000..1913a927 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsSoftwareCenter/DSC_CMClientSettingsSoftwareCenter.schema.mof @@ -0,0 +1,21 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettingsSoftwareCenter")] +class DSC_CMClientSettingsSoftwareCenter : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Required, Description("Specifies if custom software center is to be used.")] Boolean EnableCustomize; + [Write, Description("Specifies the company name to be used in software center.")] String CompanyName; + [Write, Description("Specifies in hex format the color to be used in software center.")] String ColorScheme; + [Write, Description("Specifies if application catalog link is hidden.")] Boolean HideApplicationCatalogLink; + [Write, Description("Specifies if installed applications are hidden.")] Boolean HideInstalledApplication; + [Write, Description("Specifies if unapproved applications are hidden.")] Boolean HideUnapprovedApplication; + [Write, Description("Specifies if application tab is visible.")] Boolean EnableApplicationsTab; + [Write, Description("Specifies if updates tab is visible.")] Boolean EnableUpdatesTab; + [Write, Description("Specifies if operating system tab is visible.")] Boolean EnableOperatingSystemsTab; + [Write, Description("Specifies if status tab is visible.")] Boolean EnableStatusTab; + [Write, Description("Specifies if compliance tab is visible.")] Boolean EnableComplianceTab; + [Write, Description("Specifies if options tab is visible.")] Boolean EnableOptionsTab; + [Read, Description("Specifies if the client settings policy exists.")] String ClientSettingStatus; + [Read, Description("Specifies the type of client policy setting.")] String ClientType; + [Read, Description("Specifies the portal type selected.")] String PortalType; +}; diff --git a/source/DSCResources/DSC_CMClientSettingsSoftwareCenter/en-US/DSC_CMClientSettingsSoftwareCenter.strings.psd1 b/source/DSCResources/DSC_CMClientSettingsSoftwareCenter/en-US/DSC_CMClientSettingsSoftwareCenter.strings.psd1 new file mode 100644 index 00000000..1dc0a991 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsSoftwareCenter/en-US/DSC_CMClientSettingsSoftwareCenter.strings.psd1 @@ -0,0 +1,12 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy for software center. + ClientPolicySetting = Client Policy Setting {0} does not exist, and will need to be created prior to making client setting changes. + TestState = Test-TargetResource compliance check returned: {0}. + TestDisabled = Not Match: EnableCustomize currently is enabled and should be disabled. + SettingValue = Setting value: {0} to {1}. + WrongClientType = Client Settings for Software Center only applies to default and device client settings. + ColorSchemeErrorMsg = ColorSchema is not formated correct: {0}, example format would be #CB4154. + CompanyPortalMsg = Software Center is currently set to use Company Portal in order to modify these settings, you must manually set client policy to Software Center. + DisableIgnore = Currently setting EnableCustomize to false all other parameters specified will be ignored. + TabsDisabled = With the settings specified all Tabs will be put into a disabled state, you must have at least one tab enabled. +'@ diff --git a/source/DSCResources/DSC_CMClientSettingsSoftwareDeployment/DSC_CMClientSettingsSoftwareDeployment.psm1 b/source/DSCResources/DSC_CMClientSettingsSoftwareDeployment/DSC_CMClientSettingsSoftwareDeployment.psm1 new file mode 100644 index 00000000..b8f4dcf4 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsSoftwareDeployment/DSC_CMClientSettingsSoftwareDeployment.psm1 @@ -0,0 +1,344 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + $type = @('Default','Device','User')[$clientSetting.Type] + $settings = Get-CMClientSetting -Name $ClientSettingName -Setting SoftwareDeployment + + if ($settings) + { + $schedule = Get-CMSchedule -ScheduleString $settings.EvaluationSchedule + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + Start = $schedule.Start + ScheduleType = $schedule.ScheduleType + DayOfWeek = $schedule.DayofWeek + MonthlyWeekOrder = $schedule.WeekOrder + DayofMonth = $schedule.MonthDay + RecurInterval = $schedule.RecurInterval + ClientSettingStatus = $status + ClientType = $type + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER Start + Specifies the start date and start time for the software deployment schedule Month/Day/Year, example 1/1/2020 02:00. + + .PARAMETER ScheduleType + Specifies the schedule type for the software deployment schedule. + + .PARAMETER RecurInterval + Specifies how often the ScheduleType is run. + + .PARAMETER MonthlyByWeek + Specifies week order for MonthlyByWeek schedule type. + + .PARAMETER DayOfWeek + Specifies the day of week name for MonthlyByWeek and Weekly schedules. + + .PARAMETER DayOfMonth + Specifies the day number for MonthlyByDay schedules. + Note specifying 0 sets the schedule to run the last day of the month. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [String] + $Start, + + [Parameter()] + [ValidateSet('MonthlyByDay','MonthlyByWeek','Weekly','Days','Hours','Minutes','None')] + [String] + $ScheduleType, + + [Parameter()] + [UInt32] + $RecurInterval, + + [Parameter()] + [ValidateSet('First','Second','Third','Fourth','Last')] + [String] + $MonthlyWeekOrder, + + [Parameter()] + [ValidateSet('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')] + [String] + $DayOfWeek, + + [Parameter()] + [ValidateRange(0,31)] + [UInt32] + $DayOfMonth + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + $schedResult = $true + + try + { + if ($state.ClientSettingStatus -eq 'Absent') + { + throw ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + } + + if ($state.ClientType -eq 'User') + { + throw $script:localizedData.WrongClientType + } + + if ((-not $PSBoundParameters.ContainsKey('ScheduleType')) -and ($PSBoundParameters.ContainsKey('Start') -or + $PSBoundParameters.ContainsKey('RecurInterval') -or $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('DayOfWeek') -or $PSBoundParameters.ContainsKey('DayOfMonth'))) + { + throw $script:localizedData.RequiredSchedule + } + + if ($ScheduleType) + { + $valuesToValidate = @('ScheduleType','RecurInterval','MonthlyWeekOrder','DayOfWeek','DayOfMonth','Start') + foreach ($item in $valuesToValidate) + { + if ($PSBoundParameters.ContainsKey($item)) + { + $scheduleCheck += @{ + $item = $PSBoundParameters[$item] + } + } + } + + $schedResult = Test-CMSchedule @scheduleCheck -State $state + } + + if ($schedResult -eq $false) + { + $sched = Set-CMSchedule @scheduleCheck + $newSchedule = New-CMSchedule @sched + + Write-Verbose -Message $script:localizedData.NewSchedule + + $buildingParams += @{ + Schedule = $newSchedule + } + } + + if ($buildingParams) + { + if ($state.ClientType -eq 'Default') + { + Set-CMClientSettingSoftwareDeployment -DefaultSetting @buildingParams + } + else + { + Set-CMClientSettingSoftwareDeployment -Name $ClientSettingName @buildingParams + } + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER Start + Specifies the start date and start time for the software deployment schedule Month/Day/Year, example 1/1/2020 02:00. + + .PARAMETER ScheduleType + Specifies the schedule type for the software deployment schedule. + + .PARAMETER RecurInterval + Specifies how often the ScheduleType is run. + + .PARAMETER MonthlyByWeek + Specifies week order for MonthlyByWeek schedule type. + + .PARAMETER DayOfWeek + Specifies the day of week name for MonthlyByWeek and Weekly schedules. + + .PARAMETER DayOfMonth + Specifies the day number for MonthlyByDay schedules. + Note specifying 0 sets the schedule to run the last day of the month. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [String] + $Start, + + [Parameter()] + [ValidateSet('MonthlyByDay','MonthlyByWeek','Weekly','Days','Hours','Minutes','None')] + [String] + $ScheduleType, + + [Parameter()] + [UInt32] + $RecurInterval, + + [Parameter()] + [ValidateSet('First','Second','Third','Fourth','Last')] + [String] + $MonthlyWeekOrder, + + [Parameter()] + [ValidateSet('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')] + [String] + $DayOfWeek, + + [Parameter()] + [ValidateRange(0,31)] + [UInt32] + $DayOfMonth + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + $result = $true + + if ($state.ClientSettingStatus -eq 'Absent') + { + Write-Warning -Message ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + $result = $false + } + elseif ($state.ClientType -eq 'User') + { + Write-Warning -Message $script:localizedData.WrongClientType + $result = $false + } + else + { + if ((-not $PSBoundParameters.ContainsKey('ScheduleType')) -and ($PSBoundParameters.ContainsKey('Start') -or + $PSBoundParameters.ContainsKey('RecurInterval') -or $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('DayOfWeek') -or $PSBoundParameters.ContainsKey('DayOfMonth'))) + { + Write-Warning -Message $script:localizedData.RequiredSchedule + $badInput = $true + } + + if ($ScheduleType) + { + $valuesToValidate = @('ScheduleType','RecurInterval','MonthlyWeekOrder','DayOfWeek','DayOfMonth','Start') + foreach ($item in $valuesToValidate) + { + if ($PSBoundParameters.ContainsKey($item)) + { + $scheduleCheck += @{ + $item = $PSBoundParameters[$item] + } + } + } + + $result = Test-CMSchedule @scheduleCheck -State $state + } + } + + if ($result -eq $false -or $badInput -eq $true) + { + $return = $false + } + else + { + $return = $true + } + + Write-Verbose -Message ($script:localizedData.TestState -f $return) + Set-Location -Path "$env:temp" + return $return +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettingsSoftwareDeployment/DSC_CMClientSettingsSoftwareDeployment.schema.mof b/source/DSCResources/DSC_CMClientSettingsSoftwareDeployment/DSC_CMClientSettingsSoftwareDeployment.schema.mof new file mode 100644 index 00000000..f4cc6c9d --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsSoftwareDeployment/DSC_CMClientSettingsSoftwareDeployment.schema.mof @@ -0,0 +1,14 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettingsSoftwareDeployment")] +class DSC_CMClientSettingsSoftwareDeployment : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Write, Description("Specifies the start date and start time for the software deployment schedule Month/Day/Year, example 1/1/2020 02:00.")] String Start; + [Write, Description("Specifies the schedule type for the software deployment schedule."), ValueMap{"MonthlyByDay","MonthlyByWeek","Weekly","Days","Hours","Minutes","None"}, Values{"MonthlyByDay","MonthlyByWeek","Weekly","Days","Hours","Minutes","None"}] String ScheduleType; + [Write, Description("Specifies how often the ScheduleType is run.")] UInt32 RecurInterval; + [Write, Description("Specifies week order for MonthlyByWeek schedule type."), ValueMap{"First","Second","Third","Fourth","Last"}, Values{"First","Second","Third","Fourth","Last"}] String MonthlyWeekOrder; + [Write, Description("Specifies the day of week name for MonthlyByWeek and Weekly schedules."), ValueMap{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}, Values{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}] String DayOfWeek; + [Write, Description("Specifies the day number for MonthlyByDay schedules.")] UInt32 DayOfMonth; + [Read, Description("Specifies if the client settings policy exists.")] String ClientSettingStatus; + [Read, Description("Specifies the type of client policy setting.")] String ClientType; +}; diff --git a/source/DSCResources/DSC_CMClientSettingsSoftwareDeployment/en-US/DSC_CMClientSettingsSoftwareDeployment.strings.psd1 b/source/DSCResources/DSC_CMClientSettingsSoftwareDeployment/en-US/DSC_CMClientSettingsSoftwareDeployment.strings.psd1 new file mode 100644 index 00000000..40407c7b --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsSoftwareDeployment/en-US/DSC_CMClientSettingsSoftwareDeployment.strings.psd1 @@ -0,0 +1,8 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy for software deployment settings. + ClientPolicySetting = Client Policy Setting {0} does not exist, and will need to be created prior to making client setting changes. + TestState = Test-TargetResource compliance check returned: {0}. + NewSchedule = Modifying software deployment schedule. + RequiredSchedule = In order to create a schedule you must specify ScheduleType. + WrongClientType = Client Settings for software deployment only applies to Default and Device Client settings. +'@ diff --git a/source/DSCResources/DSC_CMClientSettingsSoftwareInventory/DSC_CMClientSettingsSoftwareInventory.psm1 b/source/DSCResources/DSC_CMClientSettingsSoftwareInventory/DSC_CMClientSettingsSoftwareInventory.psm1 new file mode 100644 index 00000000..2d6b8530 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsSoftwareInventory/DSC_CMClientSettingsSoftwareInventory.psm1 @@ -0,0 +1,456 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Enable + Specifies if sofware inventory on clients is enabled or disabled. + Not used in Get +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $Enable + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + $type = @('Default','Device','User')[$clientSetting.Type] + $settings = Get-CMClientSetting -Name $ClientSettingName -Setting SoftwareInventory + + if ($settings) + { + $enabled = [System.Convert]::ToBoolean($settings.Enabled) + + if ($enabled -eq $true) + { + $schedule = Get-CMSchedule -ScheduleString $settings.Schedule + + $report = switch ($settings.ReportOptions) + { + '1' { 'ProductOnly' } + '2' { 'FileOnly' } + '7' { 'FullDetail' } + } + } + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + Enable = $enabled + ReportOption = $report + Start = $schedule.Start + ScheduleType = $schedule.ScheduleType + DayOfWeek = $schedule.DayofWeek + MonthlyWeekOrder = $schedule.WeekOrder + DayofMonth = $schedule.MonthDay + RecurInterval = $schedule.RecurInterval + ClientSettingStatus = $status + ClientType = $type + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Enable + Specifies if software inventory for clients is enabled or disabled. + + .Parameter ReportOption + Specify reporting inventory details level. + + .PARAMETER Start + Specifies the start date and start time for the software inventory schedule Month/Day/Year, example 1/1/2020 02:00. + + .PARAMETER ScheduleType + Specifies the schedule type for the software inventory schedule. + + .PARAMETER RecurInterval + Specifies how often the ScheduleType is run. + + .PARAMETER MonthlyByWeek + Specifies week order for MonthlyByWeek schedule type. + + .PARAMETER DayOfWeek + Specifies the day of week name for MonthlyByWeek and Weekly schedules. + + .PARAMETER DayOfMonth + Specifies the day number for MonthlyByDay schedules. + Note specifying 0 sets the schedule to run the last day of the month. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $Enable, + + [Parameter()] + [ValidateSet('ProductOnly','FileOnly','FullDetail')] + [String] + $ReportOption, + + [Parameter()] + [String] + $Start, + + [Parameter()] + [ValidateSet('MonthlyByDay','MonthlyByWeek','Weekly','Days','Hours','Minutes','None')] + [String] + $ScheduleType, + + [Parameter()] + [UInt32] + $RecurInterval, + + [Parameter()] + [ValidateSet('First','Second','Third','Fourth','Last')] + [String] + $MonthlyWeekOrder, + + [Parameter()] + [ValidateSet('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')] + [String] + $DayOfWeek, + + [Parameter()] + [ValidateRange(0,31)] + [UInt32] + $DayOfMonth + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName -Enable $Enable + $schedResult = $true + + try + { + if ($state.ClientSettingStatus -eq 'Absent') + { + throw ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + } + + if ($state.ClientType -eq 'User') + { + throw $script:localizedData.WrongClientType + } + + if ($Enable -eq $true) + { + if ((-not $PSBoundParameters.ContainsKey('ScheduleType')) -and ($PSBoundParameters.ContainsKey('Start') -or + $PSBoundParameters.ContainsKey('RecurInterval') -or $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('DayOfWeek') -or $PSBoundParameters.ContainsKey('DayOfMonth'))) + { + throw $script:localizedData.RequiredSchedule + } + + $defaultValues = @('Enable','ReportOption') + + foreach ($param in $PSBoundParameters.GetEnumerator()) + { + if ($defaultValues -contains $param.Key) + { + if ($param.Value -ne $state[$param.Key]) + { + Write-Verbose -Message ($script:localizedData.SettingValue -f $param.Key, $param.Value) + $buildingParams += @{ + $param.Key = $param.Value + } + } + } + } + + if ($ScheduleType) + { + $valuesToValidate = @('ScheduleType','RecurInterval','MonthlyWeekOrder','DayOfWeek','DayOfMonth','Start') + foreach ($item in $valuesToValidate) + { + if ($PSBoundParameters.ContainsKey($item)) + { + $scheduleCheck += @{ + $item = $PSBoundParameters[$item] + } + } + } + + $schedResult = Test-CMSchedule @scheduleCheck -State $state + } + + if ($schedResult -eq $false) + { + $sched = Set-CMSchedule @scheduleCheck + $newSchedule = New-CMSchedule @sched + + Write-Verbose -Message $script:localizedData.NewSchedule + $buildingParams += @{ + Schedule = $newSchedule + } + } + } + elseif ($state.Enable -eq $true) + { + if ($PSBoundParameters.ContainsKey('Start') -or $PSBoundParameters.ContainsKey('ScheduleType') -or + $PSBoundParameters.ContainsKey('RecurInterval') -or $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('DayOfWeek') -or $PSBoundParameters.ContainsKey('DayOfMonth') -or + $PSBoundParameters.ContainsKey('ReportOption')) + { + Write-Warning -Message $script:localizedData.EnableFalse + } + + $buildingParams = @{ + Enable = $false + } + } + + if ($buildingParams) + { + if ($state.ClientType -eq 'Default') + { + Set-CMClientSettingSoftwareInventory -DefaultSetting @buildingParams + } + else + { + Set-CMClientSettingSoftwareInventory -Name $ClientSettingName @buildingParams + } + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Enable + Specifies if software inventory for clients is enabled or disabled. + + .Parameter ReportOption + Specify reporting inventory details level. + + .PARAMETER Start + Specifies the start date and start time for the software inventory schedule Month/Day/Year, example 1/1/2020 02:00. + + .PARAMETER ScheduleType + Specifies the schedule type for the software inventory schedule. + + .PARAMETER RecurInterval + Specifies how often the ScheduleType is run. + + .PARAMETER MonthlyByWeek + Specifies week order for MonthlyByWeek schedule type. + + .PARAMETER DayOfWeek + Specifies the day of week name for MonthlyByWeek and Weekly schedules. + + .PARAMETER DayOfMonth + Specifies the day number for MonthlyByDay schedules. + Note specifying 0 sets the schedule to run the last day of the month. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $Enable, + + [Parameter()] + [ValidateSet('ProductOnly','FileOnly','FullDetail')] + [String] + $ReportOption, + + [Parameter()] + [String] + $Start, + + [Parameter()] + [ValidateSet('MonthlyByDay','MonthlyByWeek','Weekly','Days','Hours','Minutes','None')] + [String] + $ScheduleType, + + [Parameter()] + [UInt32] + $RecurInterval, + + [Parameter()] + [ValidateSet('First','Second','Third','Fourth','Last')] + [String] + $MonthlyWeekOrder, + + [Parameter()] + [ValidateSet('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')] + [String] + $DayOfWeek, + + [Parameter()] + [ValidateRange(0,31)] + [UInt32] + $DayOfMonth + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName -Enable $Enable + $result = $true + $schedResult = $true + + if ($state.ClientSettingStatus -eq 'Absent') + { + Write-Warning -Message ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + $result = $false + } + elseif ($state.ClientType -eq 'User') + { + Write-Warning -Message $script:localizedData.WrongClientType + $result = $false + } + else + { + if ($Enable -eq $true) + { + if ((-not $PSBoundParameters.ContainsKey('ScheduleType')) -and ($PSBoundParameters.ContainsKey('Start') -or + $PSBoundParameters.ContainsKey('RecurInterval') -or $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('DayOfWeek') -or $PSBoundParameters.ContainsKey('DayOfMonth'))) + { + Write-Warning -Message $script:localizedData.RequiredSchedule + $badInput = $true + } + + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = @('Enable','ReportOption') + } + + $result = Test-DscParameterState @testParams -TurnOffTypeChecking -Verbose + + if ($ScheduleType) + { + $valuesToValidate = @('ScheduleType','RecurInterval','MonthlyWeekOrder','DayOfWeek','DayOfMonth','Start') + foreach ($item in $valuesToValidate) + { + if ($PSBoundParameters.ContainsKey($item)) + { + $scheduleCheck += @{ + $item = $PSBoundParameters[$item] + } + } + } + + $schedResult = Test-CMSchedule @scheduleCheck -State $state + } + } + else + { + if ($PSBoundParameters.ContainsKey('Start') -or $PSBoundParameters.ContainsKey('ScheduleType') -or + $PSBoundParameters.ContainsKey('RecurInterval') -or $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('DayOfWeek') -or $PSBoundParameters.ContainsKey('DayOfMonth') -or + $PSBoundParameters.ContainsKey('ReportOption')) + { + Write-Warning -Message $script:localizedData.EnableFalse + } + + if ($state.Enable -eq $true) + { + Write-Verbose -Message $script:localizedData.TestDisabled + $result = $false + } + } + } + + if ($result -eq $false -or $schedResult -eq $false -or $badInput -eq $true) + { + $return = $false + } + else + { + $return = $true + } + + Write-Verbose -Message ($script:localizedData.TestState -f $return) + Set-Location -Path "$env:temp" + return $return +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettingsSoftwareInventory/DSC_CMClientSettingsSoftwareInventory.schema.mof b/source/DSCResources/DSC_CMClientSettingsSoftwareInventory/DSC_CMClientSettingsSoftwareInventory.schema.mof new file mode 100644 index 00000000..171148e4 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsSoftwareInventory/DSC_CMClientSettingsSoftwareInventory.schema.mof @@ -0,0 +1,16 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettingsSoftwareInventory")] +class DSC_CMClientSettingsSoftwareInventory : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Required, Description("Specifies if software inventory on clients is enabled or disabled.")] Boolean Enable; + [Write, Description("Specify reporting inventory details level."), ValueMap{"ProductOnly","FileOnly","FullDetail"}, Values{"ProductOnly","FileOnly","FullDetail"}] String ReportOption; + [Write, Description("Specifies the start date and start time for the software inventory schedule Month/Day/Year, example 1/1/2020 02:00.")] String Start; + [Write, Description("Specifies the schedule type for the software inventory schedule."), ValueMap{"MonthlyByDay","MonthlyByWeek","Weekly","Days","Hours","Minutes","None"}, Values{"MonthlyByDay","MonthlyByWeek","Weekly","Days","Hours","Minutes","None"}] String ScheduleType; + [Write, Description("Specifies how often the ScheduleType is run.")] UInt32 RecurInterval; + [Write, Description("Specifies week order for MonthlyByWeek schedule type."), ValueMap{"First","Second","Third","Fourth","Last"}, Values{"First","Second","Third","Fourth","Last"}] String MonthlyWeekOrder; + [Write, Description("Specifies the day of week name for MonthlyByWeek and Weekly schedules."), ValueMap{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}, Values{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}] String DayOfWeek; + [Write, Description("Specifies the day number for MonthlyByDay schedules.")] UInt32 DayOfMonth; + [Read, Description("Specifies if the client settings policy exists.")] String ClientSettingStatus; + [Read, Description("Specifies the type of client policy setting.")] String ClientType; +}; diff --git a/source/DSCResources/DSC_CMClientSettingsSoftwareInventory/en-US/DSC_CMClientSettingsSoftwareInventory.strings.psd1 b/source/DSCResources/DSC_CMClientSettingsSoftwareInventory/en-US/DSC_CMClientSettingsSoftwareInventory.strings.psd1 new file mode 100644 index 00000000..b423ba0f --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsSoftwareInventory/en-US/DSC_CMClientSettingsSoftwareInventory.strings.psd1 @@ -0,0 +1,11 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy for software inventory settings. + ClientPolicySetting = Client Policy Setting {0} does not exist, and will need to be created prior to making client setting changes. + TestState = Test-TargetResource compliance check returned: {0}. + TestDisabled = Enabled currently is enabled and should be disabled. + SettingValue = Setting value: {0} to {1}. + NewSchedule = Modifying software inventory schedule. + RequiredSchedule = In order to create a schedule you must specify ScheduleType. + WrongClientType = Client Settings for software inventory settings only applies to Default and Device client settings. + EnableFalse = In order to set a schedule or ReportOptions, Enable must be set to true, ignoring settings. +'@ diff --git a/source/DSCResources/DSC_CMClientSettingsSoftwareMetering/DSC_CMClientSettingsSoftwareMetering.psm1 b/source/DSCResources/DSC_CMClientSettingsSoftwareMetering/DSC_CMClientSettingsSoftwareMetering.psm1 new file mode 100644 index 00000000..dcdd8b86 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsSoftwareMetering/DSC_CMClientSettingsSoftwareMetering.psm1 @@ -0,0 +1,430 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Enable + Specifies if sofware metering on clients is enabled or disabled. + Not used in Get +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $Enable + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + $type = @('Default','Device','User')[$clientSetting.Type] + $settings = Get-CMClientSetting -Name $ClientSettingName -Setting SoftwareMetering + + if ($settings) + { + $enabled = [System.Convert]::ToBoolean($settings.Enabled) + if ($enabled -eq $true) + { + $schedule = Get-CMSchedule -ScheduleString $settings.DataCollectionSchedule + } + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + Enable = $enabled + Start = $schedule.Start + ScheduleType = $schedule.ScheduleType + DayOfWeek = $schedule.DayofWeek + MonthlyWeekOrder = $schedule.WeekOrder + DayofMonth = $schedule.MonthDay + RecurInterval = $schedule.RecurInterval + ClientSettingStatus = $status + ClientType = $type + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Enable + Specifies if software metering for clients is enabled or disabled. + + .PARAMETER Start + Specifies the start date and start time for the software metering schedule Month/Day/Year, example 1/1/2020 02:00. + + .PARAMETER ScheduleType + Specifies the schedule type for the software metering schedule. + + .PARAMETER RecurInterval + Specifies how often the ScheduleType is run. + + .PARAMETER MonthlyByWeek + Specifies week order for MonthlyByWeek schedule type. + + .PARAMETER DayOfWeek + Specifies the day of week name for MonthlyByWeek and Weekly schedules. + + .PARAMETER DayOfMonth + Specifies the day number for MonthlyByDay schedules. + Note specifying 0 sets the schedule to run the last day of the month. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $Enable, + + [Parameter()] + [String] + $Start, + + [Parameter()] + [ValidateSet('MonthlyByDay','MonthlyByWeek','Weekly','Days','Hours','Minutes','None')] + [String] + $ScheduleType, + + [Parameter()] + [UInt32] + $RecurInterval, + + [Parameter()] + [ValidateSet('First','Second','Third','Fourth','Last')] + [String] + $MonthlyWeekOrder, + + [Parameter()] + [ValidateSet('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')] + [String] + $DayOfWeek, + + [Parameter()] + [ValidateRange(0,31)] + [UInt32] + $DayOfMonth + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName -Enable $Enable + $schedResult = $true + + try + { + if ($state.ClientSettingStatus -eq 'Absent') + { + throw ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + } + + if ($state.ClientType -eq 'User') + { + throw $script:localizedData.WrongClientType + } + + if ($Enable -eq $true) + { + if ((-not $PSBoundParameters.ContainsKey('ScheduleType')) -and ($PSBoundParameters.ContainsKey('Start') -or + $PSBoundParameters.ContainsKey('RecurInterval') -or $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('DayOfWeek') -or $PSBoundParameters.ContainsKey('DayOfMonth'))) + { + throw $script:localizedData.RequiredSchedule + } + + $defaultValues = @('Enable') + + foreach ($param in $PSBoundParameters.GetEnumerator()) + { + if ($defaultValues -contains $param.Key) + { + if ($param.Value -ne $state[$param.Key]) + { + Write-Verbose -Message ($script:localizedData.SettingValue -f $param.Key, $param.Value) + $buildingParams += @{ + $param.Key = $param.Value + } + } + } + } + + if ($ScheduleType -and $state.ClientType -eq 'Default') + { + $valuesToValidate = @('ScheduleType','RecurInterval','MonthlyWeekOrder','DayOfWeek','DayOfMonth','Start') + foreach ($item in $valuesToValidate) + { + if ($PSBoundParameters.ContainsKey($item)) + { + $scheduleCheck += @{ + $item = $PSBoundParameters[$item] + } + } + } + + $schedResult = Test-CMSchedule @scheduleCheck -State $state + } + + if ($schedResult -eq $false) + { + $sched = Set-CMSchedule @scheduleCheck + $newSchedule = New-CMSchedule @sched + + Write-Verbose -Message $script:localizedData.NewSchedule + $buildingParams += @{ + Schedule = $newSchedule + } + } + } + elseif ($state.Enable -eq $true) + { + if ($PSBoundParameters.ContainsKey('EnableUserDataAndProfile') -or $PSBoundParameters.ContainsKey('Start') -or + $PSBoundParameters.ContainsKey('ScheduleType') -or $PSBoundParameters.ContainsKey('RecurInterval') -or + $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or $PSBoundParameters.ContainsKey('DayOfWeek') -or + $PSBoundParameters.ContainsKey('DayOfMonth')) + { + Write-Warning -Message $script:localizedData.EnableFalse + } + + $buildingParams = @{ + Enable = $false + } + } + + if ($buildingParams) + { + if ($state.ClientType -eq 'Default') + { + Set-CMClientSettingSoftwareMetering -DefaultSetting @buildingParams + } + else + { + Set-CMClientSettingSoftwareMetering -Name $ClientSettingName @buildingParams + } + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Enable + Specifies if software metering for clients is enabled or disabled. + + .PARAMETER Start + Specifies the start date and start time for the software metering schedule Month/Day/Year, example 1/1/2020 02:00. + + .PARAMETER ScheduleType + Specifies the schedule type for the software metering schedule. + + .PARAMETER RecurInterval + Specifies how often the ScheduleType is run. + + .PARAMETER MonthlyByWeek + Specifies week order for MonthlyByWeek schedule type. + + .PARAMETER DayOfWeek + Specifies the day of week name for MonthlyByWeek and Weekly schedules. + + .PARAMETER DayOfMonth + Specifies the day number for MonthlyByDay schedules. + Note specifying 0 sets the schedule to run the last day of the month. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $Enable, + + [Parameter()] + [String] + $Start, + + [Parameter()] + [ValidateSet('MonthlyByDay','MonthlyByWeek','Weekly','Days','Hours','Minutes','None')] + [String] + $ScheduleType, + + [Parameter()] + [UInt32] + $RecurInterval, + + [Parameter()] + [ValidateSet('First','Second','Third','Fourth','Last')] + [String] + $MonthlyWeekOrder, + + [Parameter()] + [ValidateSet('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')] + [String] + $DayOfWeek, + + [Parameter()] + [ValidateRange(0,31)] + [UInt32] + $DayOfMonth + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName -Enable $Enable + $result = $true + $schedResult = $true + + if ($state.ClientSettingStatus -eq 'Absent') + { + Write-Warning -Message ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + $result = $false + } + elseif ($state.ClientType -eq 'User') + { + Write-Warning -Message $script:localizedData.WrongClientType + $result = $false + } + else + { + if ($Enable -eq $true) + { + if ((-not $PSBoundParameters.ContainsKey('ScheduleType')) -and ($PSBoundParameters.ContainsKey('Start') -or + $PSBoundParameters.ContainsKey('RecurInterval') -or $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('DayOfWeek') -or $PSBoundParameters.ContainsKey('DayOfMonth'))) + { + Write-Warning -Message $script:localizedData.RequiredSchedule + $badInput = $true + } + + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = @('Enable') + } + + $result = Test-DscParameterState @testParams -TurnOffTypeChecking -Verbose + + if ($ScheduleType) + { + $valuesToValidate = @('ScheduleType','RecurInterval','MonthlyWeekOrder','DayOfWeek','DayOfMonth','Start') + foreach ($item in $valuesToValidate) + { + if ($PSBoundParameters.ContainsKey($item)) + { + $scheduleCheck += @{ + $item = $PSBoundParameters[$item] + } + } + } + + $schedResult = Test-CMSchedule @scheduleCheck -State $state + } + } + else + { + if ($PSBoundParameters.ContainsKey('Start') -or $PSBoundParameters.ContainsKey('ScheduleType') -or + $PSBoundParameters.ContainsKey('RecurInterval') -or $PSBoundParameters.ContainsKey('MonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('DayOfWeek') -or $PSBoundParameters.ContainsKey('DayOfMonth')) + { + Write-Warning -Message $script:localizedData.EnableFalse + } + + if ($state.Enable -eq $true) + { + Write-Verbose -Message $script:localizedData.TestDisabled + $result = $false + } + } + } + + if ($result -eq $false -or $schedResult -eq $false -or $badInput -eq $true) + { + $return = $false + } + else + { + $return = $true + } + + Write-Verbose -Message ($script:localizedData.TestState -f $return) + Set-Location -Path "$env:temp" + return $return +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettingsSoftwareMetering/DSC_CMClientSettingsSoftwareMetering.schema.mof b/source/DSCResources/DSC_CMClientSettingsSoftwareMetering/DSC_CMClientSettingsSoftwareMetering.schema.mof new file mode 100644 index 00000000..ab8b88df --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsSoftwareMetering/DSC_CMClientSettingsSoftwareMetering.schema.mof @@ -0,0 +1,15 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettingsSoftwareMetering")] +class DSC_CMClientSettingsSoftwareMetering : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Required, Description("Specifies if software metering on clients is enabled or disabled.")] Boolean Enable; + [Write, Description("Specifies the start date and start time for the software metering schedule Month/Day/Year, example 1/1/2020 02:00.")] String Start; + [Write, Description("Specifies the schedule type for the software metering schedule."), ValueMap{"MonthlyByDay","MonthlyByWeek","Weekly","Days","Hours","Minutes","None"}, Values{"MonthlyByDay","MonthlyByWeek","Weekly","Days","Hours","Minutes","None"}] String ScheduleType; + [Write, Description("Specifies how often the ScheduleType is run.")] UInt32 RecurInterval; + [Write, Description("Specifies week order for MonthlyByWeek schedule type."), ValueMap{"First","Second","Third","Fourth","Last"}, Values{"First","Second","Third","Fourth","Last"}] String MonthlyWeekOrder; + [Write, Description("Specifies the day of week name for MonthlyByWeek and Weekly schedules."), ValueMap{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}, Values{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}] String DayOfWeek; + [Write, Description("Specifies the day number for MonthlyByDay schedules.")] UInt32 DayOfMonth; + [Read, Description("Specifies if the client settings policy exists.")] String ClientSettingStatus; + [Read, Description("Specifies the type of client policy setting.")] String ClientType; +}; diff --git a/source/DSCResources/DSC_CMClientSettingsSoftwareMetering/en-US/DSC_CMClientSettingsSoftwareMetering.strings.psd1 b/source/DSCResources/DSC_CMClientSettingsSoftwareMetering/en-US/DSC_CMClientSettingsSoftwareMetering.strings.psd1 new file mode 100644 index 00000000..a2cf50f0 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsSoftwareMetering/en-US/DSC_CMClientSettingsSoftwareMetering.strings.psd1 @@ -0,0 +1,11 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy for software metering settings. + ClientPolicySetting = Client Policy Setting {0} does not exist, and will need to be created prior to making client setting changes. + TestState = Test-TargetResource compliance check returned: {0}. + TestDisabled = Enabled currently is enabled and should be disabled. + SettingValue = Setting value: {0} to {1}. + NewSchedule = Modifying software metering schedule. + RequiredSchedule = In order to create a schedule you must specify ScheduleType. + WrongClientType = Client Settings for software metering settings only applies to Default and Device client settings. + EnableFalse = In order to set a schedule, Enable must be set to true, ignoring settings. +'@ diff --git a/source/DSCResources/DSC_CMClientSettingsSoftwareUpdate/DSC_CMClientSettingsSoftwareUpdate.psm1 b/source/DSCResources/DSC_CMClientSettingsSoftwareUpdate/DSC_CMClientSettingsSoftwareUpdate.psm1 new file mode 100644 index 00000000..3711fdc8 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsSoftwareUpdate/DSC_CMClientSettingsSoftwareUpdate.psm1 @@ -0,0 +1,850 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Enable + Specifies if software update policy is enabled or disabled. + Not Used in Get. +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $Enable + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + $type = @('Default','Device','User')[$clientSetting.Type] + $settings = Get-CMClientSetting -Name $ClientSettingName -Setting SoftwareUpdates + + if ($settings) + { + $enabled = [System.Convert]::ToBoolean($settings.Enabled) + + if ($enabled -eq $true) + { + $scanSchedule = Get-CMSchedule -ScheduleString $settings.ScanSchedule + $evalSchedule = Get-CMSchedule -ScheduleString $settings.EvaluationSchedule + + if ([UInt32]$settings.AssignmentBatchingTimeout -eq 0) + { + $enforce = $false + } + elseif ([UInt32]$settings.AssignmentBatchingTimeout -ge 86400) + { + $enforce = $true + $unitTime = 'Days' + $finalValue = $($settings.AssignmentBatchingTimeout)/86400 + } + else + { + $enforce = $true + $unitTime = 'Hours' + $finalValue = $settings.AssignmentBatchingTimeout/3600 + } + + $express = [System.Convert]::ToBoolean($settings.EnableExpressUpdates) + $expressPort = [UInt32]$settings.ExpressUpdatesPort + $office = @('NotConfigured','Yes','No')[$settings.O365Management] + $thirdParty = [System.Convert]::ToBoolean($settings.EnableThirdPartyUpdates) + } + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + Enable = $enabled + ScanStart = $scanSchedule.Start + ScanScheduleType = $scanSchedule.ScheduleType + ScanDayOfWeek = $scanSchedule.DayofWeek + ScanMonthlyWeekOrder = $scanSchedule.WeekOrder + ScanDayofMonth = $scanSchedule.MonthDay + ScanRecurInterval = $scanSchedule.RecurInterval + EvalStart = $evalSchedule.Start + EvalScheduleType = $evalSchedule.ScheduleType + EvalDayOfWeek = $evalSchedule.DayofWeek + EvalMonthlyWeekOrder = $evalSchedule.WeekOrder + EvalDayofMonth = $evalSchedule.MonthDay + EvalRecurInterval = $evalSchedule.RecurInterval + EnforceMandatory = $enforce + TimeUnit = $unitTime + BatchingTimeout = $finalValue + EnableDeltaDownload = $express + DeltaDownloadPort = $expressPort + Office365ManagementType = $office + EnableThirdPartyUpdates = $thirdParty + ClientSettingStatus = $status + ClientType = $type + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Enable + Specifies if software update for clients is enabled or disabled. + + .PARAMETER ScanStart + Specifies the start date and start time for the software update scan schedule Month/Day/Year, example 1/1/2020 02:00. + + .PARAMETER ScanScheduleType + Specifies the schedule type for the software update scan schedule. + + .PARAMETER ScanRecurInterval + Specifies how often the ScanScheduleType is run. + + .PARAMETER ScanMonthlyByWeek + Specifies week order for MonthlyByWeek scan schedule type. + + .PARAMETER ScanDayOfWeek + Specifies the day of week name for MonthlyByWeek and Weekly scan schedules. + + .PARAMETER ScanDayOfMonth + Specifies the day number for MonthlyByDay scan schedules. + Note specifying 0 sets the schedule to run the last day of the month. + + .PARAMETER EvalStart + Specifies the start date and start time for the software update eval schedule Month/Day/Year, example 1/1/2020 02:00. + + .PARAMETER EvalScheduleType + Specifies the schedule type for the software update eval schedule. + + .PARAMETER EvalRecurInterval + Specifies how often the EvalScheduleType is run. + + .PARAMETER EvalMonthlyByWeek + Specifies week order for MonthlyByWeek eval schedule type. + + .PARAMETER EvalDayOfWeek + Specifies the day of week name for MonthlyByWeek and Weekly eval schedules. + + .PARAMETER EvalDayOfMonth + Specifies the day number for MonthlyByDay eval schedules. + Note specifying 0 sets the schedule to run the last day of the month. + + .Parameter EnforceMandatory + Specifies if any software update deployment deadline is + reached to install all deployments with dealing coming within a specific time period. + + .Parameter TimeUnit + Specifies the unit of time, hours or days time frame to install pending software updates. + + .Parameter BatchingTimeOut + Specifies the time within TimeUnit to install the depending updates. + + .Parameter EnableDeltaDownload + Specifies if client are allowed to download delta content when available. + + .Parameter DeltaDownloadPort + Specifies the port that clients will use to receive requests for delta content. + + .Parameter Office365ManagementType + Specifies the management of the Office 365 client. + + .Parameter EnableThirdPartyUpdates + Specifies if third party updates is enabled or disabled. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $Enable, + + [Parameter()] + [String] + $ScanStart, + + [Parameter()] + [ValidateSet('MonthlyByDay','MonthlyByWeek','Weekly','Days','Hours','Minutes','None')] + [String] + $ScanScheduleType, + + [Parameter()] + [UInt32] + $ScanRecurInterval, + + [Parameter()] + [ValidateSet('First','Second','Third','Fourth','Last')] + [String] + $ScanMonthlyWeekOrder, + + [Parameter()] + [ValidateSet('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')] + [String] + $ScanDayOfWeek, + + [Parameter()] + [ValidateRange(0,31)] + [UInt32] + $ScanDayOfMonth, + + [Parameter()] + [String] + $EvalStart, + + [Parameter()] + [ValidateSet('MonthlyByDay','MonthlyByWeek','Weekly','Days','Hours','Minutes','None')] + [String] + $EvalScheduleType, + + [Parameter()] + [UInt32] + $EvalRecurInterval, + + [Parameter()] + [ValidateSet('First','Second','Third','Fourth','Last')] + [String] + $EvalMonthlyWeekOrder, + + [Parameter()] + [ValidateSet('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')] + [String] + $EvalDayOfWeek, + + [Parameter()] + [ValidateRange(0,31)] + [UInt32] + $EvalDayOfMonth, + + [Parameter()] + [Boolean] + $EnforceMandatory, + + [Parameter()] + [ValidateSet('Hours','Days')] + [String] + $TimeUnit, + + [Parameter()] + [ValidateRange(1,365)] + [UInt32] + $BatchingTimeOut, + + [Parameter()] + [Boolean] + $EnableDeltaDownload, + + [Parameter()] + [UInt32] + $DeltaDownloadPort, + + [Parameter()] + [ValidateSet('NotConfigured','Yes','No')] + [String] + $Office365ManagementType, + + [Parameter()] + [Boolean] + $EnableThirdPartyUpdates + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName -Enable $Enable + $schedResult = $true + + try + { + if ($state.ClientSettingStatus -eq 'Absent') + { + throw ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + } + + if ($state.ClientType -eq 'User') + { + throw $script:localizedData.WrongClientType + } + + if ($Enable -eq $true) + { + if ((-not $PSBoundParameters.ContainsKey('ScanScheduleType')) -and ($PSBoundParameters.ContainsKey('ScanStart') -or + $PSBoundParameters.ContainsKey('ScanRecurInterval') -or $PSBoundParameters.ContainsKey('ScanMonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('ScanDayOfWeek') -or $PSBoundParameters.ContainsKey('ScanDayOfMonth'))) + { + throw $script:localizedData.RequiredSchedule + } + + if ((-not $PSBoundParameters.ContainsKey('EvalScheduleType')) -and ($PSBoundParameters.ContainsKey('EvalStart') -or + $PSBoundParameters.ContainsKey('EvalRecurInterval') -or $PSBoundParameters.ContainsKey('EvalMonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('EvalDayOfWeek') -or $PSBoundParameters.ContainsKey('EvalDayOfMonth'))) + { + throw $script:localizedData.RequiredSchedule + } + + $defaultValues = @('Enable','EnforceMandatory','EnableDeltaDownload','EnableThirdPartyUpdates') + + if ($EnableDeltaDownload -eq $false -and $PSBoundParameters.ContainsKey('DeltaDownloadPort')) + { + Write-Warning -Message $script:localizedData.DeltaPortIgnore + } + else + { + $defaultValues += 'DeltaDownloadPort' + } + + if ($EnforceMandatory -eq $true) + { + $defaultValues += ('TimeUnit','BatchingTimeOut') + if (-not $PSBoundParameters.ContainsKey('TimeUnit') -or -not $PSBoundParameters.ContainsKey('BatchingTimeOut')) + { + throw $script:localizedData.MissingEnforce + } + + if ($TimeUnit -eq 'Hours' -and $BatchingTimeOut -gt 23) + { + Write-Warning -Message $script:localizedData.MaxBatchHours + $PSBoundParameters.Remove('BatchingTimeOut') | Out-Null + $PSBoundParameters.Add('BatchingTimeOut',23) + } + } + elseif ($PSBoundParameters.ContainsKey('TimeUnit') -or $PSBoundParameters.ContainsKey('BatchingTimeOut')) + { + Write-Warning -Message $script:localizedData.TimeBatchIgnore + } + + foreach ($param in $PSBoundParameters.GetEnumerator()) + { + if ($defaultValues -contains $param.Key) + { + if ($param.Value -ne $state[$param.Key]) + { + Write-Verbose -Message ($script:localizedData.SettingValue -f $param.Key, $param.Value) + $buildingParams += @{ + $param.Key = $param.Value + } + } + } + } + + if ($PSBoundParameters.ContainsKey('Office365ManagementType') -and + $Office365ManagementType -ne $state.Office365ManagementType) + { + if ($Office365ManagementType -eq 'NotConfigured') + { + $buildingParams += @{ + Office365ManagementType = $null + } + } + elseif ($Office365ManagementType -eq 'Yes') + { + $buildingParams += @{ + Office365ManagementType = $true + } + } + else + { + $buildingParams += @{ + Office365ManagementType = $false + } + } + } + + if ($ScanScheduleType) + { + $valuesToValidate = @('ScanScheduleType','ScanRecurInterval','ScanMonthlyWeekOrder', + 'ScanDayOfWeek','ScanDayOfMonth','ScanStart') + foreach ($item in $valuesToValidate) + { + if ($PSBoundParameters.ContainsKey($item)) + { + $scanScheduleCheck += @{ + $item.Substring(4) = $PSBoundParameters[$item] + } + } + } + + foreach ($scan in $state.Keys) + { + if ($valuesToValidate -contains $scan) + { + $scanState += @{ + $scan.SubString(4) = $state[$scan] + } + } + } + + $scanResult = Test-CMSchedule @scanScheduleCheck -State $scanState + } + + if ($scanResult -eq $false) + { + $sched = Set-CMSchedule @scanScheduleCheck + $newSchedule = New-CMSchedule @sched + + Write-Verbose -Message $script:localizedData.NewSchedule + $buildingParams += @{ + ScanSchedule = $newSchedule + } + } + + if ($EvalScheduleType) + { + $valuesToValidate = @('EvalScheduleType','EvalRecurInterval','EvalMonthlyWeekOrder', + 'EvalDayOfWeek','EvalDayOfMonth','EvalStart') + + foreach ($item in $valuesToValidate) + { + if ($PSBoundParameters.ContainsKey($item)) + { + $evalScheduleCheck += @{ + $item.Substring(4) = $PSBoundParameters[$item] + } + } + } + + foreach ($eval in $state.Keys) + { + if ($valuesToValidate -contains $eval) + { + $evalState += @{ + $eval.SubString(4) = $state[$eval] + } + } + } + + $evalResult = Test-CMSchedule @evalScheduleCheck -State $evalState + } + + if ($evalResult -eq $false) + { + $sched = Set-CMSchedule @evalScheduleCheck + $newSchedule = New-CMSchedule @sched + + Write-Verbose -Message $script:localizedData.NewSchedule + $buildingParams += @{ + DeploymentEvaluationSchedule = $newSchedule + } + } + } + elseif ($state.Enable -eq $true) + { + if ($PSBoundParameters.Keys.Count -ge 4) + { + Write-Warning -Message $script:localizedData.DisableIgnore + } + + $buildingParams = @{ + Enable = $false + } + } + + if ($buildingParams) + { + if ($state.ClientType -eq 'Default') + { + Set-CMClientSettingSoftwareUpdate -DefaultSetting @buildingParams + } + else + { + Set-CMClientSettingSoftwareUpdate -Name $ClientSettingName @buildingParams + } + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .Parameter Enable + Specifies if software update for clients is enabled or disabled. + + .PARAMETER ScanStart + Specifies the start date and start time for the software update scan schedule Month/Day/Year, example 1/1/2020 02:00. + + .PARAMETER ScanScheduleType + Specifies the schedule type for the software update scan schedule. + + .PARAMETER ScanRecurInterval + Specifies how often the ScanScheduleType is run. + + .PARAMETER ScanMonthlyByWeek + Specifies week order for MonthlyByWeek scan schedule type. + + .PARAMETER ScanDayOfWeek + Specifies the day of week name for MonthlyByWeek and Weekly scan schedules. + + .PARAMETER ScanDayOfMonth + Specifies the day number for MonthlyByDay scan schedules. + Note specifying 0 sets the schedule to run the last day of the month. + + .PARAMETER EvalStart + Specifies the start date and start time for the software update eval schedule Month/Day/Year, example 1/1/2020 02:00. + + .PARAMETER EvalScheduleType + Specifies the schedule type for the software update eval schedule. + + .PARAMETER EvalRecurInterval + Specifies how often the EvalScheduleType is run. + + .PARAMETER EvalMonthlyByWeek + Specifies week order for MonthlyByWeek eval schedule type. + + .PARAMETER EvalDayOfWeek + Specifies the day of week name for MonthlyByWeek and Weekly eval schedules. + + .PARAMETER EvalDayOfMonth + Specifies the day number for MonthlyByDay eval schedules. + Note specifying 0 sets the schedule to run the last day of the month. + + .Parameter EnforceMandatory + Specifies if any software update deployment deadline is + reached to install all deployments with dealing coming within a specific time period. + + .Parameter TimeUnit + Specifies the unit of time, hours or days time frame to install pending software updates. + + .Parameter BatchingTimeOut + Specifies the time within TimeUnit to install the depending updates. + + .Parameter EnableDeltaDownload + Specifies if client are allowed to download delta content when available. + + .Parameter DeltaDownloadPort + Specifies the port that clients will use to receive requests for delta content. + + .Parameter Office365ManagementType + Specifies the management of the Office 365 client. + + .Parameter EnableThirdPartyUpdates + Specifies if third party updates is enabled or disabled. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter(Mandatory = $true)] + [Boolean] + $Enable, + + [Parameter()] + [String] + $ScanStart, + + [Parameter()] + [ValidateSet('MonthlyByDay','MonthlyByWeek','Weekly','Days','Hours','Minutes','None')] + [String] + $ScanScheduleType, + + [Parameter()] + [UInt32] + $ScanRecurInterval, + + [Parameter()] + [ValidateSet('First','Second','Third','Fourth','Last')] + [String] + $ScanMonthlyWeekOrder, + + [Parameter()] + [ValidateSet('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')] + [String] + $ScanDayOfWeek, + + [Parameter()] + [ValidateRange(0,31)] + [UInt32] + $ScanDayOfMonth, + + [Parameter()] + [String] + $EvalStart, + + [Parameter()] + [ValidateSet('MonthlyByDay','MonthlyByWeek','Weekly','Days','Hours','Minutes','None')] + [String] + $EvalScheduleType, + + [Parameter()] + [UInt32] + $EvalRecurInterval, + + [Parameter()] + [ValidateSet('First','Second','Third','Fourth','Last')] + [String] + $EvalMonthlyWeekOrder, + + [Parameter()] + [ValidateSet('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')] + [String] + $EvalDayOfWeek, + + [Parameter()] + [ValidateRange(0,31)] + [UInt32] + $EvalDayOfMonth, + + [Parameter()] + [Boolean] + $EnforceMandatory, + + [Parameter()] + [ValidateSet('Hours','Days')] + [String] + $TimeUnit, + + [Parameter()] + [ValidateRange(1,365)] + [UInt32] + $BatchingTimeOut, + + [Parameter()] + [Boolean] + $EnableDeltaDownload, + + [Parameter()] + [UInt32] + $DeltaDownloadPort, + + [Parameter()] + [ValidateSet('NotConfigured','Yes','No')] + [String] + $Office365ManagementType, + + [Parameter()] + [Boolean] + $EnableThirdPartyUpdates + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName -Enable $Enable + $result = $true + $schedResult = $true + + if ($state.ClientSettingStatus -eq 'Absent') + { + Write-Warning -Message ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + $result = $false + } + elseif ($state.ClientType -eq 'User') + { + Write-Warning -Message $script:localizedData.WrongClientType + $result = $false + } + else + { + if ($Enable -eq $true) + { + if ((-not $PSBoundParameters.ContainsKey('ScanScheduleType')) -and ($PSBoundParameters.ContainsKey('ScanStart') -or + $PSBoundParameters.ContainsKey('ScanRecurInterval') -or $PSBoundParameters.ContainsKey('ScanMonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('ScanDayOfWeek') -or $PSBoundParameters.ContainsKey('ScanDayOfMonth'))) + { + Write-Warning -Message $script:localizedData.RequiredSchedule + $badInput = $true + } + + if ((-not $PSBoundParameters.ContainsKey('EvalScheduleType')) -and ($PSBoundParameters.ContainsKey('EvalStart') -or + $PSBoundParameters.ContainsKey('EvalRecurInterval') -or $PSBoundParameters.ContainsKey('EvalMonthlyWeekOrder') -or + $PSBoundParameters.ContainsKey('EvalDayOfWeek') -or $PSBoundParameters.ContainsKey('EvalDayOfMonth'))) + { + Write-Warning -Message $script:localizedData.RequiredSchedule + $badInput = $true + } + + $defaultValues = @('Enable','EnforceMandatory','EnableDeltaDownload','Office365ManagementType', + 'EnableThirdPartyUpdates') + + if ($EnableDeltaDownload -eq $false -and $PSBoundParameters.ContainsKey('DeltaDownloadPort')) + { + Write-Warning -Message $script:localizedData.DeltaPortIgnore + } + else + { + $defaultValues += 'DeltaDownloadPort' + } + + if ($EnforceMandatory -eq $true) + { + $defaultValues += ('TimeUnit','BatchingTimeOut') + if (-not $PSBoundParameters.ContainsKey('TimeUnit') -or -not $PSBoundParameters.ContainsKey('BatchingTimeOut')) + { + Write-Warning -Message $script:localizedData.MissingEnforce + $badInput = $true + } + + if ($TimeUnit -eq 'Hours' -and $BatchingTimeOut -gt 23) + { + Write-Warning -Message $script:localizedData.MaxBatchHours + $PSBoundParameters.Remove('BatchingTimeOut') | Out-Null + $PSBoundParameters.Add('BatchingTimeOut',23) + } + } + elseif ($PSBoundParameters.ContainsKey('TimeUnit') -or $PSBoundParameters.ContainsKey('BatchingTimeOut')) + { + Write-Warning -Message $script:localizedData.TimeBatchIgnore + } + + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = $defaultValues + } + + $result = Test-DscParameterState @testParams -TurnOffTypeChecking -Verbose + + if ($ScanScheduleType) + { + $valuesToValidate = @('ScanScheduleType','ScanRecurInterval','ScanMonthlyWeekOrder', + 'ScanDayOfWeek','ScanDayOfMonth','ScanStart') + foreach ($item in $valuesToValidate) + { + if ($PSBoundParameters.ContainsKey($item)) + { + $scanScheduleCheck += @{ + $item.Substring(4) = $PSBoundParameters[$item] + } + } + } + + foreach ($scan in $state.Keys) + { + if ($valuesToValidate -contains $scan) + { + $scanState += @{ + $scan.SubString(4) = $state[$scan] + } + } + } + + $scanResult = Test-CMSchedule @scanScheduleCheck -State $scanState + } + + if ($EvalScheduleType) + { + $valuesToValidate = @('EvalScheduleType','EvalRecurInterval','EvalMonthlyWeekOrder', + 'EvalDayOfWeek','EvalDayOfMonth','EvalStart') + foreach ($item in $valuesToValidate) + { + if ($PSBoundParameters.ContainsKey($item)) + { + $evalScheduleCheck += @{ + $item.Substring(4) = $PSBoundParameters[$item] + } + } + } + + foreach ($eval in $state.Keys) + { + if ($valuesToValidate -contains $eval) + { + $evalState += @{ + $eval.SubString(4) = $state[$eval] + } + } + } + + $evalResult = Test-CMSchedule @evalScheduleCheck -State $evalState + } + } + else + { + if ($PSBoundParameters.Keys.Count -ge 4) + { + Write-Warning -Message $script:localizedData.DisableIgnore + } + + if ($state.Enable -eq $true) + { + Write-Verbose -Message $script:localizedData.TestDisabled + $result = $false + } + } + } + + if ($result -eq $false -or $scanResult -eq $false -or $badInput -eq $true -or $evalResult -eq $false) + { + $return = $false + } + else + { + $return = $true + } + + Write-Verbose -Message ($script:localizedData.TestState -f $return) + Set-Location -Path "$env:temp" + return $return +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettingsSoftwareUpdate/DSC_CMClientSettingsSoftwareUpdate.schema.mof b/source/DSCResources/DSC_CMClientSettingsSoftwareUpdate/DSC_CMClientSettingsSoftwareUpdate.schema.mof new file mode 100644 index 00000000..63cc0a5a --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsSoftwareUpdate/DSC_CMClientSettingsSoftwareUpdate.schema.mof @@ -0,0 +1,28 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettingsSoftwareUpdate")] +class DSC_CMClientSettingsSoftwareUpdate : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Required, Description("Specifies if software update for clients is enabled or disabled.")] Boolean Enable; + [Write, Description("Specifies the start date and start time for the software update scan schedule Month/Day/Year, example 1/1/2020 02:00.")] String ScanStart; + [Write, Description("Specifies the schedule type for the software update scan schedule."), ValueMap{"MonthlyByDay","MonthlyByWeek","Weekly","Days","Hours","Minutes","None"}, Values{"MonthlyByDay","MonthlyByWeek","Weekly","Days","Hours","Minutes","None"}] String ScanScheduleType; + [Write, Description("Specifies how often the ScheduleType is run.")] UInt32 ScanRecurInterval; + [Write, Description("Specifies week order for MonthlyByWeek schedule type."), ValueMap{"First","Second","Third","Fourth","Last"}, Values{"First","Second","Third","Fourth","Last"}] String ScanMonthlyWeekOrder; + [Write, Description("Specifies the day of week name for MonthlyByWeek and Weekly schedules."), ValueMap{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}, Values{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}] String ScanDayOfWeek; + [Write, Description("Specifies the day number for MonthlyByDay schedules.")] UInt32 ScanDayOfMonth; + [Write, Description("Specifies the start date and start time for the software update evaluation schedule Month/Day/Year, example 1/1/2020 02:00.")] String EvalStart; + [Write, Description("Specifies the schedule type for the software update evaluation schedule."), ValueMap{"MonthlyByDay","MonthlyByWeek","Weekly","Days","Hours","Minutes","None"}, Values{"MonthlyByDay","MonthlyByWeek","Weekly","Days","Hours","Minutes","None"}] String EvalScheduleType; + [Write, Description("Specifies how often the ScheduleType is run.")] UInt32 EvalRecurInterval; + [Write, Description("Specifies week order for MonthlyByWeek schedule type."), ValueMap{"First","Second","Third","Fourth","Last"}, Values{"First","Second","Third","Fourth","Last"}] String EvalMonthlyWeekOrder; + [Write, Description("Specifies the day of week name for MonthlyByWeek and Weekly schedules."), ValueMap{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}, Values{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}] String EvalDayOfWeek; + [Write, Description("Specifies the day number for MonthlyByDay schedules.")] UInt32 EvalDayOfMonth; + [Write, Description("Specifies if any software update deployment deadline is reached to install all deployments with dealing coming within a specific time period.")] Boolean EnforceMandatory; + [Write, Description("Specifies the unit of time, hours or days time frame to install pending software updates."), ValueMap{"Hours","Days"}, Values{"Hours","Days"}] String TimeUnit; + [Write, Description("Specifies the time within TimeUnit to install the depending updates.")] UInt32 BatchingTimeOut; + [Write, Description("Specifies if clients are allowed to download delta content when available.")] Boolean EnableDeltaDownload; + [Write, Description("Specifies the port that clients will use to receive requests for delta content.")] UInt32 DeltaDownloadPort; + [Write, Description("Specifies the management of the Office 365 client."), ValueMap{"NotConfigured","Yes","No"}, Values{"NotConfigured","Yes","No"}] String Office365ManagementType; + [Write, Description("Specifies if third party updates is enabled or disabled.")] Boolean EnableThirdPartyUpdates; + [Read, Description("Specifies if the client settings policy exists.")] String ClientSettingStatus; + [Read, Description("Specifies the type of client policy setting.")] String ClientType; +}; diff --git a/source/DSCResources/DSC_CMClientSettingsSoftwareUpdate/en-US/DSC_CMClientSettingsSoftwareUpdate.strings.psd1 b/source/DSCResources/DSC_CMClientSettingsSoftwareUpdate/en-US/DSC_CMClientSettingsSoftwareUpdate.strings.psd1 new file mode 100644 index 00000000..e7bbb02b --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsSoftwareUpdate/en-US/DSC_CMClientSettingsSoftwareUpdate.strings.psd1 @@ -0,0 +1,15 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy for software update. + ClientPolicySetting = Client Policy Setting {0} does not exist, and will need to be created prior to making client setting changes. + TestState = Test-TargetResource compliance check returned: {0}. + TestDisabled = Enabled currently is enabled and should be disabled. + SettingValue = Setting value: {0} to {1}. + NewSchedule = Modifying software update schedule. + RequiredSchedule = In order to create a schedule you must specify ScheduleType. + WrongClientType = Client Settings for software update only applies to Default and Device client settings. + DeltaPortIgnore = DeltaDownloadPort is specified, to set this setting EnableDeltaDownload must be set to true, ignoring setting. + MissingEnforce = When settings EnforceMandatory to true you must specify both TimeUnit and BatchingTimeOut. + MaxBatchHours = TimeUnits is set to hours, BatchingTimeOut max value is 23, setting BatchingTimeOut to 23. + TimeBatchIgnore = TimeUnit or BatchingTimeOut are specified, to set these settings EnforceMandatory must be set to true, ignoring settings. + DisableIgnore = Currently setting SoftwareUpdates to disabled all other parameters specified will be ignored. +'@ diff --git a/source/DSCResources/DSC_CMClientSettingsStateMessaging/DSC_CMClientSettingsStateMessaging.psm1 b/source/DSCResources/DSC_CMClientSettingsStateMessaging/DSC_CMClientSettingsStateMessaging.psm1 new file mode 100644 index 00000000..cae4609e --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsStateMessaging/DSC_CMClientSettingsStateMessaging.psm1 @@ -0,0 +1,208 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + $type = @('Default','Device','User')[$clientSetting.Type] + $settings = Get-CMClientSetting -Name $ClientSettingName -Setting StateMessaging + + if ($settings) + { + $cycleMins = $settings.BulkSendInterval + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + ReportingCycleMins = $cycleMins + ClientSettingStatus = $status + ClientType = $type + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER ReportingCycleMins + Specifies the state message reporting cycle in minutes. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [ValidateRange(1,43200)] + [UInt32] + $ReportingCycleMins + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + + try + { + if ($state.ClientSettingStatus -eq 'Absent') + { + throw ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + } + + if ($state.ClientType -eq 'User') + { + throw $script:localizedData.WrongClientType + } + + if ($ReportingCycleMins -ne $state.ReportingCycleMins) + { + Write-Verbose -Message ($script:localizedData.SettingValue -f $state.ReportingCycleMins, $ReportingCycleMins) + $buildingParams += @{ + ReportingCycleMins = $ReportingCycleMins + } + } + + if ($buildingParams) + { + if ($state.ClientType -eq 'Default') + { + Set-CMClientSettingStateMessaging -DefaultSetting @buildingParams + } + else + { + Set-CMClientSettingStateMessaging -Name $ClientSettingName @buildingParams + } + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER ReportingCycleMins + Specifies the state message reporting cycle in minutes. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [ValidateRange(1,43200)] + [UInt32] + $ReportingCycleMins + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + $result = $true + + if ($state.ClientSettingStatus -eq 'Absent') + { + Write-Warning -Message ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + $result = $false + } + elseif ($state.ClientType -eq 'User') + { + Write-Warning -Message $script:localizedData.WrongClientType + $result = $false + } + else + { + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = @('ReportingCycleMins') + } + + $result = Test-DscParameterState @testParams -TurnOffTypeChecking -Verbose + } + + Write-Verbose -Message ($script:localizedData.TestState -f $result) + Set-Location -Path "$env:temp" + return $result +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettingsStateMessaging/DSC_CMClientSettingsStateMessaging.schema.mof b/source/DSCResources/DSC_CMClientSettingsStateMessaging/DSC_CMClientSettingsStateMessaging.schema.mof new file mode 100644 index 00000000..690eb890 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsStateMessaging/DSC_CMClientSettingsStateMessaging.schema.mof @@ -0,0 +1,9 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettingsStateMessaging")] +class DSC_CMClientSettingsStateMessaging : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Write, Description("Specifies the state message reporting cycle in minutes.")] UInt32 ReportingCycleMins; + [Read, Description("Specifies if the client settings policy exists.")] String ClientSettingStatus; + [Read, Description("Specifies the type of client policy setting.")] String ClientType; +}; diff --git a/source/DSCResources/DSC_CMClientSettingsStateMessaging/en-US/DSC_CMClientSettingsStateMessaging.strings.psd1 b/source/DSCResources/DSC_CMClientSettingsStateMessaging/en-US/DSC_CMClientSettingsStateMessaging.strings.psd1 new file mode 100644 index 00000000..770e0390 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsStateMessaging/en-US/DSC_CMClientSettingsStateMessaging.strings.psd1 @@ -0,0 +1,7 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy for state messaging settings. + ClientPolicySetting = Client Policy Setting {0} does not exist, and will need to be created prior to making client setting changes. + TestState = Test-TargetResource compliance check returned: {0}. + SettingValue = Setting ReportingCycleMins from: {0} to {1}. + WrongClientType = Client Settings for state messaging only applies to Default and Device Client settings. +'@ diff --git a/source/DSCResources/DSC_CMClientSettingsUserDeviceAffinity/DSC_CMClientSettingsUserDeviceAffinity.psm1 b/source/DSCResources/DSC_CMClientSettingsUserDeviceAffinity/DSC_CMClientSettingsUserDeviceAffinity.psm1 new file mode 100644 index 00000000..2b3be8fc --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsUserDeviceAffinity/DSC_CMClientSettingsUserDeviceAffinity.psm1 @@ -0,0 +1,311 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $clientSetting = Get-CMClientSetting -Name $ClientSettingName + + if ($clientSetting) + { + $type = @('Default','Device','User')[$clientSetting.Type] + $settings = Get-CMClientSetting -Name $ClientSettingName -Setting UserAndDeviceAffinity + + if ($settings) + { + if ($type -eq 'Default' -or $type -eq 'Device') + { + $console = $settings.ConsoleMinutes + $intDays = $settings.IntervalDays + $allowUser = [System.Convert]::ToBoolean([UInt32]$settings.AutoApproveAffinity) + } + + if ($type -eq 'Default' -or $type -eq 'User') + { + $auto = [System.Convert]::ToBoolean([UInt32]$settings.AllowUserAffinity) + } + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteCode = $SiteCode + ClientSettingName = $ClientSettingName + LogOnThresholdMins = $console + UsageThresholdDays = $intDays + AutoApproveAffinity = $allowUser + AllowUserAffinity = $auto + ClientSettingStatus = $status + ClientType = $type + } +} + +<# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER LogOnThresholdMins + Specifies if user device affinity usage threshold in minutes. + + .PARAMETER UsageThresholdDays + Specifies if user device affinity usage threshold in days. + + .PARAMETER AutoApproveAffinity + Specifies allowing automatic configure user device affinity from usage data. + + .PARAMETER AllowUserAffinity + Specifies allowing users to define their primary device. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [ValidateRange(1,999999)] + [UInt32] + $LogOnThresholdMins, + + [Parameter()] + [ValidateRange(1,99999)] + [UInt32] + $UsageThresholdDays, + + [Parameter()] + [Boolean] + $AutoApproveAffinity, + + [Parameter()] + [Boolean] + $AllowUserAffinity + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + + try + { + if ($state.ClientSettingStatus -eq 'Absent') + { + throw ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + } + + if ($state.ClientType -eq 'Default') + { + $defaultValues = @('LogOnThresholdMins','UsageThresholdDays','AutoApproveAffinity','AllowUserAffinity') + } + elseif ($state.ClientType -eq 'Device') + { + if ($PSBoundParameters.ContainsKey('AllowUserAffinity')) + { + Write-Warning -Message $script:localizedData.NonDefaultClient + } + + $defaultValues = @('LogOnThresholdMins','UsageThresholdDays','AutoApproveAffinity') + + } + elseif ($state.ClientType -eq 'User') + { + if ($PSBoundParameters.ContainsKey('LogOnThresholdMins') -or $PSBoundParameters.ContainsKey('UsageThresholdDays') -or + $PSBoundParameters.ContainsKey('AutoApproveAffinity')) + { + Write-Warning -message $script:localizedData.NonUserSettings + } + + $defaultValues = @('AllowUserAffinity') + } + + foreach ($param in $PSBoundParameters.GetEnumerator()) + { + if ($defaultValues -contains $param.Key) + { + if ($param.Value -ne $state[$param.Key]) + { + Write-Verbose -Message ($script:localizedData.SettingValue -f $param.Key, $param.Value) + $buildingParams += @{ + $param.Key = $param.Value + } + } + } + } + + if ($buildingParams) + { + if ($state.ClientType -eq 'Default') + { + Set-CMClientSettingUserAndDeviceAffinity -DefaultSetting @buildingParams + } + else + { + Set-CMClientSettingUserAndDeviceAffinity -Name $ClientSettingName @buildingParams + } + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .Parameter ClientSettingName + Specifies which client settings policy to modify. + + .PARAMETER LogOnThresholdMins + Specifies if user device affinity usage threshold in minutes. + + .PARAMETER UsageThresholdDays + Specifies if user device affinity usage threshold in days. + + .PARAMETER AutoApproveAffinity + Specifies allowing automatic configure user device affinity from usage data. + + .PARAMETER AllowUserAffinity + Specifies allowing users to define their primary device. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $ClientSettingName, + + [Parameter()] + [ValidateRange(1,999999)] + [UInt32] + $LogOnThresholdMins, + + [Parameter()] + [ValidateRange(1,99999)] + [UInt32] + $UsageThresholdDays, + + [Parameter()] + [Boolean] + $AutoApproveAffinity, + + [Parameter()] + [Boolean] + $AllowUserAffinity + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -ClientSettingName $ClientSettingName + $result = $true + + if ($state.ClientSettingStatus -eq 'Absent') + { + Write-Warning -Message ($script:localizedData.ClientPolicySetting -f $ClientSettingName) + $result = $false + } + else + { + if ($state.ClientType -eq 'Default') + { + $defaultValues = @('LogOnThresholdMins','UsageThresholdDays','AutoApproveAffinity','AllowUserAffinity') + } + elseif ($state.ClientType -eq 'Device') + { + if ($PSBoundParameters.ContainsKey('AllowUserAffinity')) + { + Write-Warning -Message $script:localizedData.NonDefaultClient + } + + $defaultValues = @('LogOnThresholdMins','UsageThresholdDays','AutoApproveAffinity') + + } + elseif ($state.ClientType -eq 'User') + { + if ($PSBoundParameters.ContainsKey('LogOnThresholdMins') -or $PSBoundParameters.ContainsKey('UsageThresholdDays') -or + $PSBoundParameters.ContainsKey('AutoApproveAffinity')) + { + Write-Warning -message $script:localizedData.NonUserSettings + } + + $defaultValues = @('AllowUserAffinity') + } + + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = $defaultValues + } + + $result = Test-DscParameterState @testParams -TurnOffTypeChecking -Verbose + } + + Write-Verbose -Message ($script:localizedData.TestState -f $result) + Set-Location -Path "$env:temp" + return $result +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMClientSettingsUserDeviceAffinity/DSC_CMClientSettingsUserDeviceAffinity.schema.mof b/source/DSCResources/DSC_CMClientSettingsUserDeviceAffinity/DSC_CMClientSettingsUserDeviceAffinity.schema.mof new file mode 100644 index 00000000..4080c9ef --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsUserDeviceAffinity/DSC_CMClientSettingsUserDeviceAffinity.schema.mof @@ -0,0 +1,12 @@ +[ClassVersion("1.0.0"), FriendlyName("CMClientSettingsUserDeviceAffinity")] +class DSC_CMClientSettingsUserDeviceAffinity : OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies which client settings policy to modify.")] String ClientSettingName; + [Write, Description("Specifies if user device affinity usage threshold in minutes.")] UInt32 LogOnThresholdMins; + [Write, Description("Specifies if user device affinity usage threshold in days.")] UInt32 UsageThresholdDays; + [Write, Description("Specifies allowing automatic configure user device affinity from usage data.")] Boolean AutoApproveAffinity; + [Write, Description("Specifies allowing users to define their primary device.")] Boolean AllowUserAffinity; + [Read, Description("Specifies if the client settings policy exists.")] String ClientSettingStatus; + [Read, Description("Specifies the type of client policy setting.")] String ClientType; +}; diff --git a/source/DSCResources/DSC_CMClientSettingsUserDeviceAffinity/en-US/DSC_CMClientSettingsUserDeviceAffinity.strings.psd1 b/source/DSCResources/DSC_CMClientSettingsUserDeviceAffinity/en-US/DSC_CMClientSettingsUserDeviceAffinity.strings.psd1 new file mode 100644 index 00000000..7dc3d218 --- /dev/null +++ b/source/DSCResources/DSC_CMClientSettingsUserDeviceAffinity/en-US/DSC_CMClientSettingsUserDeviceAffinity.strings.psd1 @@ -0,0 +1,8 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting results for Configuration Manager client policy for user and device affinity settings. + ClientPolicySetting = Client Policy Setting {0} does not exist, and will need to be created prior to making client setting changes. + TestState = Test-TargetResource compliance check returned: {0}. + SettingValue = Setting value: {0} to {1}. + NonDefaultClient = AllowUserAffinity can only be set for the default or user client policy settings, ignoring setting. + NonUserSettings = LogOnThresholdMins, UsageThresholdDays, and AutoApproveAffinity can only be set for the default or device client policy settings, ignoring settings. +'@ diff --git a/source/Examples/Resources/CMClientSettings/CMClientSettings.ps1 b/source/Examples/Resources/CMClientSettings/CMClientSettings.ps1 new file mode 100644 index 00000000..23ff7392 --- /dev/null +++ b/source/Examples/Resources/CMClientSettings/CMClientSettings.ps1 @@ -0,0 +1,40 @@ +<# + .SYNOPSIS + A DSC configuration script to create\modify\remove client settings. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettings DevicePresent + { + SiteCode = 'Lab' + ClientSettingName = 'TestClient' + Type = 'Device' + Description = 'Device Policy' + SecurityScopesToInclude = @('Scope1','Scope1') + SecurityScopesToExclude = @('Default') + Ensure = 'Present' + } + + CMClientSettings User + { + SiteCode = 'Lab' + ClientSettingName = 'TestUser' + Type = 'User' + Description = 'User Policy' + SecurityScopes = @('Default','Scope1') + Ensure = 'Present' + } + + CMClientSettings DeviceAbsent + { + SiteCode = 'Lab' + ClientSettingName = 'TestClient2' + Type = 'Device' + Ensure = 'Absent' + } + } +} diff --git a/source/Examples/Resources/CMClientSettingsBits/CMClientSettingsBits.ps1 b/source/Examples/Resources/CMClientSettingsBits/CMClientSettingsBits.ps1 new file mode 100644 index 00000000..d736bdf9 --- /dev/null +++ b/source/Examples/Resources/CMClientSettingsBits/CMClientSettingsBits.ps1 @@ -0,0 +1,41 @@ +<# + .SYNOPSIS + A DSC configuration script to modify client policy Bits settings. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettingsBits DefaultClientSettings + { + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + EnableBitsMaxBandwidth = $true + MaxBandwidthBeginHr = 0 + MaxBandwidthEndHr = 23 + MaxTransferRateOnSchedule = 900 + EnableDownloadOffSchedule = $true + MaxTransferRateOffSchedule = 9000 + } + + CMClientSettingsBits TestClient + { + SiteCode = 'Lab' + ClientSettingName = 'TestClient' + EnableBitsMaxBandwidth = $true + MaxBandwidthBeginHr = 1 + MaxBandwidthEndHr = 11 + MaxTransferRateOnSchedule = 900 + EnableDownloadOffSchedule = $false + } + + CMClientSettingsBits TestClientDisable + { + SiteCode = 'Lab' + ClientSettingName = 'TestClientDisable' + EnableBitsMaxBandwidth = $false + } + } +} diff --git a/source/Examples/Resources/CMClientSettingsClientCache/CMClientSettingsClientCache.ps1 b/source/Examples/Resources/CMClientSettingsClientCache/CMClientSettingsClientCache.ps1 new file mode 100644 index 00000000..ccb0784b --- /dev/null +++ b/source/Examples/Resources/CMClientSettingsClientCache/CMClientSettingsClientCache.ps1 @@ -0,0 +1,41 @@ +<# + .SYNOPSIS + A DSC configuration script to modify client policy settings for client cache. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettingsClientCache DefaultAgent + { + SiteCode = 'Lab' + BroadcastPort = 8004 + MaxCacheSizePercent = 20 + ConfigureBranchCache = $true + MaxCacheSize = 20000 + MaxBranchCacheSizePercent = 10 + ConfigureCacheSize = $true + ClientSettingName = 'Default Client Agent Settings' + EnableSuperPeer = $true + DownloadPort = 8003 + EnableBranchCache = $true + } + + CMClientSettingsClientCache DeviceAgent + { + SiteCode = 'Lab' + BroadcastPort = 8004 + MaxCacheSizePercent = 20 + ConfigureBranchCache = $true + MaxCacheSize = 20000 + MaxBranchCacheSizePercent = 10 + ConfigureCacheSize = $true + ClientSettingName = 'ClientTest' + EnableSuperPeer = $true + DownloadPort = 8003 + EnableBranchCache = $true + } + } +} diff --git a/source/Examples/Resources/CMClientSettingsClientPolicy/CMClientSettingsClientPolicy.ps1 b/source/Examples/Resources/CMClientSettingsClientPolicy/CMClientSettingsClientPolicy.ps1 new file mode 100644 index 00000000..78a7d5ef --- /dev/null +++ b/source/Examples/Resources/CMClientSettingsClientPolicy/CMClientSettingsClientPolicy.ps1 @@ -0,0 +1,31 @@ +<# + .SYNOPSIS + A DSC configuration script to modify client policy settings for client policy. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettingsClientPolicy DefaultAgent + { + SiteCode = 'Lab' + EnableUserPolicyOnInternet = $false + EnableUserPolicy = $true + ClientSettingName = 'Default Client Agent Settings' + PolicyPollingMins = 60 + EnableUserPolicyOnTS = $false + } + + CMClientSettingsClientPolicy DeviceAgent + { + SiteCode = 'Lab' + EnableUserPolicyOnInternet = $false + EnableUserPolicy = $true + ClientSettingName = 'ClientTest' + PolicyPollingMins = 15 + EnableUserPolicyOnTS = $false + } + } +} diff --git a/source/Examples/Resources/CMClientSettingsCloudService/CMClientSettingsCloudService.ps1 b/source/Examples/Resources/CMClientSettingsCloudService/CMClientSettingsCloudService.ps1 new file mode 100644 index 00000000..1c19a271 --- /dev/null +++ b/source/Examples/Resources/CMClientSettingsCloudService/CMClientSettingsCloudService.ps1 @@ -0,0 +1,36 @@ +<# + .SYNOPSIS + A DSC configuration script to modify client policy settings for cloud services. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettingsCloudService DefaultAgent + { + SiteCode = 'Lab' + AutoAzureADJoin = $true + AllowCloudDistributionPoint = $false + AllowCloudManagementGateway = $true + ClientSettingName = 'Default Client Agent Settings' + } + + CMClientSettingsCloudService DeviceAgent + { + SiteCode = 'Lab' + AutoAzureADJoin = $true + AllowCloudDistributionPoint = $true + AllowCloudManagementGateway = $true + ClientSettingName = 'ClientTest' + } + + CMClientSettingsCloudService UserAgent + { + SiteCode = 'Lab' + AllowCloudDistributionPoint = $true + ClientSettingName = 'UserTest' + } + } +} diff --git a/source/Examples/Resources/CMClientSettingsCompliance/CMClientSettingsCompliance.ps1 b/source/Examples/Resources/CMClientSettingsCompliance/CMClientSettingsCompliance.ps1 new file mode 100644 index 00000000..f0a61ca8 --- /dev/null +++ b/source/Examples/Resources/CMClientSettingsCompliance/CMClientSettingsCompliance.ps1 @@ -0,0 +1,29 @@ +<# + .SYNOPSIS + A DSC configuration script to modify client policy settings for compliance. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettingsCompliance DefaultAgent + { + SiteCode = 'Lab' + Enable = $true + ScheduleType = 'None' + Start = '9/22/2021 21:48' + ClientSettingName = 'Default Client Agent Settings' + EnableUserDataAndProfile = $true + } + + CMClientSettingsCompliance DeviceAgent + { + SiteCode = 'Lab' + Enable = $true + ClientSettingName = 'ClientTest' + EnableUserDataAndProfile = $false + } + } +} diff --git a/source/Examples/Resources/CMClientSettingsComputerAgent/CMClientSettingsComputerAgent.ps1 b/source/Examples/Resources/CMClientSettingsComputerAgent/CMClientSettingsComputerAgent.ps1 new file mode 100644 index 00000000..973bec3c --- /dev/null +++ b/source/Examples/Resources/CMClientSettingsComputerAgent/CMClientSettingsComputerAgent.ps1 @@ -0,0 +1,46 @@ +<# + .SYNOPSIS + A DSC configuration script to modify client policy settings for computer agent settings. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettingsComputerAgent DefaultAgent + { + SiteCode = 'Lab' + EnableThirdPartyOrchestration = 'No' + InterimReminderHr = 4 + FinalReminderMins = 15 + DisplayNewProgramNotification = $true + BrandingTitle = 'Default Company' + InitialReminderHr = 48 + PowerShellExecutionPolicy = 'Bypass' + UseOnPremisesHealthAttestation = $true + ClientSettingName = 'Default Client Agent Settings' + SuspendBitLocker = 'Never' + InstallRestriction = 'AllUsers' + EnableHealthAttestation = $true + UseNewSoftwareCenter = $true + } + + CMClientSettingsComputerAgent DeviceAgent + { + SiteCode = 'Lab' + EnableThirdPartyOrchestration = 'Yes' + InterimReminderHr = 4 + FinalReminderMins = 15 + DisplayNewProgramNotification = $true + InitialReminderHr = 48 + PowerShellExecutionPolicy = 'Restricted' + UseOnPremisesHealthAttestation = $true + ClientSettingName = 'ClientTest' + SuspendBitLocker = 'Always' + InstallRestriction = 'NoUsers' + EnableHealthAttestation = $true + UseNewSoftwareCenter = $false + } + } +} diff --git a/source/Examples/Resources/CMClientSettingsDelivery/CMClientSettingsDelivery.ps1 b/source/Examples/Resources/CMClientSettingsDelivery/CMClientSettingsDelivery.ps1 new file mode 100644 index 00000000..6d442e66 --- /dev/null +++ b/source/Examples/Resources/CMClientSettingsDelivery/CMClientSettingsDelivery.ps1 @@ -0,0 +1,25 @@ +<# + .SYNOPSIS + A DSC configuration script to modify client policy settings for delivery. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettingsDelivery DefaultAgent + { + SiteCode = 'Lab' + Enable = $true + ClientSettingName = 'Default Client Agent Settings' + } + + CMClientSettingsDelivery DeviceAgent + { + SiteCode = 'Lab' + Enable = $false + ClientSettingName = 'ClientTest' + } + } +} diff --git a/source/Examples/Resources/CMClientSettingsHardware/CMClientSettingsHardware.ps1 b/source/Examples/Resources/CMClientSettingsHardware/CMClientSettingsHardware.ps1 new file mode 100644 index 00000000..3f960699 --- /dev/null +++ b/source/Examples/Resources/CMClientSettingsHardware/CMClientSettingsHardware.ps1 @@ -0,0 +1,35 @@ +<# + .SYNOPSIS + A DSC configuration script to modify client policy settings for hardware settings. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettingsHardware DefaultAgent + { + SiteCode = 'Lab' + Enable = $true + RecurInterval = 1 + MaxRandomDelayMins = 240 + Start = '2/1/1970 00:00' + MaxThirdPartyMifSize = 250 + CollectMifFile = 'None' + ClientSettingName = 'Default Client Agent Settings' + ScheduleType = 'Days' + } + + CMClientSettingsHardware DeviceAgent + { + SiteCode = 'Lab' + Enable = $true + RecurInterval = 1 + MaxRandomDelayMins = 240 + Start = '2/1/1970 00:00' + ClientSettingName = 'ClientTest' + ScheduleType = 'Hours' + } + } +} diff --git a/source/Examples/Resources/CMClientSettingsMetered/CMClientSettingsMetered.ps1 b/source/Examples/Resources/CMClientSettingsMetered/CMClientSettingsMetered.ps1 new file mode 100644 index 00000000..56c71614 --- /dev/null +++ b/source/Examples/Resources/CMClientSettingsMetered/CMClientSettingsMetered.ps1 @@ -0,0 +1,25 @@ +<# + .SYNOPSIS + A DSC configuration script to modify client policy settings for metered network. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettingsMetered DefaultAgent + { + SiteCode = 'Lab' + MeteredNetworkUsage = 'Block' + ClientSettingName = 'Default Client Agent Settings' + } + + CMClientSettingsMetered DeviceAgent + { + SiteCode = 'Lab' + MeteredNetworkUsage = 'Allow' + ClientSettingName = 'ClientTest' + } + } +} diff --git a/source/Examples/Resources/CMClientSettingsPower/CMClientSettingsPower.ps1 b/source/Examples/Resources/CMClientSettingsPower/CMClientSettingsPower.ps1 new file mode 100644 index 00000000..0c7a3782 --- /dev/null +++ b/source/Examples/Resources/CMClientSettingsPower/CMClientSettingsPower.ps1 @@ -0,0 +1,35 @@ +<# + .SYNOPSIS + A DSC configuration script to modify client policy settings for powered settings. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettingsPower DefaultAgent + { + SiteCode = 'Lab' + Enable = $true + AllowUserToOptOutFromPowerPlan = $false + EnableWakeUpProxy = $false + NetworkWakeUpOption = 'NotConfigured' + ClientSettingName = 'Default Client Agent Settings' + } + + CMClientSettingsPower DeviceAgent + { + SiteCode = 'Lab' + Enable = $true + WakeupProxyDirectAccessPrefix = '2001:0DB8:0000:000b::/64,2001:0DB8:0000:000b::/62' + AllowUserToOptOutFromPowerPlan = $false + WakeupProxyPort = 10 + FirewallExceptionForWakeupProxy = 'Domain','Private' + EnableWakeUpProxy = $true + WakeOnLanPort = 50 + NetworkWakeUpOption = 'Enabled' + ClientSettingName = 'ClientTest' + } + } +} diff --git a/source/Examples/Resources/CMClientSettingsRemoteTools/CMClientSettingsRemoteTools.ps1 b/source/Examples/Resources/CMClientSettingsRemoteTools/CMClientSettingsRemoteTools.ps1 new file mode 100644 index 00000000..da7ec167 --- /dev/null +++ b/source/Examples/Resources/CMClientSettingsRemoteTools/CMClientSettingsRemoteTools.ps1 @@ -0,0 +1,57 @@ +<# + .SYNOPSIS + A DSC configuration script to modify client policy settings for remote tools settings. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettingsRemoteTools DefaultClient + { + SiteCode = 'Lab' + GrantPermissionToLocalAdministrator = $false + ManageRemoteDesktopSetting = $true + AllowUnattendedComputer = $true + RequireAuthentication = $true + AllowClientChange = $true + PermittedViewer = 'Contoso\Remote Control Users' + ClientSettingName = 'Default Client Agent Settings' + FirewallExceptionProfile = 'Domain' + RemoteAssistanceAccessLevel = 'None' + PromptUserForClipboardPermission = $true + AccessLevel = 'FullControl' + AudibleSignal = 'PlaySoundAtBeginAndEnd' + PromptUserForPermission = $false + ShowSessionConnectionBar = $true + ManageSolicitedRemoteAssistance = $true + ManageUnsolicitedRemoteAssistance = $true + AllowPermittedViewer = $true + ShowNotificationIconOnTaskbar = $true + } + + CMClientSettingsRemoteTools DeviceClient + { + SiteCode = 'Lab' + GrantPermissionToLocalAdministrator = $false + ManageRemoteDesktopSetting = $false + AllowUnattendedComputer = $false + RequireAuthentication = $true + AllowClientChange = $false + PermittedViewer = 'contoso\Remote Control Users' + ClientSettingName = 'TestClient' + RemoteAssistanceAccessLevel = 'None' + PromptUserForClipboardPermission = $false + AccessLevel = 'NoAccess' + AudibleSignal = 'PlayNoSound' + PromptUserForPermission = $false + ShowSessionConnectionBar = $false + ManageSolicitedRemoteAssistance = $false + ManageUnsolicitedRemoteAssistance = $false + AllowPermittedViewer = $true + ShowNotificationIconOnTaskbar = $false + FirewallExceptionProfile = 'Domain','Private' + } + } +} diff --git a/source/Examples/Resources/CMClientSettingsSoftwareCenter/CMClientSettingsSoftwareCenter.ps1 b/source/Examples/Resources/CMClientSettingsSoftwareCenter/CMClientSettingsSoftwareCenter.ps1 new file mode 100644 index 00000000..16c563f9 --- /dev/null +++ b/source/Examples/Resources/CMClientSettingsSoftwareCenter/CMClientSettingsSoftwareCenter.ps1 @@ -0,0 +1,36 @@ +<# + .SYNOPSIS + A DSC configuration script to modify client policy settings for software center settings. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettingsSoftwareCenter 'Default Client Agent Settings' + { + SiteCode = 'Lab' + HideUnapprovedApplication = $false + CompanyName = 'Test' + HideApplicationCatalogLink = $false + EnableCustomize = $true + EnableOptionsTab = $true + ClientSettingName = 'Default Client Agent Settings' + EnableStatusTab = $true + EnableComplianceTab = $true + HideInstalledApplication = $true + EnableApplicationsTab = $true + ColorScheme = '#CB4154' + EnableUpdatesTab = $true + EnableOperatingSystemsTab = $true + } + + CMClientSettingsSoftwareCenter 'TestClient' + { + SiteCode = 'Lab' + EnableCustomize = $false + ClientSettingName = 'TestClient' + } + } +} diff --git a/source/Examples/Resources/CMClientSettingsSoftwareDeployment/CMClientSettingsSoftwareDeployment.ps1 b/source/Examples/Resources/CMClientSettingsSoftwareDeployment/CMClientSettingsSoftwareDeployment.ps1 new file mode 100644 index 00000000..58d76c60 --- /dev/null +++ b/source/Examples/Resources/CMClientSettingsSoftwareDeployment/CMClientSettingsSoftwareDeployment.ps1 @@ -0,0 +1,29 @@ +<# + .SYNOPSIS + A DSC configuration script to modify client policy settings for software deployment settings. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettingsSoftwareDeployment DefaultAgent + { + SiteCode = 'Lab' + RecurInterval = 7 + Start = '2/1/1970 00:00' + ScheduleType = 'Days' + ClientSettingName = 'Default Client Agent Settings' + } + + CMClientSettingsSoftwareDeployment DeviceAgent + { + SiteCode = 'Lab' + RecurInterval = 1 + Start = '2/1/1970 00:00' + ScheduleType = 'Hours' + ClientSettingName = 'ClientTest' + } + } +} diff --git a/source/Examples/Resources/CMClientSettingsSoftwareInventory/CMClientSettingsSoftwareInventory.ps1 b/source/Examples/Resources/CMClientSettingsSoftwareInventory/CMClientSettingsSoftwareInventory.ps1 new file mode 100644 index 00000000..7e9223c6 --- /dev/null +++ b/source/Examples/Resources/CMClientSettingsSoftwareInventory/CMClientSettingsSoftwareInventory.ps1 @@ -0,0 +1,29 @@ +<# + .SYNOPSIS + A DSC configuration script to modify client policy settings for software inventory settings. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettingsSoftwareInventory DefaultAgent + { + SiteCode = 'Lab' + Enable = $false + ClientSettingName = 'Default Client Agent Settings' + } + + CMClientSettingsSoftwareInventory DeviceAgent + { + SiteCode = 'Lab' + Enable = $true + RecurInterval = 7 + Start = '2/1/1970 00:00' + ScheduleType = 'Days' + ReportOption = 'ProductOnly' + ClientSettingName = 'ClientTest' + } + } +} diff --git a/source/Examples/Resources/CMClientSettingsSoftwareMetering/CMClientSettingsSoftwareMetering.ps1 b/source/Examples/Resources/CMClientSettingsSoftwareMetering/CMClientSettingsSoftwareMetering.ps1 new file mode 100644 index 00000000..5098f592 --- /dev/null +++ b/source/Examples/Resources/CMClientSettingsSoftwareMetering/CMClientSettingsSoftwareMetering.ps1 @@ -0,0 +1,28 @@ +<# + .SYNOPSIS + A DSC configuration script to modify client policy settings for software metering settings. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettingsSoftwareMetering DefaultAgent + { + SiteCode = 'Lab' + Enable = $true + RecurInterval = 4 + Start = '2/1/1970 00:00' + ClientSettingName = 'Default Client Agent Settings' + ScheduleType = 'Hours' + } + + CMClientSettingsSoftwareMetering DeviceAgent + { + SiteCode = 'Lab' + Enable = $false + ClientSettingName = 'ClientTest' + } + } +} diff --git a/source/Examples/Resources/CMClientSettingsSoftwareUpdate/CMClientSettingsSoftwareUpdate.ps1 b/source/Examples/Resources/CMClientSettingsSoftwareUpdate/CMClientSettingsSoftwareUpdate.ps1 new file mode 100644 index 00000000..47bceab2 --- /dev/null +++ b/source/Examples/Resources/CMClientSettingsSoftwareUpdate/CMClientSettingsSoftwareUpdate.ps1 @@ -0,0 +1,51 @@ +<# + .SYNOPSIS + A DSC configuration script to modify client policy settings for software update settings. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettingsSoftwareUpdate DefaultAgent + { + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + EnableDeltaDownload = $true + DeltaDownloadPort = 8005 + ScanStart = '2/1/1970 00:00' + ScanRecurInterval = 8 + ScanScheduleType = 'Hours' + EvalStart = '2/1/1970 00:00' + EvalScheduleType = 'Hours' + EvalRecurInterval = 8 + EnforceMandatory = $true + TimeUnit = 'Hours' + BatchingTimeOut = 1 + EnableThirdPartyUpdates = $true + Office365ManagementType = 'Yes' + } + + CMClientSettingsSoftwareUpdate DeviceAgent + { + SiteCode = 'Lab' + ClientSettingName = 'PC Imaging' + Enable = $true + ScanStart = '2/1/1970 00:00' + ScanScheduleType = 'Hours' + ScanRecurInterval = 1 + EvalStart = '2/1/1970 00:00' + EvalScheduleType = 'Hours' + EvalRecurInterval = 3 + EnableDeltaDownload = $true + DeltaDownloadPort = 8005 + EnforceMandatory = $true + TimeUnit = 'Hours' + BatchingTimeOut = 23 + EnableThirdPartyUpdates = $true + Office365ManagementType = 'NotConfigured' + } + } +} diff --git a/source/Examples/Resources/CMClientSettingsStateMessaging/CMClientSettingsStateMessaging.ps1 b/source/Examples/Resources/CMClientSettingsStateMessaging/CMClientSettingsStateMessaging.ps1 new file mode 100644 index 00000000..4a782870 --- /dev/null +++ b/source/Examples/Resources/CMClientSettingsStateMessaging/CMClientSettingsStateMessaging.ps1 @@ -0,0 +1,25 @@ +<# + .SYNOPSIS + A DSC configuration script to modify client policy settings for state messaging settings. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettingsStateMessaging DefaultAgent + { + SiteCode = 'Lab' + ReportingCycleMins = 100 + ClientSettingName = 'Default Client Agent Settings' + } + + CMClientSettingsStateMessaging DeviceAgent + { + SiteCode = 'Lab' + ReportingCycleMins = 60 + ClientSettingName = 'ClientTest' + } + } +} diff --git a/source/Examples/Resources/CMClientSettingsUserDeviceAffinity/CMClientSettingsUserDeviceAffinity.ps1 b/source/Examples/Resources/CMClientSettingsUserDeviceAffinity/CMClientSettingsUserDeviceAffinity.ps1 new file mode 100644 index 00000000..6406d0cf --- /dev/null +++ b/source/Examples/Resources/CMClientSettingsUserDeviceAffinity/CMClientSettingsUserDeviceAffinity.ps1 @@ -0,0 +1,37 @@ +<# + .SYNOPSIS + A DSC configuration script to modify client policy settings for user device affinity settings. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMClientSettingsUserDeviceAffinity DefaultAgent + { + SiteCode = 'Lab' + UsageThresholdDays = 30 + AutoApproveAffinity = $true + ClientSettingName = 'Default Client Agent Settings' + LogOnThresholdMins = 2880 + AllowUserAffinity = $true + } + + CMClientSettingsUserDeviceAffinity DeviceAgent + { + SiteCode = 'Lab' + UsageThresholdDays = 30 + AutoApproveAffinity = $false + ClientSettingName = 'ClientTest' + LogOnThresholdMins = 2880 + } + + CMClientSettingsUserDeviceAffinity UserAgent + { + SiteCode = 'Lab' + ClientSettingName = 'UserTest' + AllowUserAffinity = $true + } + } +} diff --git a/source/Modules/ConfigMgrCBDsc.ReverseDsc/ConfigMgrCBDsc.ReverseDsc.psm1 b/source/Modules/ConfigMgrCBDsc.ReverseDsc/ConfigMgrCBDsc.ReverseDsc.psm1 index aab1cd7a..d42c6cb4 100644 --- a/source/Modules/ConfigMgrCBDsc.ReverseDsc/ConfigMgrCBDsc.ReverseDsc.psm1 +++ b/source/Modules/ConfigMgrCBDsc.ReverseDsc/ConfigMgrCBDsc.ReverseDsc.psm1 @@ -66,6 +66,10 @@ function Assert-CMModule { $properties.Add($prop.Name,$CollectionName) } + elseif ($prop.Name -eq 'Type') + { + $properties.Add($prop.Name,'Device') + } elseif ($prop.PropertyType -eq '[string]') { $properties.Add($prop.Name,$StringValue) @@ -219,7 +223,11 @@ function Set-OutFile if ($ResourceName -eq 'CMCollections' -or $ResourceName -eq 'CMAssetIntelligencePoint' -or $ResourceName -eq 'CMMaintenanceWindows' -or $ResourceName -eq 'CMGroupDiscovery' -or - $ResourceName -eq 'CMSoftwareUpdatePointComponent') + $ResourceName -eq 'CMSoftwareUpdatePointComponent' -or + $ResourceName -eq 'CMClientSettingsCompliance' -or $ResourceName -eq 'CMClientSettingsHardware' -or + $ResourceName -eq 'CMClientSettingsSoftwareDeployment' -or + $ResourceName -eq 'CMClientSettingsSoftwareInventory' -or + $ResourceName -eq 'CMClientSettingsSoftwareMetering') { if ($cPush.ScheduleType -eq 'None') { @@ -322,7 +330,7 @@ function Set-OutFile $tester += "`t`t`t@{`r`n" $tester += "`t`t`t`tName = '$($item.Name)'`r`n" $tester += "`t`t`t`tLdapLocation = '$($item.LdapLocation)'`r`n" - $tester += "`t`t`t`tRecurse = '$($item.Recurse)'`r`n" + $tester += "`t`t`t`tRecurse = `$$($item.Recurse)`r`n" $tester += "`t`t`t}`r`n" } $tester += "`t`t)`r`n" @@ -332,7 +340,8 @@ function Set-OutFile { $wPush += "$tester}" } - else { + else + { $wPush += "$tester`t}`r`n" } @@ -492,6 +501,82 @@ Configuration ConfigureSccm [HashTable] `$CMClientPushSettings, + [Parameter()] + [HashTable[]] + `$CMClientSettings, + + [Parameter()] + [HashTable[]] + `$CMClientSettingsBits, + + [Parameter()] + [HashTable[]] + `$CMClientSettingsClientCache, + + [Parameter()] + [HashTable[]] + `$CMClientSettingsClientPolicy, + + [Parameter()] + [HashTable[]] + `$CMClientSettingsCloudService, + + [Parameter()] + [HashTable[]] + `$CMClientSettingsCompliance, + + [Parameter()] + [HashTable[]] + `$CMClientSettingsComputerAgent, + + [Parameter()] + [HashTable[]] + `$CMClientSettingsDelivery, + + [Parameter()] + [HashTable[]] + `$CMClientSettingsHardware, + + [Parameter()] + [HashTable[]] + `$CMClientSettingsMetered, + + [Parameter()] + [HashTable[]] + `$CMClientSettingsPower, + + [Parameter()] + [HashTable[]] + `$CMClientSettingsRemoteTools, + + [Parameter()] + [HashTable[]] + `$CMClientSettingsSoftwareCenter, + + [Parameter()] + [HashTable[]] + `$CMClientSettingsSoftwareDeployment, + + [Parameter()] + [HashTable[]] + `$CMClientSettingsSoftwareInventory, + + [Parameter()] + [HashTable[]] + `$CMClientSettingsSoftwareMetering, + + [Parameter()] + [HashTable[]] + `$CMClientSettingsSoftwareUpdate, + + [Parameter()] + [HashTable[]] + `$CMClientSettingsStateMessaging, + + [Parameter()] + [HashTable[]] + `$CMClientSettingsUserDeviceAffinity, + [Parameter()] [HashTable] `$CMClientStatusSettings, @@ -6819,278 +6904,4637 @@ Configuration ConfigureSccm } } } - } -} - -`$cd = @{ - AllNodes = @( - @{ - NodeName = 'localhost' - PSDscAllowPlainTextPassword = `$true - PSDscAllowDomainUser = `$true - } - ) -} - -ConfigureSccm -OutputPath $MofOutPutPath -ConfigurationData `$cd -DataFile $DataFile -" -} - -<# - .SYNOPSIS - This will create the data file and\or configuration. - - .PARAMETER SiteCode - Specifies the site code for Configuration Manager site. - - .PARAMETER Include - Specifies which resources will be invoked, default setting: All. - - .PARAMETER Exclude - Specifies which resources will be excluded from being evaluated. - - .PARAMETER DataFile - Specifies where the data file will be saved. - - .PARAMETER ConfigOutputPath - Specifies where the configuration file will be saved. - - .PARAMETER MofOutPutPath - Specifies where the mof file will be saved when running the configuration. -#> -function Set-ConfigMgrCBDscReverse -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [String] - $SiteCode, - - [Parameter()] - [ValidateSet('All','Accounts','AdministrativeUser','AssetIntelligencePoint','BoundaryGroups', - 'ClientPush','ClientStatusSettings','CollectionEvaluationComponent','Collections', - 'DistributionGroups','DistributionPoint','DistributionPointGroupMembers', - 'EmailNotificationComponent','FallbackPoints','ForestDiscovery','HeartbeatDiscovery', - 'MaintenanceWindow','ManagementPoint','NetworkDiscovery','PullDistributionPoint', - 'PxeDistributionPoint','ReportingServicesPoint','SecurityScopes','ServiceConnection', - 'SiteMaintenance','SiteSystemServer','SoftwareDistributionComponent','SoftwareupdatePoint', - 'StatusReportingComponent','SystemDiscovery','UserDiscovery','ConfigFileOnly','GroupDiscovery', - 'SoftwareUpdatePointComponent')] - [String[]] - $Include = 'All', - - [Parameter()] - [ValidateSet('Accounts','AdministrativeUser','AssetIntelligencePoint','BoundaryGroups', - 'ClientPush','ClientStatusSettings','CollectionEvaluationComponent','Collections', - 'DistributionGroups','DistributionPoint','DistributionPointGroupMembers', - 'EmailNotificationComponent','FallbackPoints','ForestDiscovery','HeartbeatDiscovery', - 'MaintenanceWindow','ManagementPoint','NetworkDiscovery','PullDistributionPoint', - 'PxeDistributionPoint','ReportingServicesPoint','SecurityScopes','ServiceConnection', - 'SiteMaintenance','SiteSystemServer','SoftwareDistributionComponent','SoftwareupdatePoint', - 'StatusReportingComponent','SystemDiscovery','UserDiscovery','GroupDiscovery', - 'SoftwareUpdatePointComponent')] - [String[]] - $Exclude, - [Parameter()] - [ValidateScript( + if (`$CMClientSettings) + { + foreach (`$client in `$CMClientSettings) { - if ($_.Substring($_.Length -5,5) -eq '.psd1') + if (`$client.Description) { - $true + CMClientSettings `$client.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$client.ClientSettingName + Type = `$client.Type + Description = `$client.Description + SecurityScopes = `$client.SecurityScopes + Ensure = `$client.Ensure + DependsOn = `$cmSecurityScopesDependsOn + } } else { - throw $script:localizedData.DataFileEr + CMClientSettings `$client.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$client.ClientSettingName + Type = `$client.Type + SecurityScopes = `$client.SecurityScopes + Ensure = `$client.Ensure + DependsOn = `$cmSecurityScopesDependsOn + } } + + [array]`$cmClientSettingsDependsOn += `"[CMClientSettings]`$(`$client.ClientSettingName)`" } - )] - [String] - $DataFile, + } - [Parameter()] - [ValidateScript( + if (`$CMClientSettingsBits) + { + foreach (`$bitsSetting in `$CMClientSettingsBits) { - if ($_.Substring($_.Length -4,4) -eq '.ps1') + if (`$bitsSetting.EnableBitsMaxBandwidth -eq `$false) { - $true + CMClientSettingsBits `$bitsSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$bitsSetting.ClientSettingName + EnableBitsMaxBandwidth = `$bitsSetting.EnableBitsMaxBandwidth + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$bitsSetting.EnableDownloadOffSchedule -eq `$false) + { + CMClientSettingsBits `$bitsSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$bitsSetting.ClientSettingName + EnableBitsMaxBandwidth = `$bitsSetting.EnableBitsMaxBandwidth + MaxBandwidthBeginHr = `$bitsSetting.MaxBandwidthBeginHr + MaxBandwidthEndHr = `$bitsSetting.MaxBandwidthEndHr + MaxTransferRateOnSchedule = `$bitsSetting.MaxTransferRateOnSchedule + EnableDownloadOffSchedule = `$bitsSetting.EnableDownloadOffSchedule + DependsOn = `$cmClientSettingsDependsOn + } } else { - throw $script:localizedData.ConfigOutputPathEr + CMClientSettingsBits `$bitsSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$bitsSetting.ClientSettingName + EnableBitsMaxBandwidth = `$bitsSetting.EnableBitsMaxBandwidth + MaxBandwidthBeginHr = `$bitsSetting.MaxBandwidthBeginHr + MaxBandwidthEndHr = `$bitsSetting.MaxBandwidthEndHr + MaxTransferRateOnSchedule = `$bitsSetting.MaxTransferRateOnSchedule + EnableDownloadOffSchedule = `$bitsSetting.EnableDownloadOffSchedule + MaxTransferRateOffSchedule = `$bitsSetting.MaxTransferRateOffSchedule + DependsOn = `$cmClientSettingsDependsOn + } } } - )] - [String] - $ConfigOutputPath, - - [Parameter()] - [String] - $MofOutPutPath - ) - - Import-ConfigMgrPowerShellModule -SiteCode $SiteCode - Set-Location -Path "$($SiteCode):\" - - if (($ConfigOutputPath -or $MofOutPutPath) -and ([string]::IsNullOrEmpty($ConfigOutputPath) -or - [string]::IsNullOrEmpty($MofOutPutPath) -or [string]::IsNullOrEmpty($DataFile))) - { - throw $script:localizedData.MissingParams - } - - Import-Module -Name 'ConfigMgrCBDsc' - $resources = Get-DscResource -Module 'ConfigMgrCBDsc' - - if ($Include -ne 'All' -and -not [string]::IsNullOrEmpty($Exclude)) - { - Write-Warning -Message $script:localizedData.ExcludeMsg - } - - $fileOut = "@{`r`nSiteCode = '$SiteCode'`r`n" - - if (($Include -contains 'All' -and $Exclude -notcontains 'Accounts') -or ($Include -contains 'Accounts')) - { - $resourceName = 'CMAccounts' - $accounts = Get-CMAccount -SiteCode $SiteCode + } - if ($accounts) + if (`$CMClientSettingsClientCache) { - $wCMAccounts = "$ResourceName = @(`r`n" + foreach (`$clientCache in `$CMClientSettingsClientCache) + { + if (`$clientCache.ConfigureBranchCache -eq `$true -and + `$clientCache.ConfigureCacheSize -eq `$true -and + `$clientCache.EnableSuperPeer -eq `$true) + { + CMClientSettingsClientCache `$clientCache.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$clientCache.ClientSettingName + ConfigureBranchCache = `$clientCache.ConfigureBranchCache + EnableBranchCache = `$clientCache.EnableBranchCache + MaxBranchCacheSizePercent = `$clientCache.MaxBranchCacheSizePercent + ConfigureCacheSize = `$clientCache.ConfigureCacheSize + MaxCacheSize = `$clientCache.MaxCacheSize + MaxCacheSizePercent = `$clientCache.MaxCacheSizePercent + EnableSuperPeer = `$clientCache.EnableSuperPeer + BroadcastPort = `$clientCache.BroadcastPort + DownloadPort = `$clientCache.DownloadPort + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$clientCache.ConfigureBranchCache -eq `$true -and + `$clientCache.ConfigureCacheSize -eq `$true -and + `$clientCache.EnableSuperPeer -eq `$false) + { + CMClientSettingsClientCache `$clientCache.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$clientCache.ClientSettingName + ConfigureBranchCache = `$clientCache.ConfigureBranchCache + EnableBranchCache = `$clientCache.EnableBranchCache + MaxBranchCacheSizePercent = `$clientCache.MaxBranchCacheSizePercent + ConfigureCacheSize = `$clientCache.ConfigureCacheSize + MaxCacheSize = `$clientCache.MaxCacheSize + MaxCacheSizePercent = `$clientCache.MaxCacheSizePercent + EnableSuperPeer = `$clientCache.EnableSuperPeer + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$clientCache.ConfigureBranchCache -eq `$true -and + `$clientCache.ConfigureCacheSize -eq `$false -and + `$clientCache.EnableSuperPeer -eq `$true) + { + CMClientSettingsClientCache `$clientCache.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$clientCache.ClientSettingName + ConfigureBranchCache = `$clientCache.ConfigureBranchCache + EnableBranchCache = `$clientCache.EnableBranchCache + MaxBranchCacheSizePercent = `$clientCache.MaxBranchCacheSizePercent + ConfigureCacheSize = `$clientCache.ConfigureCacheSize + EnableSuperPeer = `$clientCache.EnableSuperPeer + BroadcastPort = `$clientCache.BroadcastPort + DownloadPort = `$clientCache.DownloadPort + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$clientCache.ConfigureBranchCache -eq `$true -and + `$clientCache.ConfigureCacheSize -eq `$false -and + `$clientCache.EnableSuperPeer -eq `$false) + { + CMClientSettingsClientCache `$clientCache.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$clientCache.ClientSettingName + ConfigureBranchCache = `$clientCache.ConfigureBranchCache + EnableBranchCache = `$clientCache.EnableBranchCache + MaxBranchCacheSizePercent = `$clientCache.MaxBranchCacheSizePercent + ConfigureCacheSize = `$clientCache.ConfigureCacheSize + EnableSuperPeer = `$clientCache.EnableSuperPeer + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$clientCache.ConfigureBranchCache -eq `$false -and + `$clientCache.ConfigureCacheSize -eq `$true -and + `$clientCache.EnableSuperPeer -eq `$true) + { + CMClientSettingsClientCache `$clientCache.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$clientCache.ClientSettingName + ConfigureBranchCache = `$clientCache.ConfigureBranchCache + ConfigureCacheSize = `$clientCache.ConfigureCacheSize + MaxCacheSize = `$clientCache.MaxCacheSize + EnableSuperPeer = `$clientCache.EnableSuperPeer + BroadcastPort = `$clientCache.BroadcastPort + DownloadPort = `$clientCache.DownloadPort + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$clientCache.ConfigureBranchCache -eq `$false -and + `$clientCache.ConfigureCacheSize -eq `$true -and + `$clientCache.EnableSuperPeer -eq `$false) + { + CMClientSettingsClientCache `$clientCache.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$clientCache.ClientSettingName + ConfigureBranchCache = `$clientCache.ConfigureBranchCache + ConfigureCacheSize = `$clientCache.ConfigureCacheSize + MaxCacheSize = `$clientCache.MaxCacheSize + EnableSuperPeer = `$clientCache.EnableSuperPeer + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$clientCache.ConfigureBranchCache -eq `$false -and + `$clientCache.ConfigureCacheSize -eq `$false -and + `$clientCache.EnableSuperPeer -eq `$true) + { + CMClientSettingsClientCache `$clientCache.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$clientCache.ClientSettingName + ConfigureBranchCache = `$clientCache.ConfigureBranchCache + ConfigureCacheSize = `$clientCache.ConfigureCacheSize + EnableSuperPeer = `$clientCache.EnableSuperPeer + BroadcastPort = `$clientCache.BroadcastPort + DownloadPort = `$clientCache.DownloadPort + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$clientCache.ConfigureBranchCache -eq `$false -and + `$clientCache.ConfigureCacheSize -eq `$false -and + `$clientCache.EnableSuperPeer -eq `$false) + { + CMClientSettingsClientCache `$clientCache.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$clientCache.ClientSettingName + ConfigureBranchCache = `$clientCache.ConfigureBranchCache + ConfigureCacheSize = `$clientCache.ConfigureCacheSize + EnableSuperPeer = `$clientCache.EnableSuperPeer + DependsOn = `$cmClientSettingsDependsOn + } + } + } } - foreach ($account in $accounts) + if (`$CMClientSettingsClientPolicy) { - Write-Verbose -Message ($script:localizedData.CMAccounts -f $account.UserName) -Verbose - $params = @{ - ResourceName = $resourceName - SiteCode = $SiteCode - ExcludeList = @('SiteCode','AccountPassword') - Count = 7 - Indent = 2 - StringValue = $account.UserName - MultiEntry = $true - Resources = $resources + foreach (`$clientPolicy in `$CMClientSettingsClientPolicy) + { + CMClientSettingsClientPolicy `$clientPolicy.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$clientPolicy.ClientSettingName + PolicyPollingMins = `$clientPolicy.PolicyPollingMins + EnableUserPolicy = `$clientPolicy.EnableUserPolicy + EnableUserPolicyOnInternet = `$clientPolicy.EnableUserPolicyOnInternet + EnableUserPolicyOnTS = `$clientPolicy.EnableUserPolicyOnTS + DependsOn = `$cmClientSettingsDependsOn + } } - - $testThing = Set-OutFile @params - $wCMAccounts += "$testThing" } - if ($wCMAccounts) + if (`$CMClientSettingsCloudService) { - $wCMAccounts += ")" - $fileOut += "$wCMAccounts`r`n" + foreach (`$cloudService in `$CMClientSettingsCloudService) + { + if ([string]::IsNullOrEmpty(`$cloudService.AutoAzureADJoin)) + { + CMClientSettingsCloudService `$cloudService.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$cloudService.ClientSettingName + AllowCloudDistributionPoint = `$cloudService.AllowCloudDistributionPoint + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsCloudService `$cloudService.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$cloudService.ClientSettingName + AllowCloudDistributionPoint = `$cloudService.AllowCloudDistributionPoint + AutoAzureADJoin = `$cloudService.AutoAzureADJoin + AllowCloudManagementGateway = `$cloudService.AllowCloudManagementGateway + DependsOn = `$cmClientSettingsDependsOn + } + } + } } - } - if (($Include -eq 'All' -and $Exclude -notcontains 'AdministrativeUser') -or ($Include -eq 'AdministrativeUser')) - { + if (`$CMClientSettingsCompliance) + { + foreach (`$complianceSetting in `$CMClientSettingsCompliance) + { + if (`$complianceSetting.Enable -eq `$false) + { + CMClientSettingsCompliance `$complianceSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$complianceSetting.ClientSettingName + Enable = `$complianceSetting.Enable + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif ([string]::IsNullOrEmpty(`$complianceSetting.ScheduleType)) + { + CMClientSettingsCompliance `$complianceSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$complianceSetting.ClientSettingName + Enable = `$complianceSetting.Enable + EnableUserDataAndProfile = `$complianceSetting.EnableUserDataAndProfile + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$complianceSetting.ScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsCompliance `$complianceSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$complianceSetting.ClientSettingName + Enable = `$complianceSetting.Enable + EnableUserDataAndProfile = `$complianceSetting.EnableUserDataAndProfile + Start = `$complianceSetting.Start + ScheduleType = `$complianceSetting.ScheduleType + RecurInterval = `$complianceSetting.RecurInterval + DayOfMonth = `$complianceSetting.DayOfMonth + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$complianceSetting.ScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsCompliance `$complianceSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$complianceSetting.ClientSettingName + Enable = `$complianceSetting.Enable + EnableUserDataAndProfile = `$complianceSetting.EnableUserDataAndProfile + Start = `$complianceSetting.Start + ScheduleType = `$complianceSetting.ScheduleType + RecurInterval = `$complianceSetting.RecurInterval + DayOfWeek = `$complianceSetting.DayOfWeek + MonthlyWeekOrder = `$complianceSetting.MonthlyWeekOrder + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$complianceSetting.ScheduleType -eq 'Weekly') + { + CMClientSettingsCompliance `$complianceSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$complianceSetting.ClientSettingName + Enable = `$complianceSetting.Enable + EnableUserDataAndProfile = `$complianceSetting.EnableUserDataAndProfile + Start = `$complianceSetting.Start + ScheduleType = `$complianceSetting.ScheduleType + RecurInterval = `$complianceSetting.RecurInterval + DayOfWeek = `$complianceSetting.DayOfWeek + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$complianceSetting.ScheduleType -eq 'None') + { + CMClientSettingsCompliance `$complianceSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$complianceSetting.ClientSettingName + Enable = `$complianceSetting.Enable + EnableUserDataAndProfile = `$complianceSetting.EnableUserDataAndProfile + Start = `$complianceSetting.Start + ScheduleType = `$complianceSetting.ScheduleType + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsCompliance `$complianceSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$complianceSetting.ClientSettingName + Enable = `$complianceSetting.Enable + EnableUserDataAndProfile = `$complianceSetting.EnableUserDataAndProfile + Start = `$complianceSetting.Start + ScheduleType = `$complianceSetting.ScheduleType + RecurInterval = `$complianceSetting.RecurInterval + DependsOn = `$cmClientSettingsDependsOn + } + } + } + } + + if (`$CMClientSettingsComputerAgent) + { + foreach (`$agent in `$CMClientSettingsComputerAgent) + { + if (`$agent.EnableHealthAttestation -eq `$true) + { + CMClientSettingsComputerAgent `$agent.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$agent.ClientSettingName + InitialReminderHr = `$agent.InitialReminderHr + InterimReminderHr = `$agent.InterimReminderHr + FinalReminderMins = `$agent.FinalReminderMins + BrandingTitle = `$agent.BrandingTitle + UseNewSoftwareCenter = `$agent.UseNewSoftwareCenter + EnableHealthAttestation = `$agent.EnableHealthAttestation + UseOnPremisesHealthAttestation = `$agent.UseOnPremisesHealthAttestation + InstallRestriction = `$agent.InstallRestriction + SuspendBitLocker = `$agent.SuspendBitLocker + EnableThirdPartyOrchestration = `$agent.EnableThirdPartyOrchestration + PowerShellExecutionPolicy = `$agent.PowerShellExecutionPolicy + DisplayNewProgramNotification = `$agent.DisplayNewProgramNotification + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsComputerAgent `$agent.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$agent.ClientSettingName + InitialReminderHr = `$agent.InitialReminderHr + InterimReminderHr = `$agent.InterimReminderHr + FinalReminderMins = `$agent.FinalReminderMins + BrandingTitle = `$agent.BrandingTitle + UseNewSoftwareCenter = `$agent.UseNewSoftwareCenter + EnableHealthAttestation = `$agent.EnableHealthAttestation + InstallRestriction = `$agent.InstallRestriction + SuspendBitLocker = `$agent.SuspendBitLocker + EnableThirdPartyOrchestration = `$agent.EnableThirdPartyOrchestration + PowerShellExecutionPolicy = `$agent.PowerShellExecutionPolicy + DisplayNewProgramNotification = `$agent.DisplayNewProgramNotification + DependsOn = `$cmClientSettingsDependsOn + } + } + } + } + + if (`$CMClientSettingsDelivery) + { + foreach (`$settingsDelivery in `$CMClientSettingsDelivery) + { + CMClientSettingsDelivery `$settingsDelivery.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$settingsDelivery.ClientSettingName + Enable = `$settingsDelivery.Enable + DependsOn = `$cmClientSettingsDependsOn + } + } + } + + if (`$CMClientSettingsHardware) + { + foreach (`$hardwareSetting in `$CMClientSettingsHardware) + { + if (`$hardwareSetting.Enable -eq `$false) + { + CMClientSettingsHardware `$hardwareSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$hardwareSetting.ClientSettingName + Enable = `$hardwareSetting.Enable + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$hardwareSetting.CollectMifFile) + { + if (`$hardwareSetting.ScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsHardware `$hardwareSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$hardwareSetting.ClientSettingName + Enable = `$hardwareSetting.Enable + MaxRandomDelayMins = `$hardwareSetting.MaxRandomDelayMins + Start = `$hardwareSetting.Start + ScheduleType = `$hardwareSetting.ScheduleType + RecurInterval = `$hardwareSetting.RecurInterval + DayOfMonth = `$hardwareSetting.DayOfMonth + CollectMifFile = `$hardwareSetting.CollectMifFile + MaxThirdPartyMifSize = `$hardwareSetting.MaxThirdPartyMifSize + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$hardwareSetting.ScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsHardware `$hardwareSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$hardwareSetting.ClientSettingName + Enable = `$hardwareSetting.Enable + MaxRandomDelayMins = `$hardwareSetting.MaxRandomDelayMins + Start = `$hardwareSetting.Start + ScheduleType = `$hardwareSetting.ScheduleType + RecurInterval = `$hardwareSetting.RecurInterval + DayOfWeek = `$hardwareSetting.DayOfWeek + MonthlyWeekOrder = `$hardwareSetting.MonthlyWeekOrder + CollectMifFile = `$hardwareSetting.CollectMifFile + MaxThirdPartyMifSize = `$hardwareSetting.MaxThirdPartyMifSize + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$hardwareSetting.ScheduleType -eq 'Weekly') + { + CMClientSettingsHardware `$hardwareSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$hardwareSetting.ClientSettingName + Enable = `$hardwareSetting.Enable + MaxRandomDelayMins = `$hardwareSetting.MaxRandomDelayMins + Start = `$hardwareSetting.Start + ScheduleType = `$hardwareSetting.ScheduleType + RecurInterval = `$hardwareSetting.RecurInterval + DayOfWeek = `$hardwareSetting.DayOfWeek + CollectMifFile = `$hardwareSetting.CollectMifFile + MaxThirdPartyMifSize = `$hardwareSetting.MaxThirdPartyMifSize + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$hardwareSetting.ScheduleType -eq 'None') + { + CMClientSettingsHardware `$hardwareSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$hardwareSetting.ClientSettingName + Enable = `$hardwareSetting.Enable + MaxRandomDelayMins = `$hardwareSetting.MaxRandomDelayMins + Start = `$hardwareSetting.Start + ScheduleType = `$hardwareSetting.ScheduleType + CollectMifFile = `$hardwareSetting.CollectMifFile + MaxThirdPartyMifSize = `$hardwareSetting.MaxThirdPartyMifSize + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsHardware `$hardwareSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$hardwareSetting.ClientSettingName + Enable = `$hardwareSetting.Enable + MaxRandomDelayMins = `$hardwareSetting.MaxRandomDelayMins + Start = `$hardwareSetting.Start + ScheduleType = `$hardwareSetting.ScheduleType + RecurInterval = `$hardwareSetting.RecurInterval + CollectMifFile = `$hardwareSetting.CollectMifFile + MaxThirdPartyMifSize = `$hardwareSetting.MaxThirdPartyMifSize + DependsOn = `$cmClientSettingsDependsOn + } + } + } + else + { + if (`$hardwareSetting.ScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsHardware `$hardwareSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$hardwareSetting.ClientSettingName + Enable = `$hardwareSetting.Enable + MaxRandomDelayMins = `$hardwareSetting.MaxRandomDelayMins + Start = `$hardwareSetting.Start + ScheduleType = `$hardwareSetting.ScheduleType + RecurInterval = `$hardwareSetting.RecurInterval + DayOfMonth = `$hardwareSetting.DayOfMonth + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$hardwareSetting.ScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsHardware `$hardwareSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$hardwareSetting.ClientSettingName + Enable = `$hardwareSetting.Enable + MaxRandomDelayMins = `$hardwareSetting.MaxRandomDelayMins + Start = `$hardwareSetting.Start + ScheduleType = `$hardwareSetting.ScheduleType + RecurInterval = `$hardwareSetting.RecurInterval + DayOfWeek = `$hardwareSetting.DayOfWeek + MonthlyWeekOrder = `$hardwareSetting.MonthlyWeekOrder + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$hardwareSetting.ScheduleType -eq 'Weekly') + { + CMClientSettingsHardware `$hardwareSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$hardwareSetting.ClientSettingName + Enable = `$hardwareSetting.Enable + MaxRandomDelayMins = `$hardwareSetting.MaxRandomDelayMins + Start = `$hardwareSetting.Start + ScheduleType = `$hardwareSetting.ScheduleType + RecurInterval = `$hardwareSetting.RecurInterval + DayOfWeek = `$hardwareSetting.DayOfWeek + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$hardwareSetting.ScheduleType -eq 'None') + { + CMClientSettingsHardware `$hardwareSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$hardwareSetting.ClientSettingName + Enable = `$hardwareSetting.Enable + MaxRandomDelayMins = `$hardwareSetting.MaxRandomDelayMins + Start = `$hardwareSetting.Start + ScheduleType = `$hardwareSetting.ScheduleType + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsHardware `$hardwareSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$hardwareSetting.ClientSettingName + Enable = `$hardwareSetting.Enable + MaxRandomDelayMins = `$hardwareSetting.MaxRandomDelayMins + Start = `$hardwareSetting.Start + ScheduleType = `$hardwareSetting.ScheduleType + RecurInterval = `$hardwareSetting.RecurInterval + DependsOn = `$cmClientSettingsDependsOn + } + } + } + } + } + + if (`$CMClientSettingsMetered) + { + foreach (`$settingsMetered in `$CMClientSettingsMetered) + { + CMClientSettingsMetered `$settingsMetered.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$settingsMetered.ClientSettingName + MeteredNetworkUsage = `$settingsMetered.MeteredNetworkUsage + DependsOn = `$cmClientSettingsDependsOn + } + } + } + + if (`$CMClientSettingsSoftwareDeployment) + { + foreach (`$softwareDeploy in `$CMClientSettingsSoftwareDeployment) + { + if (`$softwareDeploy.ScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareDeployment `$softwareDeploy.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softwareDeploy.ClientSettingName + Start = `$softwareDeploy.Start + ScheduleType = `$softwareDeploy.ScheduleType + RecurInterval = `$softwareDeploy.RecurInterval + DayOfMonth = `$softwareDeploy.DayOfMonth + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$softwareDeploy.ScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareDeployment `$softwareDeploy.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softwareDeploy.ClientSettingName + Start = `$softwareDeploy.Start + ScheduleType = `$softwareDeploy.ScheduleType + RecurInterval = `$softwareDeploy.RecurInterval + DayOfWeek = `$softwareDeploy.DayOfWeek + MonthlyWeekOrder = `$softwareDeploy.MonthlyWeekOrder + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$softwareDeploy.ScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareDeployment `$softwareDeploy.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softwareDeploy.ClientSettingName + Start = `$softwareDeploy.Start + ScheduleType = `$softwareDeploy.ScheduleType + RecurInterval = `$softwareDeploy.RecurInterval + DayOfWeek = `$softwareDeploy.DayOfWeek + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$softwareDeploy.ScheduleType -eq 'None') + { + CMClientSettingsSoftwareDeployment `$softwareDeploy.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softwareDeploy.ClientSettingName + Start = `$softwareDeploy.Start + ScheduleType = `$softwareDeploy.ScheduleType + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareDeployment `$softwareDeploy.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softwareDeploy.ClientSettingName + Start = `$softwareDeploy.Start + ScheduleType = `$softwareDeploy.ScheduleType + RecurInterval = `$softwareDeploy.RecurInterval + DependsOn = `$cmClientSettingsDependsOn + } + } + } + } + + if (`$CMClientSettingsSoftwareInventory) + { + foreach (`$softInvenSetting in `$CMClientSettingsSoftwareInventory) + { + if (`$softInvenSetting.Enable -eq `$false) + { + CMClientSettingsSoftwareInventory `$softInvenSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softInvenSetting.ClientSettingName + Enable = `$softInvenSetting.Enable + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$softInvenSetting.ScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareInventory `$softInvenSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softInvenSetting.ClientSettingName + Enable = `$softInvenSetting.Enable + ReportOption = `$softInvenSetting.ReportOption + Start = `$softInvenSetting.Start + ScheduleType = `$softInvenSetting.ScheduleType + RecurInterval = `$softInvenSetting.RecurInterval + DayOfMonth = `$softInvenSetting.DayOfMonth + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$softInvenSetting.ScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareInventory `$softInvenSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softInvenSetting.ClientSettingName + Enable = `$softInvenSetting.Enable + ReportOption = `$softInvenSetting.ReportOption + Start = `$softInvenSetting.Start + ScheduleType = `$softInvenSetting.ScheduleType + RecurInterval = `$softInvenSetting.RecurInterval + DayOfWeek = `$softInvenSetting.DayOfWeek + MonthlyWeekOrder = `$softInvenSetting.MonthlyWeekOrder + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$softInvenSetting.ScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareInventory `$softInvenSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softInvenSetting.ClientSettingName + Enable = `$softInvenSetting.Enable + ReportOption = `$softInvenSetting.ReportOption + Start = `$softInvenSetting.Start + ScheduleType = `$softInvenSetting.ScheduleType + RecurInterval = `$softInvenSetting.RecurInterval + DayOfWeek = `$softInvenSetting.DayOfWeek + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$softInvenSetting.ScheduleType -eq 'None') + { + CMClientSettingsSoftwareInventory `$softInvenSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softInvenSetting.ClientSettingName + Enable = `$softInvenSetting.Enable + ReportOption = `$softInvenSetting.ReportOption + Start = `$softInvenSetting.Start + ScheduleType = `$softInvenSetting.ScheduleType + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareInventory `$softInvenSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softInvenSetting.ClientSettingName + Enable = `$softInvenSetting.Enable + ReportOption = `$softInvenSetting.ReportOption + Start = `$softInvenSetting.Start + ScheduleType = `$softInvenSetting.ScheduleType + RecurInterval = `$softInvenSetting.RecurInterval + DependsOn = `$cmClientSettingsDependsOn + } + } + } + } + + if (`$CMClientSettingsSoftwareMetering) + { + foreach (`$softMetSetting in `$CMClientSettingsSoftwareMetering) + { + if (`$softMetSetting.Enable -eq `$false) + { + CMClientSettingsSoftwareMetering `$softMetSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softMetSetting.ClientSettingName + Enable = `$softMetSetting.Enable + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$softMetSetting.ScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareMetering `$softMetSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softMetSetting.ClientSettingName + Enable = `$softMetSetting.Enable + Start = `$softMetSetting.Start + ScheduleType = `$softMetSetting.ScheduleType + RecurInterval = `$softMetSetting.RecurInterval + DayOfMonth = `$softMetSetting.DayOfMonth + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$softMetSetting.ScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareMetering `$softMetSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softMetSetting.ClientSettingName + Enable = `$softMetSetting.Enable + Start = `$softMetSetting.Start + ScheduleType = `$softMetSetting.ScheduleType + RecurInterval = `$softMetSetting.RecurInterval + DayOfWeek = `$softMetSetting.DayOfWeek + MonthlyWeekOrder = `$softMetSetting.MonthlyWeekOrder + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$softMetSetting.ScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareMetering `$softMetSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softMetSetting.ClientSettingName + Enable = `$softMetSetting.Enable + Start = `$softMetSetting.Start + ScheduleType = `$softMetSetting.ScheduleType + RecurInterval = `$softMetSetting.RecurInterval + DayOfWeek = `$softMetSetting.DayOfWeek + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$softMetSetting.ScheduleType -eq 'None') + { + CMClientSettingsSoftwareMetering `$softMetSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softMetSetting.ClientSettingName + Enable = `$softMetSetting.Enable + Start = `$softMetSetting.Start + ScheduleType = `$softMetSetting.ScheduleType + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareMetering `$softMetSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softMetSetting.ClientSettingName + Enable = `$softMetSetting.Enable + Start = `$softMetSetting.Start + ScheduleType = `$softMetSetting.ScheduleType + RecurInterval = `$softMetSetting.RecurInterval + DependsOn = `$cmClientSettingsDependsOn + } + } + } + } + + if (`$CMClientSettingsSoftwareUpdate) + { + foreach (`$update in `$CMClientSettingsSoftwareUpdate) + { + if (`$update.Enable -eq `$false) + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EnforceMandatory -eq `$true -and `$update.EnableDeltaDownload -eq `$true) + { + if (`$update.ScanScheduleType -eq 'MonthlyByDay') + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + elseif (`$update.ScanScheduleType -eq 'MonthlyByWeek') + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + elseif (`$update.ScanScheduleType -eq 'Weekly') + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + elseif (`$update.ScanScheduleType -eq 'None') + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + else + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + } + elseif (`$update.EnforceMandatory -eq `$true -and `$update.EnableDeltaDownload -eq `$false) + { + if (`$update.ScanScheduleType -eq 'MonthlyByDay') + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + elseif (`$update.ScanScheduleType -eq 'MonthlyByWeek') + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + elseif (`$update.ScanScheduleType -eq 'Weekly') + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + elseif (`$update.ScanScheduleType -eq 'None') + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + else + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + TimeUnit = `$update.TimeUnit + BatchingTimeOut = `$update.BatchingTimeOut + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + } + elseif (`$update.EnforceMandatory -eq `$false -and `$update.EnableDeltaDownload -eq `$true) + { + if (`$update.ScanScheduleType -eq 'MonthlyByDay') + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + elseif (`$update.ScanScheduleType -eq 'MonthlyByWeek') + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + elseif (`$update.ScanScheduleType -eq 'Weekly') + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + elseif (`$update.ScanScheduleType -eq 'None') + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + else + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + DeltaDownloadPort = `$update.DeltaDownloadPort + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + } + elseif (`$update.EnforceMandatory -eq `$false -and `$update.EnableDeltaDownload -eq `$false) + { + if (`$update.ScanScheduleType -eq 'MonthlyByDay') + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfMonth = `$update.ScanDayOfMonth + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + elseif (`$update.ScanScheduleType -eq 'MonthlyByWeek') + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + ScanMonthlyWeekOrder = `$update.ScanMonthlyWeekOrder + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + elseif (`$update.ScanScheduleType -eq 'Weekly') + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + ScanDayOfWeek = `$update.ScanDayOfWeek + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + elseif (`$update.ScanScheduleType -eq 'None') + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + else + { + if (`$update.EvalScheduleType -eq 'MonthlyByDay') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfMonth = `$update.EvalDayOfMonth + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'MonthlyByWeek') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EvalMonthlyWeekOrder = `$update.MonthlyWeekOrder + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'Weekly') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EvalDayOfWeek = `$update.EvalDayOfWeek + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$update.EvalScheduleType -eq 'None') + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareUpdate `$update.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$update.ClientSettingName + Enable = `$update.Enable + ScanStart = `$update.ScanStart + ScanScheduleType = `$update.ScanScheduleType + ScanRecurInterval = `$update.ScanRecurInterval + EvalStart = `$update.EvalStart + EvalScheduleType = `$update.EvalScheduleType + EvalRecurInterval = `$update.EvalRecurInterval + EnforceMandatory = `$update.EnforceMandatory + EnableDeltaDownload = `$update.EnableDeltaDownload + Office365ManagementType = `$update.Office365ManagementType + EnableThirdPartyUpdates = `$update.EnableThirdPartyUpdates + DependsOn = `$cmClientSettingsDependsOn + } + } + } + } + } + } + + if (`$CMClientSettingsPower) + { + foreach (`$powerSetting in `$CMClientSettingsPower) + { + if (`$powerSetting.NetworkWakeupOption -ne 'Enabled' -and `$powerSetting.EnableWakeupProxy -eq `$false) + { + CMClientSettingsPower `$powerSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$powerSetting.ClientSettingName + Enable = `$powerSetting.Enable + AllowUserToOptOutFromPowerPlan = `$powerSetting.AllowUserToOptOutFromPowerPlan + NetworkWakeupOption = `$powerSetting.NetworkWakeupOption + EnableWakeupProxy = `$powerSetting.EnableWakeupProxy + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$powerSetting.WakeupProxyDirectAccessPrefix) + { + CMClientSettingsPower `$powerSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$powerSetting.ClientSettingName + Enable = `$powerSetting.Enable + AllowUserToOptOutFromPowerPlan = `$powerSetting.AllowUserToOptOutFromPowerPlan + NetworkWakeupOption = `$powerSetting.NetworkWakeupOption + EnableWakeupProxy = `$powerSetting.EnableWakeupProxy + FirewallExceptionForWakeupProxy = `$powerSetting.FirewallExceptionForWakeupProxy + WakeupProxyDirectAccessPrefix = `$powerSetting.WakeupProxyDirectAccessPrefix + WakeupProxyPort = `$powerSetting.WakeupProxyPort + WakeOnLanPort = `$powerSetting.WakeOnLanPort + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsPower `$powerSetting.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$powerSetting.ClientSettingName + Enable = `$powerSetting.Enable + AllowUserToOptOutFromPowerPlan = `$powerSetting.AllowUserToOptOutFromPowerPlan + NetworkWakeupOption = `$powerSetting.NetworkWakeupOption + EnableWakeupProxy = `$powerSetting.EnableWakeupProxy + FirewallExceptionForWakeupProxy = `$powerSetting.FirewallExceptionForWakeupProxy + WakeupProxyPort = `$powerSetting.WakeupProxyPort + WakeOnLanPort = `$powerSetting.WakeOnLanPort + DependsOn = `$cmClientSettingsDependsOn + } + } + } + } + + if (`$CMClientSettingsRemoteTools) + { + foreach (`$remoteTool in `$CMClientSettingsRemoteTools) + { + if (`$remoteTool.ManageRemoteDesktopSetting -eq `$true) + { + if (`$remoteTool.PermittedViewer) + { + if (`$remoteTool.FirewallExceptionProfile) + { + CMClientSettingsRemoteTools `$remoteTool.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$remoteTool.ClientSettingName + FirewallExceptionProfile = `$remoteTool.FirewallExceptionProfile + AllowClientChange = `$remoteTool.AllowClientChange + AllowUnattendedComputer = `$remoteTool.AllowUnattendedComputer + PromptUserForPermission = `$remoteTool.PromptUserForPermission + PromptUserForClipboardPermission = `$remoteTool.PromptUserForClipboardPermission + GrantPermissionToLocalAdministrator = `$remoteTool.GrantPermissionToLocalAdministrator + AccessLevel = `$remoteTool.AccessLevel + PermittedViewer = `$remoteTool.PermittedViewer + ShowNotificationIconOnTaskbar = `$remoteTool.ShowNotificationIconOnTaskbar + ShowSessionConnectionBar = `$remoteTool.ShowSessionConnectionBar + AudibleSignal = `$remoteTool.AudibleSignal + ManageUnsolicitedRemoteAssistance = `$remoteTool.ManageUnsolicitedRemoteAssistance + ManageSolicitedRemoteAssistance = `$remoteTool.ManageSolicitedRemoteAssistance + RemoteAssistanceAccessLevel = `$remoteTool.RemoteAssistanceAccessLevel + ManageRemoteDesktopSetting = `$remoteTool.ManageRemoteDesktopSetting + AllowPermittedViewer = `$remoteTool.AllowPermittedViewer + RequireAuthentication = `$remoteTool.RequireAuthentication + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsRemoteTools `$remoteTool.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$remoteTool.ClientSettingName + AllowClientChange = `$remoteTool.AllowClientChange + AllowUnattendedComputer = `$remoteTool.AllowUnattendedComputer + PromptUserForPermission = `$remoteTool.PromptUserForPermission + PromptUserForClipboardPermission = `$remoteTool.PromptUserForClipboardPermission + GrantPermissionToLocalAdministrator = `$remoteTool.GrantPermissionToLocalAdministrator + AccessLevel = `$remoteTool.AccessLevel + PermittedViewer = `$remoteTool.PermittedViewer + ShowNotificationIconOnTaskbar = `$remoteTool.ShowNotificationIconOnTaskbar + ShowSessionConnectionBar = `$remoteTool.ShowSessionConnectionBar + AudibleSignal = `$remoteTool.AudibleSignal + ManageUnsolicitedRemoteAssistance = `$remoteTool.ManageUnsolicitedRemoteAssistance + ManageSolicitedRemoteAssistance = `$remoteTool.ManageSolicitedRemoteAssistance + RemoteAssistanceAccessLevel = `$remoteTool.RemoteAssistanceAccessLevel + ManageRemoteDesktopSetting = `$remoteTool.ManageRemoteDesktopSetting + AllowPermittedViewer = `$remoteTool.AllowPermittedViewer + RequireAuthentication = `$remoteTool.RequireAuthentication + DependsOn = `$cmClientSettingsDependsOn + } + } + } + else + { + if (`$remoteTool.FirewallExceptionProfile) + { + CMClientSettingsRemoteTools `$remoteTool.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$remoteTool.ClientSettingName + FirewallExceptionProfile = `$remoteTool.FirewallExceptionProfile + AllowClientChange = `$remoteTool.AllowClientChange + AllowUnattendedComputer = `$remoteTool.AllowUnattendedComputer + PromptUserForPermission = `$remoteTool.PromptUserForPermission + PromptUserForClipboardPermission = `$remoteTool.PromptUserForClipboardPermission + GrantPermissionToLocalAdministrator = `$remoteTool.GrantPermissionToLocalAdministrator + AccessLevel = `$remoteTool.AccessLevel + PermittedViewer = `$remoteTool.PermittedViewer + ShowNotificationIconOnTaskbar = `$remoteTool.ShowNotificationIconOnTaskbar + ShowSessionConnectionBar = `$remoteTool.ShowSessionConnectionBar + AudibleSignal = `$remoteTool.AudibleSignal + ManageUnsolicitedRemoteAssistance = `$remoteTool.ManageUnsolicitedRemoteAssistance + ManageSolicitedRemoteAssistance = `$remoteTool.ManageSolicitedRemoteAssistance + RemoteAssistanceAccessLevel = `$remoteTool.RemoteAssistanceAccessLevel + ManageRemoteDesktopSetting = `$remoteTool.ManageRemoteDesktopSetting + AllowPermittedViewer = `$remoteTool.AllowPermittedViewer + RequireAuthentication = `$remoteTool.RequireAuthentication + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsRemoteTools `$remoteTool.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$remoteTool.ClientSettingName + AllowClientChange = `$remoteTool.AllowClientChange + AllowUnattendedComputer = `$remoteTool.AllowUnattendedComputer + PromptUserForPermission = `$remoteTool.PromptUserForPermission + PromptUserForClipboardPermission = `$remoteTool.PromptUserForClipboardPermission + GrantPermissionToLocalAdministrator = `$remoteTool.GrantPermissionToLocalAdministrator + AccessLevel = `$remoteTool.AccessLevel + PermittedViewer = `$remoteTool.PermittedViewer + ShowNotificationIconOnTaskbar = `$remoteTool.ShowNotificationIconOnTaskbar + ShowSessionConnectionBar = `$remoteTool.ShowSessionConnectionBar + AudibleSignal = `$remoteTool.AudibleSignal + ManageUnsolicitedRemoteAssistance = `$remoteTool.ManageUnsolicitedRemoteAssistance + ManageSolicitedRemoteAssistance = `$remoteTool.ManageSolicitedRemoteAssistance + RemoteAssistanceAccessLevel = `$remoteTool.RemoteAssistanceAccessLevel + ManageRemoteDesktopSetting = `$remoteTool.ManageRemoteDesktopSetting + AllowPermittedViewer = `$remoteTool.AllowPermittedViewer + RequireAuthentication = `$remoteTool.RequireAuthentication + DependsOn = `$cmClientSettingsDependsOn + } + } + } + } + else + { + if (`$remoteTool.PermittedViewer) + { + if (`$remoteTool.FirewallExceptionProfile) + { + CMClientSettingsRemoteTools `$remoteTool.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$remoteTool.ClientSettingName + FirewallExceptionProfile = `$remoteTool.FirewallExceptionProfile + AllowClientChange = `$remoteTool.AllowClientChange + AllowUnattendedComputer = `$remoteTool.AllowUnattendedComputer + PromptUserForPermission = `$remoteTool.PromptUserForPermission + PromptUserForClipboardPermission = `$remoteTool.PromptUserForClipboardPermission + GrantPermissionToLocalAdministrator = `$remoteTool.GrantPermissionToLocalAdministrator + AccessLevel = `$remoteTool.AccessLevel + ShowNotificationIconOnTaskbar = `$remoteTool.ShowNotificationIconOnTaskbar + ShowSessionConnectionBar = `$remoteTool.ShowSessionConnectionBar + AudibleSignal = `$remoteTool.AudibleSignal + ManageUnsolicitedRemoteAssistance = `$remoteTool.ManageUnsolicitedRemoteAssistance + ManageSolicitedRemoteAssistance = `$remoteTool.ManageSolicitedRemoteAssistance + RemoteAssistanceAccessLevel = `$remoteTool.RemoteAssistanceAccessLevel + ManageRemoteDesktopSetting = `$remoteTool.ManageRemoteDesktopSetting + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsRemoteTools `$remoteTool.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$remoteTool.ClientSettingName + AllowClientChange = `$remoteTool.AllowClientChange + AllowUnattendedComputer = `$remoteTool.AllowUnattendedComputer + PromptUserForPermission = `$remoteTool.PromptUserForPermission + PromptUserForClipboardPermission = `$remoteTool.PromptUserForClipboardPermission + GrantPermissionToLocalAdministrator = `$remoteTool.GrantPermissionToLocalAdministrator + AccessLevel = `$remoteTool.AccessLevel + ShowNotificationIconOnTaskbar = `$remoteTool.ShowNotificationIconOnTaskbar + ShowSessionConnectionBar = `$remoteTool.ShowSessionConnectionBar + AudibleSignal = `$remoteTool.AudibleSignal + ManageUnsolicitedRemoteAssistance = `$remoteTool.ManageUnsolicitedRemoteAssistance + ManageSolicitedRemoteAssistance = `$remoteTool.ManageSolicitedRemoteAssistance + RemoteAssistanceAccessLevel = `$remoteTool.RemoteAssistanceAccessLevel + ManageRemoteDesktopSetting = `$remoteTool.ManageRemoteDesktopSetting + DependsOn = `$cmClientSettingsDependsOn + } + } + } + else + { + if (`$remoteTool.FirewallExceptionProfile) + { + CMClientSettingsRemoteTools `$remoteTool.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$remoteTool.ClientSettingName + FirewallExceptionProfile = `$remoteTool.FirewallExceptionProfile + AllowClientChange = `$remoteTool.AllowClientChange + AllowUnattendedComputer = `$remoteTool.AllowUnattendedComputer + PromptUserForPermission = `$remoteTool.PromptUserForPermission + PromptUserForClipboardPermission = `$remoteTool.PromptUserForClipboardPermission + GrantPermissionToLocalAdministrator = `$remoteTool.GrantPermissionToLocalAdministrator + AccessLevel = `$remoteTool.AccessLevel + ShowNotificationIconOnTaskbar = `$remoteTool.ShowNotificationIconOnTaskbar + ShowSessionConnectionBar = `$remoteTool.ShowSessionConnectionBar + AudibleSignal = `$remoteTool.AudibleSignal + ManageUnsolicitedRemoteAssistance = `$remoteTool.ManageUnsolicitedRemoteAssistance + ManageSolicitedRemoteAssistance = `$remoteTool.ManageSolicitedRemoteAssistance + RemoteAssistanceAccessLevel = `$remoteTool.RemoteAssistanceAccessLevel + ManageRemoteDesktopSetting = `$remoteTool.ManageRemoteDesktopSetting + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsRemoteTools `$remoteTool.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$remoteTool.ClientSettingName + AllowClientChange = `$remoteTool.AllowClientChange + AllowUnattendedComputer = `$remoteTool.AllowUnattendedComputer + PromptUserForPermission = `$remoteTool.PromptUserForPermission + PromptUserForClipboardPermission = `$remoteTool.PromptUserForClipboardPermission + GrantPermissionToLocalAdministrator = `$remoteTool.GrantPermissionToLocalAdministrator + AccessLevel = `$remoteTool.AccessLevel + ShowNotificationIconOnTaskbar = `$remoteTool.ShowNotificationIconOnTaskbar + ShowSessionConnectionBar = `$remoteTool.ShowSessionConnectionBar + AudibleSignal = `$remoteTool.AudibleSignal + ManageUnsolicitedRemoteAssistance = `$remoteTool.ManageUnsolicitedRemoteAssistance + ManageSolicitedRemoteAssistance = `$remoteTool.ManageSolicitedRemoteAssistance + RemoteAssistanceAccessLevel = `$remoteTool.RemoteAssistanceAccessLevel + ManageRemoteDesktopSetting = `$remoteTool.ManageRemoteDesktopSetting + DependsOn = `$cmClientSettingsDependsOn + } + } + } + } + } + } + + if (`$CMClientSettingsSoftwareCenter) + { + foreach (`$softwareCenter in `$CMClientSettingsSoftwareCenter) + { + if (`$softwareCenter.EnableCustomize -eq `$false) + { + CMClientSettingsSoftwareCenter `$softwareCenter.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softwareCenter.ClientSettingName + EnableCustomize = `$softwareCenter.EnableCustomize + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif ([string]::IsNullOrEmpty(`$softwareCenter.CompanyName) -and + [string]::IsNullOrEmpty(`$softwareCenter.ColorScheme)) + { + CMClientSettingsSoftwareCenter `$softwareCenter.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softwareCenter.ClientSettingName + EnableCustomize = `$softwareCenter.EnableCustomize + HideApplicationCatalogLink = `$softwareCenter.HideApplicationCatalogLink + HideInstalledApplication = `$softwareCenter.HideInstalledApplication + HideUnapprovedApplication = `$softwareCenter.HideUnapprovedApplication + EnableApplicationsTab = `$softwareCenter.EnableApplicationsTab + EnableUpdatesTab = `$softwareCenter.EnableUpdatesTab + EnableOperatingSystemsTab = `$softwareCenter.EnableOperatingSystemsTab + EnableStatusTab = `$softwareCenter.EnableStatusTab + EnableComplianceTab = `$softwareCenter.EnableComplianceTab + EnableOptionsTab = `$softwareCenter.EnableOptionsTab + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif ([string]::IsNullOrEmpty(`$softwareCenter.CompanyName)) + { + CMClientSettingsSoftwareCenter `$softwareCenter.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softwareCenter.ClientSettingName + EnableCustomize = `$softwareCenter.EnableCustomize + ColorScheme = `$softwareCenter.ColorScheme + HideApplicationCatalogLink = `$softwareCenter.HideApplicationCatalogLink + HideInstalledApplication = `$softwareCenter.HideInstalledApplication + HideUnapprovedApplication = `$softwareCenter.HideUnapprovedApplication + EnableApplicationsTab = `$softwareCenter.EnableApplicationsTab + EnableUpdatesTab = `$softwareCenter.EnableUpdatesTab + EnableOperatingSystemsTab = `$softwareCenter.EnableOperatingSystemsTab + EnableStatusTab = `$softwareCenter.EnableStatusTab + EnableComplianceTab = `$softwareCenter.EnableComplianceTab + EnableOptionsTab = `$softwareCenter.EnableOptionsTab + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif ([string]::IsNullOrEmpty(`$softwareCenter.ColorScheme)) + { + CMClientSettingsSoftwareCenter `$softwareCenter.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softwareCenter.ClientSettingName + EnableCustomize = `$softwareCenter.EnableCustomize + CompanyName = `$softwareCenter.CompanyName + HideApplicationCatalogLink = `$softwareCenter.HideApplicationCatalogLink + HideInstalledApplication = `$softwareCenter.HideInstalledApplication + HideUnapprovedApplication = `$softwareCenter.HideUnapprovedApplication + EnableApplicationsTab = `$softwareCenter.EnableApplicationsTab + EnableUpdatesTab = `$softwareCenter.EnableUpdatesTab + EnableOperatingSystemsTab = `$softwareCenter.EnableOperatingSystemsTab + EnableStatusTab = `$softwareCenter.EnableStatusTab + EnableComplianceTab = `$softwareCenter.EnableComplianceTab + EnableOptionsTab = `$softwareCenter.EnableOptionsTab + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsSoftwareCenter `$softwareCenter.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$softwareCenter.ClientSettingName + EnableCustomize = `$softwareCenter.EnableCustomize + CompanyName = `$softwareCenter.CompanyName + ColorScheme = `$softwareCenter.ColorScheme + HideApplicationCatalogLink = `$softwareCenter.HideApplicationCatalogLink + HideInstalledApplication = `$softwareCenter.HideInstalledApplication + HideUnapprovedApplication = `$softwareCenter.HideUnapprovedApplication + EnableApplicationsTab = `$softwareCenter.EnableApplicationsTab + EnableUpdatesTab = `$softwareCenter.EnableUpdatesTab + EnableOperatingSystemsTab = `$softwareCenter.EnableOperatingSystemsTab + EnableStatusTab = `$softwareCenter.EnableStatusTab + EnableComplianceTab = `$softwareCenter.EnableComplianceTab + EnableOptionsTab = `$softwareCenter.EnableOptionsTab + DependsOn = `$cmClientSettingsDependsOn + } + } + } + } + + if (`$CMClientSettingsStateMessaging) + { + foreach (`$stateMessage in `$CMClientSettingsStateMessaging) + { + CMClientSettingsStateMessaging `$stateMessage.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$stateMessage.ClientSettingName + ReportingCycleMins = `$stateMessage.ReportingCycleMins + DependsOn = `$cmClientSettingsDependsOn + } + } + } + + if (`$CMClientSettingsUserDeviceAffinity) + { + foreach (`$udAffinity in `$CMClientSettingsUserDeviceAffinity) + { + if (`$udAffinity.LogOnThresholdMins -and `$udAffinity.AllowUserAffinity) + { + CMClientSettingsUserDeviceAffinity `$udAffinity.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$udAffinity.ClientSettingName + LogOnThresholdMins = `$udAffinity.LogOnThresholdMins + UsageThresholdDays = `$udAffinity.UsageThresholdDays + AutoApproveAffinity = `$udAffinity.AutoApproveAffinity + AllowUserAffinity = `$udAffinity.AllowUserAffinity + DependsOn = `$cmClientSettingsDependsOn + } + } + elseif (`$udAffinity.LogOnThresholdMins) + { + CMClientSettingsUserDeviceAffinity `$udAffinity.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$udAffinity.ClientSettingName + LogOnThresholdMins = `$udAffinity.LogOnThresholdMins + UsageThresholdDays = `$udAffinity.UsageThresholdDays + AutoApproveAffinity = `$udAffinity.AutoApproveAffinity + DependsOn = `$cmClientSettingsDependsOn + } + } + else + { + CMClientSettingsUserDeviceAffinity `$udAffinity.ClientSettingName + { + SiteCode = `$SiteCode + ClientSettingName = `$udAffinity.ClientSettingName + AllowUserAffinity = `$udAffinity.AllowUserAffinity + DependsOn = `$cmClientSettingsDependsOn + } + } + } + } + } +} + +`$cd = @{ + AllNodes = @( + @{ + NodeName = 'localhost' + PSDscAllowPlainTextPassword = `$true + PSDscAllowDomainUser = `$true + } + ) +} + +ConfigureSccm -OutputPath $MofOutPutPath -ConfigurationData `$cd -DataFile $DataFile +" +} + +<# + .SYNOPSIS + This will create the data file and\or configuration. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .PARAMETER Include + Specifies which resources will be invoked, default setting: All. + + .PARAMETER Exclude + Specifies which resources will be excluded from being evaluated. + + .PARAMETER DataFile + Specifies where the data file will be saved. + + .PARAMETER ConfigOutputPath + Specifies where the configuration file will be saved. + + .PARAMETER MofOutPutPath + Specifies where the mof file will be saved when running the configuration. +#> +function Set-ConfigMgrCBDscReverse +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter()] + [ValidateSet('All','Accounts','AdministrativeUser','AssetIntelligencePoint','BoundaryGroups', + 'ClientPush','ClientStatusSettings','CollectionEvaluationComponent','Collections', + 'DistributionGroups','DistributionPoint','DistributionPointGroupMembers', + 'EmailNotificationComponent','FallbackPoints','ForestDiscovery','HeartbeatDiscovery', + 'MaintenanceWindow','ManagementPoint','NetworkDiscovery','PullDistributionPoint', + 'PxeDistributionPoint','ReportingServicesPoint','SecurityScopes','ServiceConnection', + 'SiteMaintenance','SiteSystemServer','SoftwareDistributionComponent','SoftwareupdatePoint', + 'StatusReportingComponent','SystemDiscovery','UserDiscovery','ConfigFileOnly','GroupDiscovery', + 'SoftwareUpdatePointComponent','ClientSettings','ClientSettingsBits', + 'ClientSettingsClientCache','ClientSettingsClientPolicy','ClientSettingsCloudService', + 'ClientSettingsCompliance','ClientSettingsComputerAgent','ClientSettingsDelivery', + 'ClientSettingsHardware','ClientSettingsMetered','ClientSettingsPower', + 'ClientSettingsRemoteTools','ClientSettingsSoftwareCenter','ClientSettingsSoftwareDeployment', + 'ClientSettingsSoftwareInventory','ClientSettingsSoftwareMetering','ClientSettingsSoftwareUpdate', + 'ClientSettingsStateMessaging','ClientSettingsUserDeviceAffinity')] + [String[]] + $Include = 'All', + + [Parameter()] + [ValidateSet('Accounts','AdministrativeUser','AssetIntelligencePoint','BoundaryGroups', + 'ClientPush','ClientStatusSettings','CollectionEvaluationComponent','Collections', + 'DistributionGroups','DistributionPoint','DistributionPointGroupMembers', + 'EmailNotificationComponent','FallbackPoints','ForestDiscovery','HeartbeatDiscovery', + 'MaintenanceWindow','ManagementPoint','NetworkDiscovery','PullDistributionPoint', + 'PxeDistributionPoint','ReportingServicesPoint','SecurityScopes','ServiceConnection', + 'SiteMaintenance','SiteSystemServer','SoftwareDistributionComponent','SoftwareupdatePoint', + 'StatusReportingComponent','SystemDiscovery','UserDiscovery','GroupDiscovery', + 'SoftwareUpdatePointComponent','ClientSettings','ClientSettingsBits', + 'ClientSettingsClientCache','ClientSettingsClientPolicy','ClientSettingsCloudService', + 'ClientSettingsCompliance','ClientSettingsComputerAgent','ClientSettingsDelivery', + 'ClientSettingsHardware','ClientSettingsMetered','ClientSettingsPower', + 'ClientSettingsRemoteTools','ClientSettingsSoftwareCenter','ClientSettingsSoftwareDeployment', + 'ClientSettingsSoftwareInventory','ClientSettingsSoftwareMetering','ClientSettingsSoftwareUpdate', + 'ClientSettingsStateMessaging','ClientSettingsUserDeviceAffinity')] + [String[]] + $Exclude, + + [Parameter()] + [ValidateScript( + { + if ($_.Substring($_.Length -5,5) -eq '.psd1') + { + $true + } + else + { + throw $script:localizedData.DataFileEr + } + } + )] + [String] + $DataFile, + + [Parameter()] + [ValidateScript( + { + if ($_.Substring($_.Length -4,4) -eq '.ps1') + { + $true + } + else + { + throw $script:localizedData.ConfigOutputPathEr + } + } + )] + [String] + $ConfigOutputPath, + + [Parameter()] + [String] + $MofOutPutPath + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + if (($ConfigOutputPath -or $MofOutPutPath) -and ([string]::IsNullOrEmpty($ConfigOutputPath) -or + [string]::IsNullOrEmpty($MofOutPutPath) -or [string]::IsNullOrEmpty($DataFile))) + { + throw $script:localizedData.MissingParams + } + + Import-Module -Name 'ConfigMgrCBDsc' + $resources = Get-DscResource -Module 'ConfigMgrCBDsc' + + if ($Include -ne 'All' -and -not [string]::IsNullOrEmpty($Exclude)) + { + Write-Warning -Message $script:localizedData.ExcludeMsg + } + + $fileOut = "@{`r`nSiteCode = '$SiteCode'`r`n" + + if (($Include -contains 'All' -and $Exclude -notcontains 'Accounts') -or ($Include -contains 'Accounts')) + { + $resourceName = 'CMAccounts' + $accounts = Get-CMAccount -SiteCode $SiteCode + + if ($accounts) + { + $wCMAccounts = "$ResourceName = @(`r`n" + } + + foreach ($account in $accounts) + { + Write-Verbose -Message ($script:localizedData.CMAccounts -f $account.UserName) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + ExcludeList = @('SiteCode','AccountPassword') + Count = 7 + Indent = 2 + StringValue = $account.UserName + MultiEntry = $true + Resources = $resources + } + + $testThing = Set-OutFile @params + $wCMAccounts += "$testThing" + } + + if ($wCMAccounts) + { + $wCMAccounts += ")" + $fileOut += "$wCMAccounts`r`n" + } + } + + if (($Include -eq 'All' -and $Exclude -notcontains 'AdministrativeUser') -or ($Include -eq 'AdministrativeUser')) + { $resourceName = 'CMAdministrativeUser' $susers = (Get-CMAdministrativeUser).LogonName if ($susers) { - $wAdministrativeUser = "$resourceName = @(`r`n" + $wAdministrativeUser = "$resourceName = @(`r`n" + } + + foreach ($user in $susers) + { + Write-Verbose -Message ($script:localizedData.AdminUser -f $user) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + StringValue = $user + MultiEntry = $true + Resources = $resources + } + + $testThing = Set-OutFile @params + $wAdministrativeUser += "$testThing" + } + + if ($wAdministrativeUser) + { + $wAdministrativeUser += ")" + $fileOut += "$wAdministrativeUser`r`n" + } + } + + if (($Include -eq 'All' -and $Exclude -notcontains 'AssetIntelligencePoint') -or ($Include -contains 'AssetIntelligencePoint')) + { + $resourceName = 'CMAssetIntelligencePoint' + Write-Verbose -Message ($script:localizedData.SingleOutput -f $resourceName) -Verbose + + $assetIntel = Get-CMAssetIntelligenceSynchronizationPoint -SiteCode $SiteCode + + if ($assetIntel) + { + $wAsset = "$resourceName = @{`r`n" + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + StringValue = 'Yes' + Indent = 1 + MultiEntry = $false + Resources = $resources + } + + $testThing = Set-OutFile @params + $wAsset += "$testThing" + $fileOut += "$wAsset`r`n" + } + } + + if (($Include -eq 'All' -and $Exclude -notcontains 'BoundaryGroups') -or ($Include -contains 'BoundaryGroups')) + { + $resourceName = 'CMBoundaryGroups' + $boundaryGroups = Get-CMBoundaryGroup + + foreach ($boundaryGroup in $boundaryGroups) + { + if ([string]::IsNullOrEmpty($wBG)) + { + $wBG = "$resourceName = @(`r`n" + } + + Write-Verbose -Message ($script:localizedData.BoundaryGroup -f $boundaryGroup.Name) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + ExcludeList = @('SiteCode','Boundaries','BoundaryAction','SiteSystems') + Indent = 2 + StringValue = $boundaryGroup.Name + MultiEntry = $true + Resources = $resources + } + + $testThing = Set-OutFile @params + $wBG += "$testThing" + } + + if ($wBG) + { + $wBG += ")" + $fileOut += "$wBG`r`n" + } + } + + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientPush') -or ($Include -contains 'ClientPush')) + { + $resourceName = 'CMClientPushSettings' + Write-Verbose -Message ($script:localizedData.SingleOutput -f $resourceName) -Verbose + $wPush = "$resourceName = @{`r`n" + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 1 + MultiEntry = $false + Resources = $resources + } + + $testThing = Set-OutFile @params + $wPush += "$testThing" + $fileOut += "$wPush`r`n" + } + + if (($Include -eq 'All') -or (@($Include) -like 'ClientSettings*').Count -gt 0) + { + $clientSettings = Get-CMClientSetting + + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettings') -or + ($Include -contains 'ClientSettings')) + { + foreach ($item in $clientSettings) + { + if ($item.Type -ne 0) + { + if ([string]::IsNullOrEmpty($wCSClient)) + { + $resourceName = 'CMClientSettings' + $wCSClient = "$resourceName = @(`r`n" + } + + Write-Verbose -Message ($script:localizedData.ClientSettings -f $item.Name) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + Resources = $resources + StringValue = $item.Name + } + + $testThing = Set-OutFile @params + $wCSClient += "$testThing" + } + } + + if ($wCSClient) + { + $wCSClient += ")" + $fileOut += "$wCSClient`r`n" + } + } + + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettingsBits') -or + ($Include -contains 'ClientSettingsBits')) + { + foreach ($item in $clientSettings) + { + if (Get-CMClientSetting -Setting BackgroundIntelligentTransfer -Name $item.Name) + { + if ([string]::IsNullOrEmpty($wCSBits)) + { + $resourceName = 'CMClientSettingsBits' + $wCSBits = "$resourceName = @(`r`n" + } + + Write-Verbose -Message ($script:localizedData.ClientBits -f $item.Name) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + Resources = $resources + StringValue = $item.Name + } + + $testThing = Set-OutFile @params + $wCSBits += "$testThing" + } + } + + if ($wCSBits) + { + $wCSBits += ")" + $fileOut += "$wCSBits`r`n" + } + } + + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettingsClientCache') -or + ($Include -contains 'ClientSettingsClientCache')) + { + foreach ($item in $clientSettings) + { + if (Get-CMClientSetting -Setting ClientCache -Name $item.Name) + { + if ([string]::IsNullOrEmpty($wCSClientCache)) + { + $resourceName = 'CMClientSettingsClientCache' + $wCSClientCache = "$resourceName = @(`r`n" + } + + Write-Verbose -Message ($script:localizedData.ClientClientCache -f $item.Name) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + Resources = $resources + StringValue = $item.Name + } + + $testThing = Set-OutFile @params + $wCSClientCache += "$testThing" + } + } + + if ($wCSClientCache) + { + $wCSClientCache += ")" + $fileOut += "$wCSClientCache`r`n" + } + } + + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettingsClientPolicy') -or + ($Include -contains 'ClientSettingsClientPolicy')) + { + foreach ($item in $clientSettings) + { + if (Get-CMClientSetting -Setting ClientPolicy -Name $item.Name) + { + if ([string]::IsNullOrEmpty($wCSClientPolicy)) + { + $resourceName = 'CMClientSettingsClientPolicy' + $wCSClientPolicy = "$resourceName = @(`r`n" + } + + Write-Verbose -Message ($script:localizedData.ClientClientPolicy -f $item.Name) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + Resources = $resources + StringValue = $item.Name + } + + $testThing = Set-OutFile @params + $wCSClientPolicy += "$testThing" + } + } + + if ($wCSClientPolicy) + { + $wCSClientPolicy += ")" + $fileOut += "$wCSClientPolicy`r`n" + } + } + + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettingsCloudService') -or + ($Include -contains 'ClientSettingsCloudService')) + { + foreach ($item in $clientSettings) + { + if (Get-CMClientSetting -Setting Cloud -Name $item.Name) + { + if ([string]::IsNullOrEmpty($wCSClientCloud)) + { + $resourceName = 'CMClientSettingsCloudService' + $wCSClientCloud = "$resourceName = @(`r`n" + } + + Write-Verbose -Message ($script:localizedData.ClientCloud -f $item.Name) -Verbose + + if ($item.Type -eq 2) + { + $eList = @('SiteCode','AutoAzureADJoin','AllowCloudManagementGateway') + } + else + { + $eList = @('SiteCode') + } + + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + ExcludeList = $eList + Resources = $resources + StringValue = $item.Name + } + + $testThing = Set-OutFile @params + $wCSClientCloud += "$testThing" + } + } + + if ($wCSClientCloud) + { + $wCSClientCloud += ")" + $fileOut += "$wCSClientCloud`r`n" + } + } + + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettingsCompliance') -or + ($Include -contains 'ClientSettingsCompliance')) + { + foreach ($item in $clientSettings) + { + if (Get-CMClientSetting -Setting ComplianceSettings -Name $item.Name) + { + if ([string]::IsNullOrEmpty($wCSCompliance)) + { + $resourceName = 'CMClientSettingsCompliance' + $wCSCompliance = "$resourceName = @(`r`n" + } + + Write-Verbose -Message ($script:localizedData.ClientCompliance -f $item.Name) -Verbose + + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + Resources = $resources + StringValue = $item.Name + } + + $testThing = Set-OutFile @params + $wCSCompliance += "$testThing" + } + } + + if ($wCSCompliance) + { + $wCSCompliance += ")" + $fileOut += "$wCSCompliance`r`n" + } + } + + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettingsComputerAgent') -or + ($Include -contains 'ClientSettingsComputerAgent')) + { + foreach ($item in $clientSettings) + { + if (Get-CMClientSetting -Setting ComputerAgent -Name $item.Name) + { + if ([string]::IsNullOrEmpty($wCSCompAgent)) + { + $resourceName = 'CMClientSettingsComputerAgent' + $wCSCompAgent = "$resourceName = @(`r`n" + } + + Write-Verbose -Message ($script:localizedData.ClientCompAgent -f $item.Name) -Verbose + + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + Resources = $resources + StringValue = $item.Name + } + + $testThing = Set-OutFile @params + $wCSCompAgent += "$testThing" + } + } + + if ($wCSCompAgent) + { + $wCSCompAgent += ")" + $fileOut += "$wCSCompAgent`r`n" + } + } + + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettingsDelivery') -or + ($Include -contains 'ClientSettingsDelivery')) + { + foreach ($item in $clientSettings) + { + if (Get-CMClientSetting -Setting DeliveryOptimization -Name $item.Name) + { + if ([string]::IsNullOrEmpty($wCSDelivery)) + { + $resourceName = 'CMClientSettingsDelivery' + $wCSDelivery = "$resourceName = @(`r`n" + } + + Write-Verbose -Message ($script:localizedData.ClientDelivery -f $item.Name) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + Resources = $resources + StringValue = $item.Name + } + + $testThing = Set-OutFile @params + $wCSDelivery += "$testThing" + } + } + + if ($wCSDelivery) + { + $wCSDelivery += ")" + $fileOut += "$wCSDelivery`r`n" + } } - foreach ($user in $susers) + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettingsHardware') -or + ($Include -contains 'ClientSettingsHardware')) { - Write-Verbose -Message ($script:localizedData.AdminUser -f $user) -Verbose - $params = @{ - ResourceName = $resourceName - SiteCode = $SiteCode - Indent = 2 - StringValue = $user - MultiEntry = $true - Resources = $resources + foreach ($item in $clientSettings) + { + if (Get-CMClientSetting -Setting HardwareInventory -Name $item.Name) + { + if ([string]::IsNullOrEmpty($wCSHardware)) + { + $resourceName = 'CMClientSettingsHardware' + $wCSHardware = "$resourceName = @(`r`n" + } + + if ($item.Type -eq 0) + { + $exList = @('SiteCode') + } + else + { + $exList = @('SiteCode','MaxThirdPartyMifSize','CollectMifFile') + } + + Write-Verbose -Message ($script:localizedData.ClientHardware -f $item.Name) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + Resources = $resources + ExcludeList = $exList + StringValue = $item.Name + } + + $testThing = Set-OutFile @params + $wCSHardware += "$testThing" + } } - $testThing = Set-OutFile @params - $wAdministrativeUser += "$testThing" + if ($wCSHardware) + { + $wCSHardware += ")" + $fileOut += "$wCSHardware`r`n" + } } - if ($wAdministrativeUser) + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettingsMetered') -or + ($Include -contains 'ClientSettingsMetered')) { - $wAdministrativeUser += ")" - $fileOut += "$wAdministrativeUser`r`n" + foreach ($item in $clientSettings) + { + if (Get-CMClientSetting -Setting MeteredNetwork -Name $item.Name) + { + if ([string]::IsNullOrEmpty($wCSMetered)) + { + $resourceName = 'CMClientSettingsMetered' + $wCSMetered = "$resourceName = @(`r`n" + } + + Write-Verbose -Message ($script:localizedData.ClientMetered -f $item.Name) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + Resources = $resources + StringValue = $item.Name + } + + $testThing = Set-OutFile @params + $wCSMetered += "$testThing" + } + } + + if ($wCSMetered) + { + $wCSMetered += ")" + $fileOut += "$wCSMetered`r`n" + } } - } - if (($Include -eq 'All' -and $Exclude -notcontains 'AssetIntelligencePoint') -or ($Include -contains 'AssetIntelligencePoint')) - { - $resourceName = 'CMAssetIntelligencePoint' - Write-Verbose -Message ($script:localizedData.SingleOutput -f $resourceName) -Verbose + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettingsPower') -or + ($Include -contains 'ClientSettingsPower')) + { + foreach ($item in $clientSettings) + { + if (Get-CMClientSetting -Setting PowerManagement -Name $item.Name) + { + if ([string]::IsNullOrEmpty($wCSPower)) + { + $resourceName = 'CMClientSettingsPower' + $wCSPower = "$resourceName = @(`r`n" + } - $assetIntel = Get-CMAssetIntelligenceSynchronizationPoint -SiteCode $SiteCode + Write-Verbose -Message ($script:localizedData.ClientPower -f $item.Name) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + Resources = $resources + StringValue = $item.Name + } - if ($assetIntel) + $testThing = Set-OutFile @params + $wCSPower += "$testThing" + } + } + + if ($wCSPower) + { + $wCSPower += ")" + $fileOut += "$wCSPower`r`n" + } + } + + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettingsRemoteTools') -or + ($Include -contains 'ClientSettingsRemoteTools')) { - $wAsset = "$resourceName = @{`r`n" - $params = @{ - ResourceName = $resourceName - SiteCode = $SiteCode - StringValue = 'Yes' - Indent = 1 - MultiEntry = $false - Resources = $resources + foreach ($item in $clientSettings) + { + $clientRemoteTools = Get-CMClientSetting -Setting RemoteTools -Name $item.Name + if ($clientRemoteTools -and $clientRemoteTools.FirewallExceptionProfiles -ge 1) + { + if ([string]::IsNullOrEmpty($wCSRemoteTools)) + { + $resourceName = 'CMClientSettingsRemoteTools' + $wCSRemoteTools = "$resourceName = @(`r`n" + } + + Write-Verbose -Message ($script:localizedData.ClientRemoteTools -f $item.Name) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + Resources = $resources + StringValue = $item.Name + } + + $testThing = Set-OutFile @params + $wCSRemoteTools += "$testThing" + } } - $testThing = Set-OutFile @params - $wAsset += "$testThing" - $fileOut += "$wAsset`r`n" + if ($wCSRemoteTools) + { + $wCSRemoteTools += ")" + $fileOut += "$wCSRemoteTools`r`n" + } } - } - if (($Include -eq 'All' -and $Exclude -notcontains 'BoundaryGroups') -or ($Include -contains 'BoundaryGroups')) - { - $resourceName = 'CMBoundaryGroups' - $boundaryGroups = Get-CMBoundaryGroup + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettingsSoftwareCenter') -or + ($Include -contains 'ClientSettingsSoftwareCenter')) + { + foreach ($item in $clientSettings) + { + $softwareCenter = Get-CMClientSetting -Setting SoftwareCenter -Name $item.Name + if (($softwareCenter) -and ($softwareCenter.SC_UserPortal -eq 0)) + { + if ([string]::IsNullOrEmpty($wCSSoftCenter)) + { + $resourceName = 'CMClientSettingsSoftwareCenter' + $wCSSoftCenter = "$resourceName = @(`r`n" + } - foreach ($boundaryGroup in $boundaryGroups) + Write-Verbose -Message ($script:localizedData.ClientSoftCenter -f $item.Name) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + Resources = $resources + StringValue = $item.Name + } + + $testThing = Set-OutFile @params + $wCSSoftCenter += "$testThing" + } + } + + if ($wCSSoftCenter) + { + $wCSSoftCenter += ")" + $fileOut += "$wCSSoftCenter`r`n" + } + } + + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettingsSoftwareDeployment') -or + ($Include -contains 'ClientSettingsSoftwareDeployment')) { - if ([string]::IsNullOrEmpty($wBG)) + foreach ($item in $clientSettings) { - $wBG = "$resourceName = @(`r`n" + if (Get-CMClientSetting -Setting SoftwareDeployment -Name $item.Name) + { + if ([string]::IsNullOrEmpty($wCSSoftDeploy)) + { + $resourceName = 'CMClientSettingsSoftwareDeployment' + $wCSSoftDeploy = "$resourceName = @(`r`n" + } + + Write-Verbose -Message ($script:localizedData.ClientSoftDeploy -f $item.Name) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + Resources = $resources + StringValue = $item.Name + } + + $testThing = Set-OutFile @params + $wCSSoftDeploy += "$testThing" + } } - Write-Verbose -Message ($script:localizedData.BoundaryGroup -f $boundaryGroup.Name) -Verbose - $params = @{ - ResourceName = $resourceName - SiteCode = $SiteCode - ExcludeList = @('SiteCode','Boundaries','BoundaryAction','SiteSystems') - Indent = 2 - StringValue = $boundaryGroup.Name - MultiEntry = $true - Resources = $resources + if ($wCSSoftDeploy) + { + $wCSSoftDeploy += ")" + $fileOut += "$wCSSoftDeploy`r`n" } + } - $testThing = Set-OutFile @params - $wBG += "$testThing" + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettingsSoftwareInventory') -or + ($Include -contains 'ClientSettingsSoftwareInventory')) + { + foreach ($item in $clientSettings) + { + if (Get-CMClientSetting -Setting SoftwareInventory -Name $item.Name) + { + if ([string]::IsNullOrEmpty($wCSSoftInven)) + { + $resourceName = 'CMClientSettingsSoftwareInventory' + $wCSSoftInven = "$resourceName = @(`r`n" + } + + Write-Verbose -Message ($script:localizedData.ClientSoftInven -f $item.Name) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + Resources = $resources + StringValue = $item.Name + } + + $testThing = Set-OutFile @params + $wCSSoftInven += "$testThing" + } + } + + if ($wCSSoftInven) + { + $wCSSoftInven += ")" + $fileOut += "$wCSSoftInven`r`n" + } } - if ($wBG) + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettingsSoftwareMetering') -or + ($Include -contains 'ClientSettingsSoftwareMetering')) { - $wBG += ")" - $fileOut += "$wBG`r`n" + foreach ($item in $clientSettings) + { + if (Get-CMClientSetting -Setting SoftwareMetering -Name $item.Name) + { + if ([string]::IsNullOrEmpty($wCSSoftMet)) + { + $resourceName = 'CMClientSettingsSoftwareMetering' + $wCSSoftMet = "$resourceName = @(`r`n" + } + + Write-Verbose -Message ($script:localizedData.ClientSoftMet -f $item.Name) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + Resources = $resources + StringValue = $item.Name + } + + $testThing = Set-OutFile @params + $wCSSoftMet += "$testThing" + } + } + + if ($wCSSoftMet) + { + $wCSSoftMet += ")" + $fileOut += "$wCSSoftMet`r`n" + } } - } - if (($Include -eq 'All' -and $Exclude -notcontains 'ClientPush') -or ($Include -contains 'ClientPush')) - { - $resourceName = 'CMClientPushSettings' - Write-Verbose -Message ($script:localizedData.SingleOutput -f $resourceName) -Verbose - $wPush = "$resourceName = @{`r`n" - $params = @{ - ResourceName = $resourceName - SiteCode = $SiteCode - Indent = 1 - MultiEntry = $false - Resources = $resources + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettingsSoftwareUpdate') -or + ($Include -contains 'ClientSettingsSoftwareUpdate')) + { + foreach ($item in $clientSettings) + { + if (Get-CMClientSetting -Setting SoftwareUpdates -Name $item.Name) + { + if ([string]::IsNullOrEmpty($wCSSoftUp)) + { + $resourceName = 'CMClientSettingsSoftwareUpdate' + $wCSSoftUp = "$resourceName = @(`r`n" + } + + Write-Verbose -Message ($script:localizedData.ClientSoftUp -f $item.Name) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + Resources = $resources + StringValue = $item.Name + } + + $testThing = Set-OutFile @params + $wCSSoftUp += "$testThing" + } + } + + if ($wCSSoftUp) + { + $wCSSoftUp += ")" + $fileOut += "$wCSSoftUp`r`n" + } } - $testThing = Set-OutFile @params - $wPush += "$testThing" - $fileOut += "$wPush`r`n" + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettingsStateMessaging') -or + ($Include -contains 'ClientSettingsStateMessaging')) + { + foreach ($item in $clientSettings) + { + if (Get-CMClientSetting -Setting StateMessaging -Name $item.Name) + { + if ([string]::IsNullOrEmpty($wCSStateMsg)) + { + $resourceName = 'CMClientSettingsStateMessaging' + $wCSStateMsg = "$resourceName = @(`r`n" + } + + Write-Verbose -Message ($script:localizedData.ClientStateMessage -f $item.Name) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + Resources = $resources + StringValue = $item.Name + } + + $testThing = Set-OutFile @params + $wCSStateMsg += "$testThing" + } + } + + if ($wCSStateMsg) + { + $wCSStateMsg += ")" + $fileOut += "$wCSStateMsg`r`n" + } + } + + if (($Include -eq 'All' -and $Exclude -notcontains 'ClientSettingsUserDeviceAffinity') -or + ($Include -contains 'ClientSettingsUserDeviceAffinity')) + { + foreach ($item in $clientSettings) + { + if (Get-CMClientSetting -Setting UserAndDeviceAffinity -Name $item.Name) + { + if ([string]::IsNullOrEmpty($wCSUDAffinity)) + { + $resourceName = 'CMClientSettingsUserDeviceAffinity' + $wCSUDAffinity = "$resourceName = @(`r`n" + } + + Write-Verbose -Message ($script:localizedData.ClientAffinity -f $item.Name) -Verbose + $params = @{ + ResourceName = $resourceName + SiteCode = $SiteCode + Indent = 2 + MultiEntry = $true + Resources = $resources + StringValue = $item.Name + } + + $testThing = Set-OutFile @params + $wCSUDAffinity += "$testThing" + } + } + + if ($wCSUDAffinity) + { + $wCSUDAffinity += ")" + $fileOut += "$wCSUDAffinity`r`n" + } + } + # new client setting here } if (($Include -eq 'All' -and $Exclude -notcontains 'ClientStatusSettings') -or ($Include -contains 'ClientStatusSettings')) @@ -7401,6 +11845,7 @@ function Set-ConfigMgrCBDscReverse $params = @{ ResourceName = $resourceName SiteCode = $SiteCode + ExcludeList = @('SiteCode','GroupDiscoveryScope') Indent = 1 Resources = $resources } diff --git a/source/Modules/ConfigMgrCBDsc.ReverseDsc/en-US/ConfigMgrCBDsc.ReverseDsc.strings.psd1 b/source/Modules/ConfigMgrCBDsc.ReverseDsc/en-US/ConfigMgrCBDsc.ReverseDsc.strings.psd1 index 446a29e2..347026a1 100644 --- a/source/Modules/ConfigMgrCBDsc.ReverseDsc/en-US/ConfigMgrCBDsc.ReverseDsc.strings.psd1 +++ b/source/Modules/ConfigMgrCBDsc.ReverseDsc/en-US/ConfigMgrCBDsc.ReverseDsc.strings.psd1 @@ -25,4 +25,23 @@ ConvertFrom-StringData @' NewDataFile = Creating new Datafile {0}. NewConfigFile = Creating Configuration file {0}. ConfigFileComplete = Completed creating new Configuration file only. + ClientSettings = Processing CMClientSettings for client: {0}. + ClientBits = Processing CMClientSettingsBits for client: {0}. + ClientClientCache = Processing CMClientSettingsClientCache for client policy: {0}. + ClientClientPolicy = Processing CMClientSettingsClientPolicy for client policy: {0}. + ClientCloud = Processing CMClientSettingsCloud for client policy: {0}. + ClientCompliance = Processing CMClientSettingsCompliance for client policy: {0}. + ClientCompAgent = Processing CMClientSettingsComputerAgent for client policy: {0}. + ClientDelivery = Processing CMClientSettingsDelivery for client policy: {0}. + ClientMetered = Processing CMClientSettingsMetered for client policy: {0}. + ClientHardware = Processing CMClientSettingsHardware for client policy: {0}. + ClientPower = Processing CMClientSettingsPower for client policy: {0}. + ClientRemoteTools = Processing CMClientSettingsRemoteTools for client policy: {0}. + ClientSoftCenter = Processing CMClientSettingsSoftwareCenter for client policy: {0}. + ClientSoftDeploy = Processing CMClientSettingsSoftwareDeployment for client policy: {0}. + ClientSoftInven = Processing CMClientSettingsSoftwareInventory for client policy: {0}. + ClientSoftMet = Processing CMClientSettingsSoftwareMetering for client policy: {0}. + ClientSoftUp = Processing CMClientSettingsSoftwareUpdate for client policy: {0}. + ClientStateMessage = Processing CMClientSettingsStateMessaging for client policy: {0}. + ClientAffinity = Processing CMClientSettingsUserDeviceAffinity for client policy: {0}. '@ diff --git a/tests/Unit/CMClientSettings.tests.ps1 b/tests/Unit/CMClientSettings.tests.ps1 new file mode 100644 index 00000000..4b9db271 --- /dev/null +++ b/tests/Unit/CMClientSettings.tests.ps1 @@ -0,0 +1,529 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettings' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettings\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $clientReturn = @{ + Type = 1 + Description = 'Test Settings' + SecuredScopeNames = @('Default','Scope1') + } + + $defaultReturn = @{ + Type = 0 + Description = 'Default Agent' + SecuredScopeNames = @('Default','Scope1') + } + + $getInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Type = 'Device' + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When retrieving Client Policy Settings for Client Cache' { + + It 'Should return desired results when client settings exist' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.Description | Should -Be -ExpectedValue 'Test Settings' + $result.Type | Should -Be -ExpectedValue 'Device' + $result.SecurityScopes | Should -Be -ExpectedValue @('Default','Scope1') + $result.SecurityScopesToInclude | Should -Be -ExpectedValue $null + $result.SecurityScopesToExclude | Should -Be -ExpectedValue $null + $result.Ensure | Should -Be -ExpectedValue 'Present' + } + + It 'Should return desired results when specifying a default client policy' { + Mock -CommandName Get-CMClientSetting -MockWith { $defaultReturn } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.Description | Should -Be -ExpectedValue $null + $result.Type | Should -Be -ExpectedValue $null + $result.SecurityScopes | Should -Be -ExpectedValue $null + $result.SecurityScopesToInclude | Should -Be -ExpectedValue $null + $result.SecurityScopesToExclude | Should -Be -ExpectedValue $null + $result.Ensure | Should -Be -ExpectedValue 'Present' + } + + It 'Should return desired results when client policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.Description | Should -Be -ExpectedValue $null + $result.Type | Should -Be -ExpectedValue $null + $result.SecurityScopes | Should -Be -ExpectedValue $null + $result.SecurityScopesToInclude | Should -Be -ExpectedValue $null + $result.SecurityScopesToExclude | Should -Be -ExpectedValue $null + $result.Ensure | Should -Be -ExpectedValue 'Absent' + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettings\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Description = 'Test Client' + Type = 'Device' + SecurityScopes = @('Default','Scope1') + SecurityScopesToInclude = $null + SecurityScopesToExclude = $null + Ensure = 'Present' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Description = 'Test Client' + Type = 'Device' + SecurityScopesToInclude = @('Default','Scope1') + SecurityScopesToExclude = @('Scope2') + Ensure = 'Present' + } + + $getClientHash = @{ + Name = 'ClientTest' + Type = 1 + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + Mock -CommandName New-CMClientSetting + Mock -CommandName Set-CMClientSetting + Mock -CommandName Add-CMObjectSecurityScope + Mock -CommandName Remove-CMObjectSecurityScope + Mock -CommandName Remove-CMClientSetting + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $returnAbsentClient = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Description = $null + Type = $null + SecurityScopes = $null + SecurityScopesToInclude = $null + SecurityScopesToExclude = $null + Ensure = 'Absent' + } + + $inputMisMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Description = 'Test Client Settings' + Type = 'Device' + SecurityScopes = @('Scope1','Scope2') + SecurityScopesToInclude = @('Default','Scope1') + SecurityScopesToExclude = @('Scope2') + Ensure = 'Present' + } + + $inputAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Type = 'Device' + Ensure = 'Absent' + } + + $inputNewClient = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Type = 'Device' + Ensure = 'Present' + } + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + Mock -CommandName Get-CMClientSetting + Mock -CommandName Get-CMSecurityScope + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Add-CMObjectSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMObjectSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMClientSetting -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when creating a new client policy with no description and no scopes' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsentClient } + Mock -CommandName Get-CMClientSetting + Mock -CommandName Get-CMSecurityScope + + Set-TargetResource @inputNewClient + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMClientSetting -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Add-CMObjectSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMObjectSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMClientSetting -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when creating a new client policy' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsentClient } + Mock -CommandName Get-CMClientSetting -MockWith { $getClientHash } + Mock -CommandName Get-CMSecurityScope -MockWith { $true } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMClientSetting -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMSecurityScope -Exactly -Times 1 -Scope It + Assert-MockCalled Add-CMObjectSecurityScope -Exactly -Times 1 -Scope It + Assert-MockCalled Remove-CMObjectSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMClientSetting -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when settings mismatch' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + Mock -CommandName Get-CMClientSetting -MockWith { $getClientHash } + Mock -CommandName Get-CMSecurityScope -MockWith { $true } + + Set-TargetResource @inputMisMatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSetting -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMSecurityScope -Exactly -Times 1 -Scope It + Assert-MockCalled Add-CMObjectSecurityScope -Exactly -Times 1 -Scope It + Assert-MockCalled Remove-CMObjectSecurityScope -Exactly -Times 1 -Scope It + Assert-MockCalled Remove-CMClientSetting -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when client policy is present and expected absent' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + Mock -CommandName Get-CMClientSetting + Mock -CommandName Get-CMSecurityScope + + Set-TargetResource @inputAbsent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Add-CMObjectSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMObjectSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMClientSetting -Exactly -Times 1 -Scope It + } + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $inputExcludeAll = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Description = 'Test Client' + Type = 'Device' + SecurityScopesToExclude = @('Default','Scope1') + Ensure = 'Present' + } + + $excludeAllMsg = 'Client Settings Policy must have at least 1 Security Scope assigned, SecurityScopesToExclude is currently set to remove all Security Scopes.' + + $inputTypeMisMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Type = 'User' + Ensure = 'Present' + } + + $typeMisMatchMsg = 'The ClientTest client setting already exists as a different type.' + + $inputIncludeExcludeMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Type = 'Device' + SecurityScopesToInclude = @('Scope1') + SecurityScopesToExclude = @('Scope1') + Ensure = 'Present' + } + + $includeExcludeMsg = 'SecurityScopesToInclude and SecurityScopesToExclude contain to same entry Scope1, remove from one of the arrays.' + + $inputSingleScope = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Type = 'Device' + SecurityScopesToInclude = @('Scope3') + } + + $nullScopeMsg = 'The Security Scope specified does not exist: Scope3.' + } + + It 'Should throw and call expected commands when client type mismatch' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + Mock -CommandName Get-CMClientSetting + Mock -CommandName Get-CMSecurityScope + + { Set-TargetResource @inputTypeMisMatch } | Should -Throw -ExpectedMessage $typeMisMatchMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Add-CMObjectSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMObjectSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMClientSetting -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when trying to exclude all security scopes' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + Mock -CommandName Get-CMClientSetting + Mock -CommandName Get-CMSecurityScope + + { Set-TargetResource @inputExcludeAll } | Should -Throw -ExpectedMessage $excludeAllMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Add-CMObjectSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMObjectSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMClientSetting -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when include and exclude contain the same entry' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + Mock -CommandName Get-CMClientSetting + Mock -CommandName Get-CMSecurityScope + + { Set-TargetResource @inputIncludeExcludeMatch } | Should -Throw -ExpectedMessage $includeExcludeMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Add-CMObjectSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMObjectSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMClientSetting -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when trying to add a security scope that does not exist' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + Mock -CommandName Get-CMClientSetting -MockWith { $getClientHash } + Mock -CommandName Get-CMSecurityScope + + { Set-TargetResource @inputSingleScope } | Should -Throw -ExpectedMessage $nullScopeMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSetting -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMSecurityScope -Exactly -Times 1 -Scope It + Assert-MockCalled Add-CMObjectSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMObjectSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMClientSetting -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettings\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Description = 'Test Client' + Type = 'Device' + SecurityScopes = @('Default','Scope1') + SecurityScopesToInclude = $null + SecurityScopesToExclude = $null + Ensure = 'Present' + } + + $returnAbsentClient = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Description = $null + Type = $null + SecurityScopes = $null + SecurityScopesToInclude = $null + SecurityScopesToExclude = $null + Ensure = 'Absent' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Description = 'Test Client' + Type = 'Device' + SecurityScopesToInclude = @('Default','Scope1') + SecurityScopesToExclude = @('Scope2') + Ensure = 'Present' + } + + $inputMisMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Description = 'Test Client Settings' + Type = 'Device' + SecurityScopes = @('Scope1','Scope2') + SecurityScopesToInclude = @('Default','Scope1') + SecurityScopesToExclude = @('Scope2') + Ensure = 'Present' + } + + $inputAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'CilentTest' + Type = 'Device' + Ensure = 'Absent' + } + + $inputExcludeAll = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Description = 'Test Client' + Type = 'Device' + SecurityScopesToExclude = @('Default','Scope1') + Ensure = 'Present' + } + + $inputTypeMisMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Type = 'User' + Ensure = 'Present' + } + + $inputIncludeExcludeMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Type = 'Device' + SecurityScopesToInclude = @('Scope1') + SecurityScopesToExclude = @('Scope1') + Ensure = 'Present' + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false when settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputMisMatch | Should -Be $false + } + + It 'Should return desired result false when client settings exists and expected absent' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputAbsent | Should -Be $false + } + + It 'Should return desired result false when excluding all security scopes' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputExcludeAll | Should -Be $false + } + + It 'Should return desired result false when client setting types does not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputTypeMisMatch | Should -Be $false + } + + It 'Should return desired result false when include and exclude contain the same entry' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputIncludeExcludeMatch | Should -Be $false + } + + It 'Should return desired result true when client policy is absent and expected absent' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsentClient } + + Test-TargetResource @inputAbsent | Should -Be $true + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/CMClientSettingsBits.tests.ps1 b/tests/Unit/CMClientSettingsBits.tests.ps1 new file mode 100644 index 00000000..b1bd903a --- /dev/null +++ b/tests/Unit/CMClientSettingsBits.tests.ps1 @@ -0,0 +1,441 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettingsBits' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsBits\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $clientDefault = @{ + Type = 0 + } + + $clientReturn = @{ + EnableBitsMaxBandwidth = $true + MaxBandwidthValidFrom = 0 + MaxBandwidthValidTo = 23 + MaxTransferRateOnSchedule = 900 + EnableDownloadOffSchedule = $true + MaxTransferRateOffSchedule = 400 + } + + $getInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableBitsMaxBandwidth = $true + + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When retrieving Client Policy Settings for BITS' { + + It 'Should return desired results when client settings exist' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientDefault } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } -ParameterFilter { $Setting -eq 'BackgroundIntelligentTransfer' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.EnableBitsMaxBandwidth | Should -Be -ExpectedValue $true + $result.MaxBandwidthBeginHr | Should -Be -ExpectedValue 0 + $result.MaxBandwidthEndHr | Should -Be -ExpectedValue 23 + $result.MaxTransferRateOnSchedule | Should -Be -ExpectedValue 900 + $result.EnableDownloadOffSchedule | Should -Be -ExpectedValue $true + $result.MaxTransferRateOffSchedule | Should -Be -ExpectedValue 400 + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired result when client setting policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.EnableBitsMaxBandwidth | Should -Be -ExpectedValue $null + $result.MaxBandwidthBeginHr | Should -Be -ExpectedValue $null + $result.MaxBandwidthEndHr | Should -Be -ExpectedValue $null + $result.MaxTransferRateOnSchedule | Should -Be -ExpectedValue $null + $result.EnableDownloadOffSchedule | Should -Be -ExpectedValue $null + $result.MaxTransferRateOffSchedule | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Absent' + $result.ClientType | Should -Be -ExpectedValue $null + } + + It 'Should return desired result when client setting policy exist but bits is not configured' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientDefault } + Mock -CommandName Get-CMClientSetting -MockWith { $null } -ParameterFilter { $Setting -eq 'BackgroundIntelligentTransfer' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.EnableBitsMaxBandwidth | Should -Be -ExpectedValue $null + $result.MaxBandwidthBeginHr | Should -Be -ExpectedValue $null + $result.MaxBandwidthEndHr | Should -Be -ExpectedValue $null + $result.MaxTransferRateOnSchedule | Should -Be -ExpectedValue $null + $result.EnableDownloadOffSchedule | Should -Be -ExpectedValue $null + $result.MaxTransferRateOffSchedule | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsBits\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableBitsMaxBandwidth = $true + MaxBandwidthBeginHr = 0 + MaxBandwidthEndHr = 23 + MaxTransferRateOnSchedule = 900 + EnableDownloadOffSchedule = $true + MaxTransferRateOffSchedule = 1000 + } + + Mock -CommandName Set-CMClientSettingBackgroundIntelligentTransfer + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableBitsMaxBandwidth = $true + MaxBandwidthBeginHr = 0 + MaxBandwidthEndHr = 23 + MaxTransferRateOnSchedule = 900 + EnableDownloadOffSchedule = $true + MaxTransferRateOffSchedule = 1000 + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableBitsMaxBandwidth = $null + MaxBandwidthBeginHr = $null + MaxBandwidthEndHr = $null + MaxTransferRateOnSchedule = $null + EnableDownloadOffSchedule = $null + MaxTransferRateOffSchedule = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnDefaultClient = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + EnableBitsMaxBandwidth = $true + MaxBandwidthBeginHr = 0 + MaxBandwidthEndHr = 23 + MaxTransferRateOnSchedule = 900 + EnableDownloadOffSchedule = $true + MaxTransferRateOffSchedule = 1000 + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $inputDefaultClient = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + EnableBitsMaxBandwidth = $true + MaxBandwidthBeginHr = 5 + MaxBandwidthEndHr = 11 + } + + $inputBitsDisabled = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableBitsMaxBandwidth = $false + EnableDownloadOffSchedule = $true + } + + $inputOffSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableBitsMaxBandwidth = $true + EnableDownloadOffSchedule = $false + MaxTransferRateOffSchedule = 1000 + } + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingBackgroundIntelligentTransfer -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingBackgroundIntelligentTransfer -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when disabling BITs' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputBitsDisabled + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingBackgroundIntelligentTransfer -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when modifying default client settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnDefaultClient } + + Set-TargetResource @inputDefaultClient + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingBackgroundIntelligentTransfer -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when settings do not match and specifying EnableDownloadOffSchedule disabled and specifying MaxTransferRateOffSchedule' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputOffSchedule + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingBackgroundIntelligentTransfer -Exactly -Times 1 -Scope It + } + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableBitsMaxBandwidth = $null + MaxBandwidthBeginHr = $null + MaxBandwidthEndHr = $null + MaxTransferRateOnSchedule = $null + EnableDownloadOffSchedule = $null + MaxTransferRateOffSchedule = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $absentMsg = 'Client Policy setting ClientTest does not exist, and will need to be created prior to making client setting changes.' + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserTest' + EnableBitsMaxBandwidth = $null + MaxBandwidthBeginHr = $null + MaxBandwidthEndHr = $null + MaxTransferRateOnSchedule = $null + EnableDownloadOffSchedule = $null + MaxTransferRateOffSchedule = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $userMsg = 'Client Settings for Bits only applies to Default and Device Client settings.' + } + + It 'Should throw and call expected commands when setting command when disabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $absentMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingBackgroundIntelligentTransfer -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when client policy is user based' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $userMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingBackgroundIntelligentTransfer -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsBits\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableBitsMaxBandwidth = $true + MaxBandwidthBeginHr = 0 + MaxBandwidthEndHr = 23 + MaxTransferRateOnSchedule = 900 + EnableDownloadOffSchedule = $true + MaxTransferRateOffSchedule = 1000 + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableBitsMaxBandwidth = $null + MaxBandwidthBeginHr = $null + MaxBandwidthEndHr = $null + MaxTransferRateOnSchedule = $null + EnableDownloadOffSchedule = $null + MaxTransferRateOffSchedule = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableBitsMaxBandwidth = $null + MaxBandwidthBeginHr = $null + MaxBandwidthEndHr = $null + MaxTransferRateOnSchedule = $null + EnableDownloadOffSchedule = $null + MaxTransferRateOffSchedule = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserTest' + EnableBitsMaxBandwidth = $null + MaxBandwidthBeginHr = $null + MaxBandwidthEndHr = $null + MaxTransferRateOnSchedule = $null + EnableDownloadOffSchedule = $null + MaxTransferRateOffSchedule = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableBitsMaxBandwidth = $true + MaxBandwidthBeginHr = 0 + MaxBandwidthEndHr = 23 + MaxTransferRateOnSchedule = 900 + EnableDownloadOffSchedule = $true + MaxTransferRateOffSchedule = 1000 + } + + $inputBitsDisabled = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableBitsMaxBandwidth = $false + EnableDownloadOffSchedule = $true + } + + $inputOffSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableBitsMaxBandwidth = $true + EnableDownloadOffSchedule = $false + MaxTransferRateOffSchedule = 1000 + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when client policy exists but does not set BITs settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when setting bits to disabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputBitsDisabled | Should -Be $false + } + + It 'Should return desired result false when client policy is user based' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + Test-TargetResource @inputBitsDisabled | Should -Be $false + } + + It 'Should return desired result false when settings do not match and specifying EnableDownloadOffSchedule disabled and specifying MaxTransferRateOffSchedule' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputOffSchedule | Should -Be $false + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/CMClientSettingsClientCache.tests.ps1 b/tests/Unit/CMClientSettingsClientCache.tests.ps1 new file mode 100644 index 00000000..925c631e --- /dev/null +++ b/tests/Unit/CMClientSettingsClientCache.tests.ps1 @@ -0,0 +1,583 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettingsClientCache' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsClientCache\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $clientReturn = @{ + ConfigureBranchCache = $true + BranchCacheEnabled = 1 + MaxBranchCacheSizePercent = 20 + ConfigureCacheSize = 1 + MaxCacheSizeMB = 1048576 + MaxCacheSizePercent = 80 + CanBeSuperPeer = $true + BroadcastPort = 8006 + HttpPort = 8003 + } + + $clientType = @{ + Type = 0 + } + + $getInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When retrieving Client Policy Settings for Client Cache' { + + It 'Should return desired results when client settings exist' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } -ParameterFilter { $Setting -eq 'ClientCache' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.ConfigureBranchCache | Should -Be -ExpectedValue $true + $result.EnableBranchCache | Should -Be -ExpectedValue $true + $result.MaxBranchCacheSizePercent | Should -Be -ExpectedValue 20 + $result.ConfigureCacheSize | Should -Be -ExpectedValue $true + $result.MaxCacheSize | Should -Be -ExpectedValue 1048576 + $result.MaxCacheSizePercent | Should -Be -ExpectedValue 80 + $result.EnableSuperPeer | Should -Be -ExpectedValue $true + $result.BroadcastPort | Should -Be -ExpectedValue 8006 + $result.DownloadPort | Should -Be -ExpectedValue 8003 + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired result when client setting policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.ConfigureBranchCache | Should -Be -ExpectedValue $null + $result.EnableBranchCache | Should -Be -ExpectedValue $null + $result.MaxBranchCacheSizePercent | Should -Be -ExpectedValue $null + $result.ConfigureCacheSize | Should -Be -ExpectedValue $null + $result.MaxCacheSize | Should -Be -ExpectedValue $null + $result.MaxCacheSizePercent | Should -Be -ExpectedValue $null + $result.EnableSuperPeer | Should -Be -ExpectedValue $null + $result.BroadcastPort | Should -Be -ExpectedValue $null + $result.DownloadPort | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Absent' + $result.ClientType | Should -Be -ExpectedValue $null + } + + It 'Should return desired result when client setting policy exist but client cache is not configured' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $null } -ParameterFilter { $Setting -eq 'ClientCache' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.ConfigureBranchCache | Should -Be -ExpectedValue $null + $result.EnableBranchCache | Should -Be -ExpectedValue $null + $result.MaxBranchCacheSizePercent | Should -Be -ExpectedValue $null + $result.ConfigureCacheSize | Should -Be -ExpectedValue $null + $result.MaxCacheSize | Should -Be -ExpectedValue $null + $result.MaxCacheSizePercent | Should -Be -ExpectedValue $null + $result.EnableSuperPeer | Should -Be -ExpectedValue $null + $result.BroadcastPort | Should -Be -ExpectedValue $null + $result.DownloadPort | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsClientCache\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $true + EnableBranchCache = $true + MaxBranchCacheSizePercent = 20 + ConfigureCacheSize = $true + MaxCacheSize = 1048576 + MaxCacheSizePercent = 80 + EnableSuperPeer = $true + BroadcastPort = 8006 + DownloadPort = 8003 + } + + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $true + EnableBranchCache = $true + MaxBranchCacheSizePercent = 20 + ConfigureCacheSize = $true + MaxCacheSize = 1048576 + MaxCacheSizePercent = 80 + EnableSuperPeer = $true + BroadcastPort = 8006 + DownloadPort = 8003 + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + Mock -CommandName Set-CMClientSettingClientCache + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $null + EnableBranchCache = $null + MaxBranchCacheSizePercent = $null + ConfigureCacheSize = $null + MaxCacheSize = $null + MaxCacheSizePercent = $null + EnableSuperPeer = $null + BroadcastPort = $null + DownloadPort = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnDefaultClient = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + ConfigureBranchCache = $true + EnableBranchCache = $true + MaxBranchCacheSizePercent = 20 + ConfigureCacheSize = $true + MaxCacheSize = 1048576 + MaxCacheSizePercent = 80 + EnableSuperPeer = $true + BroadcastPort = 8006 + DownloadPort = 8003 + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $inputDefaultClient = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + ConfigureBranchCache = $true + EnableBranchCache = $false + ConfigureCacheSize = $false + } + + $inputDisabled = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $false + } + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingClientCache -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingClientCache -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when disabling ConfigureBranchCache' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputDisabled + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingClientCache -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when modifying default client settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnDefaultClient } + + Set-TargetResource @inputDefaultClient + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingClientCache -Exactly -Times 1 -Scope It + } + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $null + EnableBranchCache = $null + MaxBranchCacheSizePercent = $null + ConfigureCacheSize = $null + MaxCacheSize = $null + MaxCacheSizePercent = $null + EnableSuperPeer = $null + BroadcastPort = $null + DownloadPort = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $absentMsg = 'Client Policy setting ClientTest does not exist, and will need to be created prior to making client setting changes.' + + $inputInvalidParamBranch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $false + EnableBranchCache = $true + } + + $errorBranchCache = 'When trying to set EnableBranchCache or MaxBranchCacheSizePercent, ConfigurureBranchCache must be set to true.' + + $inputInvalidParamCache = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $true + ConfigureCacheSize = $false + MaxCacheSize = 100 + } + + $configCacheFalseSize = 'When trying to set MaxCacheSize or MaxCacheSizePercent, ConfigureCacheSize must be set to true.' + + $inputInvalidParamSuperPeer = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $true + EnableSuperPeer = $false + BroadcastPort = 8000 + } + + $disableSuperBroad = 'When trying to set BroadcastPort or DownloadPort, EnableSuperPeer must be set to true.' + + $inputInvalidParamDisableBranch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $false + ConfigureCacheSize = $true + MaxCacheSizePercent = 90 + } + + $branchMaxCache = 'When setting MaxCacheSizePercent, ConfigureBranchCache must be set to true.' + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $null + EnableBranchCache = $null + MaxBranchCacheSizePercent = $null + ConfigureCacheSize = $null + MaxCacheSize = $null + MaxCacheSizePercent = $null + EnableSuperPeer = $null + BroadcastPort = $null + DownloadPort = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $wrongClientType = 'Client Settings for Client Cache only applies to Default and Device Client settings.' + } + + It 'Should throw and call expected commands when client policy is absent' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $absentMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingClientCache -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when ConfigureBranchCache is disabled and setting EnableBranchCached' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + { Set-TargetResource @inputInvalidParamBranch } | Should -Throw -ExpectedMessage $errorBranchCache + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingClientCache -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when ConfigureCacheSize is disabled and setting MaxCacheSize' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + { Set-TargetResource @inputInvalidParamCache } | Should -Throw -ExpectedMessage $configCacheFalseSize + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingClientCache -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when EnableSuperPeer is disabled and setting BroadcastPort' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + { Set-TargetResource @inputInvalidParamSuperPeer } | Should -Throw -ExpectedMessage $disableSuperBroad + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingClientCache -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when ConfigureBranchCache is disabled and setting MaxCacheSizePercent' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + { Set-TargetResource @inputInvalidParamDisableBranch } | Should -Throw -ExpectedMessage $branchMaxCache + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingClientCache -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when Client Policy Settings are user targeted' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $wrongClientType + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingClientCache -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsClientCache\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $true + EnableBranchCache = $true + MaxBranchCacheSizePercent = 20 + ConfigureCacheSize = $true + MaxCacheSize = 1048576 + MaxCacheSizePercent = 80 + EnableSuperPeer = $true + BroadcastPort = 8006 + DownloadPort = 8003 + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $null + EnableBranchCache = $null + MaxBranchCacheSizePercent = $null + ConfigureCacheSize = $null + MaxCacheSize = $null + MaxCacheSizePercent = $null + EnableSuperPeer = $null + BroadcastPort = $null + DownloadPort = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $null + EnableBranchCache = $null + MaxBranchCacheSizePercent = $null + ConfigureCacheSize = $null + MaxCacheSize = $null + MaxCacheSizePercent = $null + EnableSuperPeer = $null + BroadcastPort = $null + DownloadPort = $null + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $true + EnableBranchCache = $true + MaxBranchCacheSizePercent = 20 + ConfigureCacheSize = $true + MaxCacheSize = 1048576 + MaxCacheSizePercent = 80 + EnableSuperPeer = $true + BroadcastPort = 8006 + DownloadPort = 8003 + } + + $inputBranchCacheDisabled = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $false + } + + $inputInvalidParamBranch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $false + EnableBranchCache = $true + } + + $inputInvalidParamCache = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $true + ConfigureCacheSize = $false + MaxCacheSize = 100 + } + + $inputInvalidParamSuperPeer = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $true + EnableSuperPeer = $false + BroadcastPort = 8000 + } + + $inputInvalidParamDisableBranch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $false + MaxCacheSizePercent = 90 + } + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $null + EnableBranchCache = $null + MaxBranchCacheSizePercent = $null + ConfigureCacheSize = $null + MaxCacheSize = $null + MaxCacheSizePercent = $null + EnableSuperPeer = $null + BroadcastPort = $null + DownloadPort = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when client policy exists but does not set branch cache settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when setting branch cache to disabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputBranchCacheDisabled | Should -Be $false + } + + It 'Should return desired result false when disabling Cache settings and disabling branch cache' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputInvalidParamBranch | Should -Be $false + } + + It 'Should return desired result false when disabling ConfigureCacheSize and setting max cache size' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputInvalidParamCache | Should -Be $false + } + + It 'Should return desired result false when disabling SuperPeers and setting broadcast port' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputInvalidParamSuperPeer | Should -Be $false + } + + It 'Should return desired result false when disabling ConfigureBranchCache and setting MaxCacheSizePercent' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputInvalidParamDisableBranch | Should -Be $false + } + + It 'Should return desired result false when Client Policy settings are user based' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + Test-TargetResource @inputPresent | Should -Be $false + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/CMClientSettingsClientPolicy.tests.ps1 b/tests/Unit/CMClientSettingsClientPolicy.tests.ps1 new file mode 100644 index 00000000..5730a7b5 --- /dev/null +++ b/tests/Unit/CMClientSettingsClientPolicy.tests.ps1 @@ -0,0 +1,382 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettingsClientPolicy' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsClientPolicy\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $clientReturn = @{ + PolicyRequestAssignmentTimeout = 60 + PolicyEnableUserPolicyPolling = 1 + PolicyEnableUserPolicyOnInternet = 0 + PolicyEnableUserPolicyOnTS = $true + } + + $clientType = @{ + Type = 0 + } + + $getInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When retrieving Client Policy Settings for Client Policy' { + + It 'Should return desired results when client settings exist' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } -ParameterFilter { $Setting -eq 'ClientPolicy' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.PolicyPollingMins | Should -Be -ExpectedValue 60 + $result.EnableUserPolicy | Should -Be -ExpectedValue $true + $result.EnableUserPolicyOnInternet | Should -Be -ExpectedValue $false + $result.EnableUserPolicyOnTS | Should -Be -ExpectedValue $true + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired result when client setting policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.PolicyPollingMins | Should -Be -ExpectedValue $null + $result.EnableUserPolicy | Should -Be -ExpectedValue $null + $result.EnableUserPolicyOnInternet | Should -Be -ExpectedValue $null + $result.EnableUserPolicyOnTS | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Absent' + $result.ClientType | Should -Be -ExpectedValue $null + } + + It 'Should return desired result when client setting policy exist but client policy is not configured' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $null } -ParameterFilter { $Setting -eq 'ClientPolicy' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.PolicyPollingMins | Should -Be -ExpectedValue $null + $result.EnableUserPolicy | Should -Be -ExpectedValue $null + $result.EnableUserPolicyOnInternet | Should -Be -ExpectedValue $null + $result.EnableUserPolicyOnTS | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsClientPolicy\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + PolicyPollingMins = 60 + EnableUserPolicy = $true + EnableUserPolicyOnInternet = $false + EnableUserPolicyOnTS = $true + } + + Mock -CommandName Set-CMClientSettingClientPolicy + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + PolicyPollingMins = 60 + EnableUserPolicy = $true + EnableUserPolicyOnInternet = $false + EnableUserPolicyOnTS = $true + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + PolicyPollingMins = $null + EnableUserPolicy = $null + EnableUserPolicyOnInternet = $null + EnableUserPolicyOnTS = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnDefaultClient = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + PolicyPollingMins = 60 + EnableUserPolicy = $true + EnableUserPolicyOnInternet = $false + EnableUserPolicyOnTS = $true + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $inputDefaultClient = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + PolicyPollingMins = 50 + EnableUserPolicy = $true + EnableUserPolicyOnInternet = $true + EnableUserPolicyOnTS = $true + } + + $inputMismatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + PolicyPollingMins = 50 + EnableUserPolicy = $false + EnableUserPolicyOnInternet = $true + EnableUserPolicyOnTS = $false + } + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingClientPolicy -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when settings do not match and nothing is currently set' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingClientPolicy -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when settings mis match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputMismatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingClientPolicy -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when modifying default client settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnDefaultClient } + + Set-TargetResource @inputDefaultClient + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingClientPolicy -Exactly -Times 1 -Scope It + } + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + PolicyPollingMins = $null + EnableUserPolicy = $null + EnableUserPolicyOnInternet = $null + EnableUserPolicyOnTS = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $absentMsg = 'Client Policy setting ClientTest does not exist, and will need to be created prior to making client setting changes.' + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + PolicyPollingMins = $null + EnableUserPolicy = $null + EnableUserPolicyOnInternet = $null + EnableUserPolicyOnTS = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $wrongClientType = 'Client Settings for Client Policy settings only applies to Default and Device Client settings.' + } + + It 'Should throw and call expected commands when setting command when disabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $absentMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingClientPolicy -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when Client Policy Settings are user targeted' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $wrongClientType + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingClientPolicy -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsClientPolicy\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + PolicyPollingMins = 60 + EnableUserPolicy = $true + EnableUserPolicyOnInternet = $false + EnableUserPolicyOnTS = $true + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + PolicyPollingMins = $null + EnableUserPolicy = $null + EnableUserPolicyOnInternet = $null + EnableUserPolicyOnTS = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + PolicyPollingMins = $null + EnableUserPolicy = $null + EnableUserPolicyOnInternet = $null + EnableUserPolicyOnTS = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + PolicyPollingMins = $null + EnableUserPolicy = $null + EnableUserPolicyOnInternet = $null + EnableUserPolicyOnTS = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + PolicyPollingMins = 60 + EnableUserPolicy = $true + EnableUserPolicyOnInternet = $false + EnableUserPolicyOnTS = $true + } + + $inputMismatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + PolicyPollingMins = 50 + EnableUserPolicy = $false + EnableUserPolicyOnInternet = $true + EnableUserPolicyOnTS = $false + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when client policy exists but does not set settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when settings mismatch' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputMismatch | Should -Be $false + } + + It 'Should return desired result false when Client Policy settings are user based' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + Test-TargetResource @inputMismatch | Should -Be $false + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/CMClientSettingsCloudService.tests.ps1 b/tests/Unit/CMClientSettingsCloudService.tests.ps1 new file mode 100644 index 00000000..bc327152 --- /dev/null +++ b/tests/Unit/CMClientSettingsCloudService.tests.ps1 @@ -0,0 +1,326 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettingsCloudService' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsCloudService\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $returnClientType = @{ + Type = 1 + } + + $clientReturn = @{ + AllowCloudDP = 1 + AutoAADJoin = 0 + AllowCMG = $true + } + + $getInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When retrieving Client Policy Settings for Cloud Services' { + + It 'Should return desired results when client settings exist' { + Mock -CommandName Get-CMClientSetting -MockWith { $returnClientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } -ParameterFilter { $Setting -eq 'Cloud' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.AllowCloudDistributionPoint | Should -Be -ExpectedValue $true + $result.AutoAzureADJoin | Should -Be -ExpectedValue $false + $result.AllowCloudManagementGateway | Should -Be -ExpectedValue $true + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + + It 'Should return desired result when client setting policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.AllowCloudDistributionPoint | Should -Be -ExpectedValue $null + $result.AutoAzureADJoin | Should -Be -ExpectedValue $null + $result.AllowCloudManagementGateway | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Absent' + $result.ClientType | Should -Be -ExpectedValue $null + } + + It 'Should return desired result when client setting policy exist but cloud services is not configured' { + Mock -CommandName Get-CMClientSetting -MockWith { $returnClientType } + Mock -CommandName Get-CMClientSetting -MockWith { $null } -ParameterFilter { $Setting -eq 'Cloud' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.AllowCloudDistributionPoint | Should -Be -ExpectedValue $null + $result.AutoAzureADJoin | Should -Be -ExpectedValue $null + $result.AllowCloudManagementGateway | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsCloudService\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + AllowCloudDistributionPoint = $true + AutoAzureADJoin = $true + AllowCloudManagementGateway = $true + } + + Mock -CommandName Set-CMClientSettingCloudService + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + AllowCloudDistributionPoint = $true + AutoAzureADJoin = $true + AllowCloudManagementGateway = $true + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnPresentDefault = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Setting' + AllowCloudDistributionPoint = $true + AutoAzureADJoin = $true + AllowCloudManagementGateway = $true + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $returnNotConfigUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserTest' + AllowCloudDistributionPoint = $null + AutoAzureADJoin = $null + AllowCloudManagementGateway = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + AllowCloudDistributionPoint = $true + AutoAzureADJoin = $true + AllowCloudManagementGateway = $true + } + + $inputMismatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + AllowCloudDistributionPoint = $true + AutoAzureADJoin = $true + AllowCloudManagementGateway = $false + } + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingCloudService -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputMismatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingCloudService -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when client policy exists with no Cloud Services settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfigUser } + + Set-TargetResource @inputMismatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingCloudService -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when modifying default client settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + + Set-TargetResource @inputMismatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingCloudService -Exactly -Times 1 -Scope It + } + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + AllowCloudDistributionPoint = $null + AutoAzureADJoin = $null + AllowCloudManagementGateway = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $absentMsg = 'Client Policy setting ClientTest does not exist, and will need to be created prior to making client setting changes.' + } + + It 'Should throw and call expected commands when setting command when disabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $absentMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingCloudService -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsCloudService\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + AllowCloudDistributionPoint = $true + AutoAzureADJoin = $true + AllowCloudManagementGateway = $true + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + AllowCloudDistributionPoint = $null + AutoAzureADJoin = $null + AllowCloudManagementGateway = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $returnNotConfigUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserTest' + AllowCloudDistributionPoint = $null + AutoAzureADJoin = $null + AllowCloudManagementGateway = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + AllowCloudDistributionPoint = $true + AutoAzureADJoin = $true + AllowCloudManagementGateway = $true + } + + $inputMismatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + AllowCloudDistributionPoint = $true + AutoAzureADJoin = $true + AllowCloudManagementGateway = $false + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputMismatch | Should -Be $false + } + + It 'Should return desired result false when client policy exists with no Cloud Services settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfigUser } + + Test-TargetResource @inputMismatch | Should -Be $false + } + + It 'Should return desired result false when client policy settings does not exist' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + Test-TargetResource @inputMismatch | Should -Be $false + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/CMClientSettingsCompliance.tests.ps1 b/tests/Unit/CMClientSettingsCompliance.tests.ps1 new file mode 100644 index 00000000..ebe54055 --- /dev/null +++ b/tests/Unit/CMClientSettingsCompliance.tests.ps1 @@ -0,0 +1,581 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettingsCompliance' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsCompliance\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $clientReturn = @{ + Type = 0 + } + + $complianceReturn = @{ + Enabled = $true + EnableUserStateManagement = $true + EvaluationSchedule = 'DA159CC000280400' + } + + $cmScheduleReturn = @{ + MinuteDuration = $null + RecurInterval = 1 + WeekOrder = $null + HourDuration = $null + Start = '9/21/2021 16:54' + DayOfWeek = $null + ScheduleType = 'MonthlyByDay' + MonthDay = 0 + DayDuration = $null + } + + $getInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + Mock -CommandName Get-CMSchedule -MockWith { $cmScheduleReturn } + } + + Context 'When retrieving Client Policy Settings for Compliance' { + + It 'Should return desired results when client settings exist' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $complianceReturn } -ParameterFilter { $Setting -eq 'ComplianceSettings' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $true + $result.EnableUserDataAndProfile | Should -Be -ExpectedValue $true + $result.Start | Should -Be -ExpectedValue '9/21/2021 16:54' + $result.ScheduleType | Should -Be -ExpectedValue 'MonthlyByDay' + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue 0 + $result.RecurInterval | Should -Be -ExpectedValue 1 + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired result when client setting policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $null + $result.EnableUserDataAndProfile | Should -Be -ExpectedValue $null + $result.Start | Should -Be -ExpectedValue $null + $result.ScheduleType | Should -Be -ExpectedValue $null + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue $null + $result.RecurInterval | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Absent' + $result.ClientType | Should -Be -ExpectedValue $null + } + + It 'Should return desired result when client setting policy exist but compliance settings is not configured' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $null } -ParameterFilter { $Setting -eq 'ComplianceSettings' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $null + $result.EnableUserDataAndProfile | Should -Be -ExpectedValue $null + $result.Start | Should -Be -ExpectedValue $null + $result.ScheduleType | Should -Be -ExpectedValue $null + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue $null + $result.RecurInterval | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsCompliance\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $returnPresentDevice = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EnableUserDataAndProfile = $true + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnPresentDefault = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + EnableUserDataAndProfile = $true + Start = '9/21/2021 16:54' + ScheduleType = 'MonthlyByDay' + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = 0 + RecurInterval = 1 + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EnableUserDataAndProfile = $true + } + + Mock -CommandName Set-CMClientSettingComplianceSetting + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + EnableUserDataAndProfile = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $inputPresentMismatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EnableUserDataAndProfile = $false + } + + $inputPresentDisable = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $false + EnableUserDataAndProfile = $false + } + + $inputSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + EnableUserDataAndProfile = $true + ScheduleType = 'MonthlyByWeek' + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + $inputDeviceSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EnableUserDataAndProfile = $true + ScheduleType = 'Days' + RecurInterval = 10 + } + + $cmScheduleInput = @{ + RecurCount = 1 + RecurInterval = 'Days' + } + + Mock -CommandName Set-CMSchedule -MockWith { $cmScheduleInput } + Mock -CommandName New-CMSchedule + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingComplianceSetting -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule + + Set-TargetResource @inputPresentMismatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingComplianceSetting -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when settings do not match and disabling' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule + + Set-TargetResource @inputPresentDisable + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingComplianceSetting -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when schedule does not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + Mock -CommandName Test-CMSchedule -MockWith { $false } + + Set-TargetResource @inputSchedule + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingComplianceSetting -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when trying to modify schedule on device collection and all other settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule + + Set-TargetResource @inputDeviceSchedule + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingComplianceSetting -Exactly -Times 0 -Scope It + }#> + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + EnableUserDataAndProfile = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $absentMsg = 'Client Policy setting ClientTest does not exist, and will need to be created prior to making client setting changes.' + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserTest' + Enable = $null + EnableUserDataAndProfile = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $clientTypeError = 'Client Settings for Compliance settings only applies to Default and Device client settings.' + + $inputInvalidSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + $scheduleError = 'In order to create a schedule you must specify ScheduleType.' + + Mock -CommandName Test-CMSchedule + Mock -CommandName Set-CMSchedule + Mock -CommandName New-CMSchedule + } + + It 'Should throw and call expected commands when client policy does not exist' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $absentMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingComplianceSetting -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when client policy is a user policy' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $clientTypeError + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingComplianceSetting -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when not specifying a schedule type with schedule settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + + { Set-TargetResource @inputInvalidSchedule } | Should -Throw -ExpectedMessage $scheduleError + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingComplianceSetting -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsCompliance\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresentDevice = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EnableUserDataAndProfile = $true + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnPresentDefault = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + EnableUserDataAndProfile = $true + Start = '9/21/2021 16:54' + ScheduleType = 'MonthlyByDay' + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = 0 + RecurInterval = 1 + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + EnableUserDataAndProfile = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + EnableUserDataAndProfile = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserTest' + Enable = $null + EnableUserDataAndProfile = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EnableUserDataAndProfile = $true + } + + $inputPresentMismatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $false + EnableUserDataAndProfile = $true + } + + $inputSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + EnableUserDataAndProfile = $true + ScheduleType = 'MonthlyByWeek' + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + $inputInvalidSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + $inputDeviceSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EnableUserDataAndProfile = $true + ScheduleType = 'Days' + RecurInterval = 10 + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Test-TargetResource @inputPresentMismatch | Should -Be $false + } + + It 'Should return desired result false when schedule does not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + + Test-TargetResource @inputSchedule | Should -Be $false + } + + It 'Should return desired result false when client policy does not exist' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when client policy is user based' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when not specifying a schedule type' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + + Test-TargetResource @inputInvalidSchedule | Should -Be $false + } + + It 'Should return desired result true when settings match and specifying device policy and setting a schedule' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Test-TargetResource @inputDeviceSchedule | Should -Be $true + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/CMClientSettingsComputerAgent.tests.ps1 b/tests/Unit/CMClientSettingsComputerAgent.tests.ps1 new file mode 100644 index 00000000..d6e6fb1c --- /dev/null +++ b/tests/Unit/CMClientSettingsComputerAgent.tests.ps1 @@ -0,0 +1,465 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettingsComputerAgent' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsComputerAgent\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $clientReturn = @{ + ReminderInterval = 2 + DayReminderInterval = 1 + HourReminderInterval = 20 + BrandingTitle = 'Test Site' + UseNewSoftwareCenter = $true + EnableHealthAttestation = $true + UseOnPremHAService = $true + InstallRestriction = 1 + SuspendBitLocker = 0 + EnableThirdPartyOrchestration = 1 + PowerShellExecutionPolicy = 1 + DisplayNewProgramNotification = $true + } + + $clientType = @{ + Type = '1' + } + + $getInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When retrieving Client Policy Settings for Computer Agent' { + + It 'Should return desired results when client settings exist' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } -ParameterFilter { $Setting -eq 'ComputerAgent' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.InitialReminderHr | Should -Be -ExpectedValue 2 + $result.InterimReminderHr | Should -Be -ExpectedValue 1 + $result.FinalReminderMins | Should -Be -ExpectedValue 20 + $result.BrandingTitle | Should -Be -ExpectedValue 'Test Site' + $result.UseNewSoftwareCenter | Should -Be -ExpectedValue $true + $result.EnableHealthAttestation | Should -Be -ExpectedValue $true + $result.UseOnPremisesHealthAttestation | Should -Be -ExpectedValue $true + $result.InstallRestriction | Should -Be -ExpectedValue 'OnlyAdministrators' + $result.SuspendBitLocker | Should -Be -ExpectedValue 'Never' + $result.EnableThirdPartyOrchestration | Should -Be -ExpectedValue 'Yes' + $result.PowerShellExecutionPolicy | Should -Be -ExpectedValue 'Bypass' + $result.DisplayNewProgramNotification | Should -Be -ExpectedValue $true + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + + It 'Should return desired result when client setting policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.InitialReminderHr | Should -Be -ExpectedValue $null + $result.InterimReminderHr | Should -Be -ExpectedValue $null + $result.FinalReminderMins | Should -Be -ExpectedValue $null + $result.BrandingTitle | Should -Be -ExpectedValue $null + $result.UseNewSoftwareCenter | Should -Be -ExpectedValue $null + $result.EnableHealthAttestation | Should -Be -ExpectedValue $null + $result.UseOnPremisesHealthAttestation | Should -Be -ExpectedValue $null + $result.InstallRestriction | Should -Be -ExpectedValue $null + $result.SuspendBitLocker | Should -Be -ExpectedValue $null + $result.EnableThirdPartyOrchestration | Should -Be -ExpectedValue $null + $result.PowerShellExecutionPolicy | Should -Be -ExpectedValue $null + $result.DisplayNewProgramNotification | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Absent' + $result.ClientType | Should -Be -ExpectedValue $null + } + + It 'Should return desired result when client setting policy exist but computer agent is not configured' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $null } -ParameterFilter { $Setting -eq 'ComputerAgent' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.InitialReminderHr | Should -Be -ExpectedValue $null + $result.InterimReminderHr | Should -Be -ExpectedValue $null + $result.FinalReminderMins | Should -Be -ExpectedValue $null + $result.BrandingTitle | Should -Be -ExpectedValue $null + $result.UseNewSoftwareCenter | Should -Be -ExpectedValue $null + $result.EnableHealthAttestation | Should -Be -ExpectedValue $null + $result.UseOnPremisesHealthAttestation | Should -Be -ExpectedValue $null + $result.InstallRestriction | Should -Be -ExpectedValue $null + $result.SuspendBitLocker | Should -Be -ExpectedValue $null + $result.EnableThirdPartyOrchestration | Should -Be -ExpectedValue $null + $result.PowerShellExecutionPolicy | Should -Be -ExpectedValue $null + $result.DisplayNewProgramNotification | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsComputerAgent\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + InitialReminderHr = 2 + InterimReminderHr = 1 + FinalReminderMins = 20 + BrandingTitle = 'Test Site' + UseNewSoftwareCenter = $true + EnableHealthAttestation = $true + UseOnPremisesHealthAttestation = $true + InstallRestriction = 'OnlyAdministrators' + SuspendBitLocker = 'Never' + EnableThirdPartyOrchestration = 'Yes' + } + + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + InitialReminderHr = 2 + InterimReminderHr = 1 + FinalReminderMins = 20 + BrandingTitle = 'Test Site' + UseNewSoftwareCenter = $true + EnableHealthAttestation = $true + UseOnPremisesHealthAttestation = $true + InstallRestriction = 'OnlyAdministrators' + SuspendBitLocker = 'Never' + EnableThirdPartyOrchestration = 'Yes' + PowerShellExecutionPolicy = 'Bypass' + DisplayNewProgramNotification = $true + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + Mock -CommandName Set-CMClientSettingComputerAgent + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $inputMismatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + InitialReminderHr = 3 + InterimReminderHr = 2 + FinalReminderMins = 25 + BrandingTitle = 'Test Site' + UseNewSoftwareCenter = $true + EnableHealthAttestation = $false + UseOnPremisesHealthAttestation = $true + InstallRestriction = 'OnlyAdministrators' + SuspendBitLocker = 'Always' + EnableThirdPartyOrchestration = 'No' + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + InitialReminderHr = $null + InterimReminderHr = $null + FinalReminderMins = $null + BrandingTitle = $null + UseNewSoftwareCenter = $null + EnableHealthAttestation = $null + UseOnPremisesHealthAttestation = $null + InstallRestriction = $null + SuspendBitLocker = $null + EnableThirdPartyOrchestration = $null + PowerShellExecutionPolicy = $null + DisplayNewProgramNotification = $null + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $inputMismatchHealth = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + UseNewSoftwareCenter = $true + EnableHealthAttestation = $true + UseOnPremisesHealthAttestation = $false + } + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingComputerAgent -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputMismatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingComputerAgent -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when settings do not match when EnableHealth matches and UseOnPremise does not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputMismatchHealth + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingComputerAgent -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when state returns present for the default policy' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingComputerAgent -Exactly -Times 1 -Scope It + } + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + InitialReminderHr = $null + InterimReminderHr = $null + FinalReminderMins = $null + BrandingTitle = $null + UseNewSoftwareCenter = $null + EnableHealthAttestation = $null + UseOnPremisesHealthAttestation = $null + InstallRestriction = $null + SuspendBitLocker = $null + EnableThirdPartyOrchestration = $null + PowerShellExecutionPolicy = $null + DisplayNewProgramNotification = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $absentMsg = 'Client Policy setting ClientTest does not exist, and will need to be created prior to making client setting changes.' + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + InitialReminderHr = $null + InterimReminderHr = $null + FinalReminderMins = $null + BrandingTitle = $null + UseNewSoftwareCenter = $null + EnableHealthAttestation = $null + UseOnPremisesHealthAttestation = $null + InstallRestriction = $null + SuspendBitLocker = $null + EnableThirdPartyOrchestration = $null + PowerShellExecutionPolicy = $null + DisplayNewProgramNotification = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $wrongClientType = 'Client Settings for software update only applies to Default and Device Client settings.' + } + + It 'Should throw and call expected commands when client settings does not exist' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $absentMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingComputerAgent -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when client type is incorrect' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $wrongClientType + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingComputerAgent -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsComputerAgent\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + InitialReminderHr = 2 + InterimReminderHr = 1 + FinalReminderMins = 20 + BrandingTitle = 'Test Site' + UseNewSoftwareCenter = $true + EnableHealthAttestation = $true + UseOnPremisesHealthAttestation = $true + InstallRestriction = 'OnlyAdministrators' + SuspendBitLocker = 'Never' + EnableThirdPartyOrchestration = 'Yes' + PowerShellExecutionPolicy = 'Bypass' + DisplayNewProgramNotification = $true + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + InitialReminderHr = $null + InterimReminderHr = $null + FinalReminderMins = $null + BrandingTitle = $null + UseNewSoftwareCenter = $null + EnableHealthAttestation = $null + UseOnPremisesHealthAttestation = $null + InstallRestriction = $null + SuspendBitLocker = $null + EnableThirdPartyOrchestration = $null + PowerShellExecutionPolicy = $null + DisplayNewProgramNotification = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + InitialReminderHr = $null + InterimReminderHr = $null + FinalReminderMins = $null + BrandingTitle = $null + UseNewSoftwareCenter = $null + EnableHealthAttestation = $null + UseOnPremisesHealthAttestation = $null + InstallRestriction = $null + SuspendBitLocker = $null + EnableThirdPartyOrchestration = $null + PowerShellExecutionPolicy = $null + DisplayNewProgramNotification = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + InitialReminderHr = 2 + InterimReminderHr = 1 + FinalReminderMins = 20 + BrandingTitle = 'Test Site' + UseNewSoftwareCenter = $true + EnableHealthAttestation = $true + UseOnPremisesHealthAttestation = $true + InstallRestriction = 'OnlyAdministrators' + SuspendBitLocker = 'Never' + EnableThirdPartyOrchestration = 'Yes' + } + + $inputMismatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + InitialReminderHr = 3 + InterimReminderHr = 2 + FinalReminderMins = 25 + BrandingTitle = 'Test Site' + UseNewSoftwareCenter = $true + EnableHealthAttestation = $false + UseOnPremisesHealthAttestation = $true + InstallRestriction = 'OnlyAdministrators' + SuspendBitLocker = 'Always' + EnableThirdPartyOrchestration = 'No' + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false when settings mismatch' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputMismatch | Should -Be $false + } + + It 'Should return desired result false when user policy is returned' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + Test-TargetResource @inputMismatch | Should -Be $false + } + + It 'Should return desired result false when client policy is absent' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + Test-TargetResource @inputMismatch | Should -Be $false + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/CMClientSettingsDelivery.tests.ps1 b/tests/Unit/CMClientSettingsDelivery.tests.ps1 new file mode 100644 index 00000000..802dab3a --- /dev/null +++ b/tests/Unit/CMClientSettingsDelivery.tests.ps1 @@ -0,0 +1,328 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettingsDelivery' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsDelivery\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $clientReturn = @{ + EnableWindowsDO = 1 + } + + $clientType = @{ + Type = '0' + } + + $getInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When retrieving Client Policy Settings for Delivery Optimization' { + + It 'Should return desired results when client settings exist' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } -ParameterFilter { $Setting -eq 'DeliveryOptimization' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.Enable | Should -Be -ExpectedValue $true + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired result when client setting policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.Enable | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Absent' + $result.ClientType | Should -Be -ExpectedValue $null + } + + It 'Should return desired result when client setting policy exist but delivery optimization is not configured' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $null } -ParameterFilter { $Setting -eq 'DeliveryOptimization' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.Enable | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsDelivery\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + } + + Mock -CommandName Set-CMClientSettingDeliveryOptimization + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnPresentDefaultClient = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $false + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $inputDeliveryDisabled = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $false + } + + $inputDeliveryDefaultClient = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + } + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingDeliveryOptimization -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingDeliveryOptimization -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when disabling delivery optimization' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputDeliveryDisabled + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingDeliveryOptimization -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when disabling delivery optimization for default client settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefaultClient } + + Set-TargetResource @inputDeliveryDefaultClient + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingDeliveryOptimization -Exactly -Times 1 -Scope It + } + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $absentMsg = 'Client Policy setting ClientTest does not exist, and will need to be created prior to making client setting changes.' + + $returnWrongClientType = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $wrongClientType = 'Client Settings for Delivery Optimization only applies to Default and Device Client settings.' + } + + It 'Should throw and call expected commands when client settings does not exist' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $absentMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingDeliveryOptimization -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when client type is incorrect' { + Mock -CommandName Get-TargetResource -MockWith { $returnWrongClientType } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $wrongClientType + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingDeliveryOptimization -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsDelivery\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnWrongClientType = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + } + + $inputDisabled = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $false + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when client policy exists but currently does not set Delivery optimization settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when client policy exists but is currently a User based client policy' { + Mock -CommandName Get-TargetResource -MockWith { $returnWrongClientType } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when setting delivery optimization to disabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputDisabled | Should -Be $false + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/CMClientSettingsHardware.tests.ps1 b/tests/Unit/CMClientSettingsHardware.tests.ps1 new file mode 100644 index 00000000..17a21554 --- /dev/null +++ b/tests/Unit/CMClientSettingsHardware.tests.ps1 @@ -0,0 +1,708 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettingsHardware' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsHardware\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $clientReturn = @{ + Type = 0 + } + + $hardwareReturnNone = @{ + Enabled = $true + MaxRandomDelayMinutes = 40 + Schedule = 'DA159CC000280400' + Max3rdPartyMIFSize = 100 + MIFCollection = 0 + } + + $hardwareReturnNoIDMif = @{ + Enabled = $true + MaxRandomDelayMinutes = 40 + Schedule = 'DA159CC000280400' + Max3rdPartyMIFSize = 100 + MIFCollection = 4 + } + + $hardwareReturnIDMif = @{ + Enabled = $true + MaxRandomDelayMinutes = 40 + Schedule = 'DA159CC000280400' + Max3rdPartyMIFSize = 100 + MIFCollection = 8 + } + + $hardwareReturnBoth = @{ + Enabled = $true + MaxRandomDelayMinutes = 40 + Schedule = 'DA159CC000280400' + Max3rdPartyMIFSize = 100 + MIFCollection = 12 + } + + $cmScheduleReturn = @{ + MinuteDuration = $null + RecurInterval = 1 + WeekOrder = $null + HourDuration = $null + Start = '9/21/2021 16:54' + DayOfWeek = $null + ScheduleType = 'MonthlyByDay' + MonthDay = 0 + DayDuration = $null + } + + $getInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + Mock -CommandName Get-CMSchedule -MockWith { $cmScheduleReturn } + } + + Context 'When retrieving Client Policy Settings for hardware settings' { + + It 'Should return desired results when client settings exist collect mif file set to none' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $hardwareReturnNone } -ParameterFilter { $Setting -eq 'HardwareInventory' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $true + $result.MaxRandomDelayMins | Should -Be -ExpectedValue 40 + $result.Start | Should -Be -ExpectedValue '9/21/2021 16:54' + $result.ScheduleType | Should -Be -ExpectedValue 'MonthlyByDay' + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue 0 + $result.RecurInterval | Should -Be -ExpectedValue 1 + $result.CollectMifFile | Should -Be -ExpectedValue 'None' + $result.MaxThirdPartyMifSize | Should -Be -ExpectedValue 100 + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired results when client settings exist collect mif file set to CollectNoIdMifFile' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $hardwareReturnNoIDMif } -ParameterFilter { $Setting -eq 'HardwareInventory' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $true + $result.MaxRandomDelayMins | Should -Be -ExpectedValue 40 + $result.Start | Should -Be -ExpectedValue '9/21/2021 16:54' + $result.ScheduleType | Should -Be -ExpectedValue 'MonthlyByDay' + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue 0 + $result.RecurInterval | Should -Be -ExpectedValue 1 + $result.CollectMifFile | Should -Be -ExpectedValue 'CollectNoIdMifFile' + $result.MaxThirdPartyMifSize | Should -Be -ExpectedValue 100 + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired results when client settings exist collect mif file set to CollectIdMifFile' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $hardwareReturnIDMif } -ParameterFilter { $Setting -eq 'HardwareInventory' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $true + $result.MaxRandomDelayMins | Should -Be -ExpectedValue 40 + $result.Start | Should -Be -ExpectedValue '9/21/2021 16:54' + $result.ScheduleType | Should -Be -ExpectedValue 'MonthlyByDay' + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue 0 + $result.RecurInterval | Should -Be -ExpectedValue 1 + $result.CollectMifFile | Should -Be -ExpectedValue 'CollectIdMifFile' + $result.MaxThirdPartyMifSize | Should -Be -ExpectedValue 100 + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired results when client settings exist collect mif file set to CollectIdMifAndNoIdMifFile' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $hardwareReturnBoth } -ParameterFilter { $Setting -eq 'HardwareInventory' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $true + $result.MaxRandomDelayMins | Should -Be -ExpectedValue 40 + $result.Start | Should -Be -ExpectedValue '9/21/2021 16:54' + $result.ScheduleType | Should -Be -ExpectedValue 'MonthlyByDay' + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue 0 + $result.RecurInterval | Should -Be -ExpectedValue 1 + $result.CollectMifFile | Should -Be -ExpectedValue 'CollectIdMifAndNoIdMifFile' + $result.MaxThirdPartyMifSize | Should -Be -ExpectedValue 100 + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired result when client setting policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $null + $result.MaxRandomDelayMins | Should -Be -ExpectedValue $null + $result.Start | Should -Be -ExpectedValue $null + $result.ScheduleType | Should -Be -ExpectedValue $null + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue $null + $result.RecurInterval | Should -Be -ExpectedValue $null + $result.CollectMifFile | Should -Be -ExpectedValue $null + $result.MaxThirdPartyMifSize | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Absent' + $result.ClientType | Should -Be -ExpectedValue $null + } + + It 'Should return desired result when client setting policy exist but hardware settings is not configured' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $null } -ParameterFilter { $Setting -eq 'HardwareInventory' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $null + $result.MaxRandomDelayMins | Should -Be -ExpectedValue $null + $result.Start | Should -Be -ExpectedValue $null + $result.ScheduleType | Should -Be -ExpectedValue $null + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue $null + $result.RecurInterval | Should -Be -ExpectedValue $null + $result.CollectMifFile | Should -Be -ExpectedValue $null + $result.MaxThirdPartyMifSize | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsHardware\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $returnPresentDevice = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + MaxRandomDelayMins = 40 + Start = $null + ScheduleType = 'MonthlyByWeek' + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + DayofMonth = $null + RecurInterval = 1 + CollectMifFile = $null + MaxThirdPartyMifSize = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnPresentDefault = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + MaxRandomDelayMins = 100 + Start = '9/21/2021 16:54' + ScheduleType = 'MonthlyByDay' + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = 0 + RecurInterval = 1 + CollectMifFile = 'None' + MaxThirdPartyMifSize = 100 + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + MaxRandomDelayMins = 40 + MaxThirdPartyMifSize = 200 + } + + Mock -CommandName Set-CMClientSettingHardwareInventory + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + MaxRandomDelayMins = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + CollectMifFile = $null + MaxThirdPartyMifSize = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $inputPresentMismatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $false + MaxRandomDelayMins = 20 + } + + $inputPresentDisable =@{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $false + } + + $inputPersentMismatchDefault = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $false + MaxRandomDelayMins = 10 + } + + $inputSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + MaxRandomDelayMins = 40 + ScheduleType = 'MonthlyByWeek' + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + $inputDeviceSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + MaxRandomDelayMins = $true + ScheduleType = 'Days' + RecurInterval = 10 + } + + $cmScheduleInput = @{ + RecurCount = 1 + RecurInterval = 'Days' + } + + Mock -CommandName Set-CMSchedule -MockWith { $cmScheduleInput } + Mock -CommandName New-CMSchedule + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingHardwareInventory -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule + + Set-TargetResource @inputPresentMismatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingHardwareInventory -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when settings do not match and disabling' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule + + Set-TargetResource @inputPresentDisable + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingHardwareInventory -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when schedule does not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + Mock -CommandName Test-CMSchedule -MockWith { $false } + + Set-TargetResource @inputSchedule + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingHardwareInventory -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when trying to modify schedule on device collection and all other settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule -MockWith { $false } + + Set-TargetResource @inputDeviceSchedule + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingHardwareInventory -Exactly -Times 1 -Scope It + } + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + MaxRandomDelayMins = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + CollectMifFile = $null + MaxThirdPartyMifSize = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $absentMsg = 'Client Policy setting ClientTest does not exist, and will need to be created prior to making client setting changes.' + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserTest' + Enable = $null + MaxRandomDelayMins = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + CollectMifFile = $null + MaxThirdPartyMifSize = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $clientTypeError = 'Client Settings for Hardware Inventory only applies to Default and Device client settings.' + + $inputInvalidSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + $scheduleError = 'In order to create a schedule you must specify ScheduleType.' + + Mock -CommandName Test-CMSchedule + Mock -CommandName Set-CMSchedule + Mock -CommandName New-CMSchedule + } + + It 'Should throw and call expected commands when client policy does not exist' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $absentMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingHardwareInventory -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when client policy is a user policy' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $clientTypeError + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingHardwareInventory -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when not specifying a schedule type with schedule settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + + { Set-TargetResource @inputInvalidSchedule } | Should -Throw -ExpectedMessage $scheduleError + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingHardwareInventory -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsHardware\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresentDevice = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + MaxRandomDelayMins = 40 + Start = $null + ScheduleType = 'MonthlyByWeek' + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + DayofMonth = $null + RecurInterval = 1 + CollectMifFile = $null + MaxThirdPartyMifSize = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnPresentDefault = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + MaxRandomDelayMins = 100 + Start = '9/21/2021 16:54' + ScheduleType = 'MonthlyByDay' + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = 0 + RecurInterval = 1 + CollectMifFile = 'None' + MaxThirdPartyMifSize = 100 + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + MaxRandomDelayMins = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + CollectMifFile = $null + MaxThirdPartyMifSize = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + MaxRandomDelayMins = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + CollectMifFile = $null + MaxThirdPartyMifSize = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserTest' + Enable = $null + MaxRandomDelayMins = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + CollectMifFile = $null + MaxThirdPartyMifSize = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + MaxRandomDelayMins = 40 + MaxThirdPartyMifSize = 200 + } + + $inputPresentMismatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $false + MaxRandomDelayMins = 20 + } + + $inputPersentMismatchDefault = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $false + MaxRandomDelayMins = 10 + } + + $inputSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + MaxRandomDelayMins = 40 + ScheduleType = 'MonthlyByWeek' + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + $inputInvalidSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + $inputDeviceSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + MaxRandomDelayMins = $true + ScheduleType = 'Days' + RecurInterval = 10 + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Test-TargetResource @inputPresentMismatch | Should -Be $false + } + + It 'Should return desired result false when schedule does not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + + Test-TargetResource @inputSchedule | Should -Be $false + } + + It 'Should return desired result false when client policy does not exist' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when client policy is user based' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when not specifying a schedule type' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + + Test-TargetResource @inputInvalidSchedule | Should -Be $false + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/CMClientSettingsMetered.tests.ps1 b/tests/Unit/CMClientSettingsMetered.tests.ps1 new file mode 100644 index 00000000..c1570bb9 --- /dev/null +++ b/tests/Unit/CMClientSettingsMetered.tests.ps1 @@ -0,0 +1,373 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettingsMetered' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsMetered\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $clientReturnAllow = @{ + MeteredNetworkUsage = 1 + } + + $clientReturnLimit = @{ + MeteredNetworkUsage = 2 + } + + $clientReturnBlock = @{ + MeteredNetworkUsage = 4 + } + + $getInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + } + + $clientType = @{ + Type = 1 + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When retrieving Client Policy Settings for Metered settings' { + + It 'Should return desired results when client settings exist and allowed' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnAllow } -ParameterFilter { $Setting -eq 'MeteredNetwork' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.MeteredNetworkUsage | Should -Be -ExpectedValue 'Allow' + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + + It 'Should return desired results when client settings exist and limited' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnLimit } -ParameterFilter { $Setting -eq 'MeteredNetwork' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.MeteredNetworkUsage | Should -Be -ExpectedValue 'Limit' + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + + It 'Should return desired results when client settings exist and blocked' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnBlock } -ParameterFilter { $Setting -eq 'MeteredNetwork' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.MeteredNetworkUsage | Should -Be -ExpectedValue 'Block' + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + + It 'Should return desired result when client setting policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.MeteredNetworkUsage | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Absent' + $result.ClientType | Should -Be -ExpectedValue $null + } + + It 'Should return desired result when client setting policy exist but metered settings is not configured' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $null } -ParameterFilter { $Setting -eq 'MeteredNetwork' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.MeteredNetworkUsage | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsMetered\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + MeteredNetworkUsage = 'Allow' + } + + Mock -CommandName Set-CMClientSettingMeteredInternetConnection + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + MeteredNetworkUsage = 'Allow' + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnPresentDefaultClient = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + MeteredNetworkUsage = 'Block' + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + MeteredNetworkUsage = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $inputMeteredLimited = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + MeteredNetworkUsage = 'Limit' + } + + $inputMeteredDefaultClient = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + MeteredNetworkUsage = 'Limit' + } + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingMeteredInternetConnection -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingMeteredInternetConnection -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when limiting metered' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputMeteredLimited + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingMeteredInternetConnection -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when changing metered settings for default client settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefaultClient } + + Set-TargetResource @inputMeteredDefaultClient + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingMeteredInternetConnection -Exactly -Times 1 -Scope It + } + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + MeteredNetworkUsage = $null + ClientSettingStatus = 'Absent' + } + + $absentMsg = 'Client Policy setting ClientTest does not exist, and will need to be created prior to making client setting changes.' + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + MeteredNetworkUsage = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $wrongClientType = 'Client Settings for Metered Connections only applies to Default and Device Client settings.' + } + + It 'Should throw and call expected commands when setting command when disabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $absentMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingMeteredInternetConnection -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when Client Policy Settings are user targeted' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $wrongClientType + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingMeteredInternetConnection -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsMetered\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + MeteredNetworkUsage = 'Allow' + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + MeteredNetworkUsage = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + MeteredNetworkUsage = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + MeteredNetworkUsage = 'Allow' + } + + $inputBlocked = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + MeteredNetworkUsage = 'Block' + } + + $inputLimit = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + MeteredNetworkUsage = 'Limit' + } + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + MeteredNetworkUsage = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when client policy exists but does not set metered connection settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when setting metered connection to blocked' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputBlocked | Should -Be $false + } + + It 'Should return desired result false when setting metered connection to limited' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputLimit | Should -Be $false + } + + It 'Should return desired result false when Client Policy settings are user based' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + Test-TargetResource @inputLimit | Should -Be $false + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/CMClientSettingsPower.tests.ps1 b/tests/Unit/CMClientSettingsPower.tests.ps1 new file mode 100644 index 00000000..a6fe6384 --- /dev/null +++ b/tests/Unit/CMClientSettingsPower.tests.ps1 @@ -0,0 +1,738 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettingsPower' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsPower\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $clientReturnNone = @{ + Enabled = $true + AllowUserToOptOutFromPowerPlan = $true + AllowWakeup = 1 + EnableWakeupProxy = $true + Port = 40 + WolPort = 41 + WakeupProxyFirewallFlags = 0 + WakeupProxyDirectAccessPrefixList = 'fe80::6013:b219:6a1b:4767' + } + + $clientReturnPublic = @{ + Enabled = $true + AllowUserToOptOutFromPowerPlan = $true + AllowWakeup = 0 + EnableWakeupProxy = $true + Port = 40 + WolPort = 41 + WakeupProxyFirewallFlags = 9 + WakeupProxyDirectAccessPrefixList = 'fe80::6013:b219:6a1b:4767' + } + + $clientReturnPrivate = @{ + Enabled = $true + AllowUserToOptOutFromPowerPlan = $true + AllowWakeup = 1 + EnableWakeupProxy = $true + Port = 40 + WolPort = 41 + WakeupProxyFirewallFlags = 10 + WakeupProxyDirectAccessPrefixList = 'fe80::6013:b219:6a1b:4767' + } + + $clientReturnPubPriv = @{ + Enabled = $true + AllowUserToOptOutFromPowerPlan = $true + AllowWakeup = 1 + EnableWakeupProxy = $true + Port = 40 + WolPort = 41 + WakeupProxyFirewallFlags = 11 + WakeupProxyDirectAccessPrefixList = 'fe80::6013:b219:6a1b:4767' + } + + $clientReturnDomain = @{ + Enabled = $true + AllowUserToOptOutFromPowerPlan = $true + AllowWakeup = 1 + EnableWakeupProxy = $true + Port = 40 + WolPort = 41 + WakeupProxyFirewallFlags = 12 + WakeupProxyDirectAccessPrefixList = 'fe80::6013:b219:6a1b:4767' + } + + $clientReturnPubDom = @{ + Enabled = $true + AllowUserToOptOutFromPowerPlan = $true + AllowWakeup = 1 + EnableWakeupProxy = $true + Port = 40 + WolPort = 41 + WakeupProxyFirewallFlags = 13 + WakeupProxyDirectAccessPrefixList = 'fe80::6013:b219:6a1b:4767' + } + + $clientReturnPrivDom = @{ + Enabled = $true + AllowUserToOptOutFromPowerPlan = $true + AllowWakeup = 1 + EnableWakeupProxy = $true + Port = 40 + WolPort = 41 + WakeupProxyFirewallFlags = 14 + WakeupProxyDirectAccessPrefixList = 'fe80::6013:b219:6a1b:4767' + } + + $clientReturnPubPrivDom = @{ + Enabled = $true + AllowUserToOptOutFromPowerPlan = $true + AllowWakeup = 1 + EnableWakeupProxy = $true + Port = 40 + WolPort = 41 + WakeupProxyFirewallFlags = 15 + WakeupProxyDirectAccessPrefixList = 'fe80::6013:b219:6a1b:4767' + } + + $clientType = @{ + Type = 1 + } + + $getInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When retrieving Client Policy Settings for Power settings' { + + It 'Should return desired results when client settings exist firewall none' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnNone } -ParameterFilter { $Setting -eq 'PowerManagement' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.Enable | Should -Be -ExpectedValue $true + $result.AllowUserToOptOutFromPowerPlan | Should -Be -ExpectedValue $true + $result.EnableWakeupProxy | Should -Be -ExpectedValue $true + $result.WakeupProxyPort | Should -Be -ExpectedValue 40 + $result.WakeOnLanPort | Should -Be -ExpectedValue 41 + $result.FirewallExceptionForWakeupProxy | Should -Be -ExpectedValue 'None' + $result.WakeupProxyDirectAccessPrefix | Should -Be -ExpectedValue @('fe80::6013:b219:6a1b:4767') + $result.NetworkWakeupOption | Should -Be -ExpectedValue 'Enabled' + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + + It 'Should return desired results when client settings exist firewall Public' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnPublic } -ParameterFilter { $Setting -eq 'PowerManagement' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.Enable | Should -Be -ExpectedValue $true + $result.AllowUserToOptOutFromPowerPlan | Should -Be -ExpectedValue $true + $result.EnableWakeupProxy | Should -Be -ExpectedValue $true + $result.WakeupProxyPort | Should -Be -ExpectedValue 40 + $result.WakeOnLanPort | Should -Be -ExpectedValue 41 + $result.FirewallExceptionForWakeupProxy | Should -Be -ExpectedValue 'Public' + $result.WakeupProxyDirectAccessPrefix | Should -Be -ExpectedValue @('fe80::6013:b219:6a1b:4767') + $result.NetworkWakeupOption | Should -Be -ExpectedValue 'NotConfigured' + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + + It 'Should return desired results when client settings exist firewall Private' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnPrivate } -ParameterFilter { $Setting -eq 'PowerManagement' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.Enable | Should -Be -ExpectedValue $true + $result.AllowUserToOptOutFromPowerPlan | Should -Be -ExpectedValue $true + $result.EnableWakeupProxy | Should -Be -ExpectedValue $true + $result.WakeupProxyPort | Should -Be -ExpectedValue 40 + $result.WakeOnLanPort | Should -Be -ExpectedValue 41 + $result.FirewallExceptionForWakeupProxy | Should -Be -ExpectedValue 'Private' + $result.WakeupProxyDirectAccessPrefix | Should -Be -ExpectedValue @('fe80::6013:b219:6a1b:4767') + $result.NetworkWakeupOption | Should -Be -ExpectedValue 'Enabled' + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + + It 'Should return desired results when client settings exist firewall Private and Public' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnPubPriv } -ParameterFilter { $Setting -eq 'PowerManagement' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.Enable | Should -Be -ExpectedValue $true + $result.AllowUserToOptOutFromPowerPlan | Should -Be -ExpectedValue $true + $result.EnableWakeupProxy | Should -Be -ExpectedValue $true + $result.WakeupProxyPort | Should -Be -ExpectedValue 40 + $result.WakeOnLanPort | Should -Be -ExpectedValue 41 + $result.FirewallExceptionForWakeupProxy | Should -Be -ExpectedValue @('Private','Public') + $result.WakeupProxyDirectAccessPrefix | Should -Be -ExpectedValue @('fe80::6013:b219:6a1b:4767') + $result.NetworkWakeupOption | Should -Be -ExpectedValue 'Enabled' + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + + It 'Should return desired results when client settings exist firewall Domain' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnDomain } -ParameterFilter { $Setting -eq 'PowerManagement' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.Enable | Should -Be -ExpectedValue $true + $result.AllowUserToOptOutFromPowerPlan | Should -Be -ExpectedValue $true + $result.EnableWakeupProxy | Should -Be -ExpectedValue $true + $result.WakeupProxyPort | Should -Be -ExpectedValue 40 + $result.WakeOnLanPort | Should -Be -ExpectedValue 41 + $result.FirewallExceptionForWakeupProxy | Should -Be -ExpectedValue 'Domain' + $result.WakeupProxyDirectAccessPrefix | Should -Be -ExpectedValue @('fe80::6013:b219:6a1b:4767') + $result.NetworkWakeupOption | Should -Be -ExpectedValue 'Enabled' + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + + It 'Should return desired results when client settings exist firewall Public and Domain' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnPubDom } -ParameterFilter { $Setting -eq 'PowerManagement' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.Enable | Should -Be -ExpectedValue $true + $result.AllowUserToOptOutFromPowerPlan | Should -Be -ExpectedValue $true + $result.EnableWakeupProxy | Should -Be -ExpectedValue $true + $result.WakeupProxyPort | Should -Be -ExpectedValue 40 + $result.WakeOnLanPort | Should -Be -ExpectedValue 41 + $result.FirewallExceptionForWakeupProxy | Should -Be -ExpectedValue @('Public','Domain') + $result.WakeupProxyDirectAccessPrefix | Should -Be -ExpectedValue @('fe80::6013:b219:6a1b:4767') + $result.NetworkWakeupOption | Should -Be -ExpectedValue 'Enabled' + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + + It 'Should return desired results when client settings exist firewall Private and Domain' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnPrivDom } -ParameterFilter { $Setting -eq 'PowerManagement' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.Enable | Should -Be -ExpectedValue $true + $result.AllowUserToOptOutFromPowerPlan | Should -Be -ExpectedValue $true + $result.EnableWakeupProxy | Should -Be -ExpectedValue $true + $result.WakeupProxyPort | Should -Be -ExpectedValue 40 + $result.WakeOnLanPort | Should -Be -ExpectedValue 41 + $result.FirewallExceptionForWakeupProxy | Should -Be -ExpectedValue @('Domain','Private') + $result.WakeupProxyDirectAccessPrefix | Should -Be -ExpectedValue @('fe80::6013:b219:6a1b:4767') + $result.NetworkWakeupOption | Should -Be -ExpectedValue 'Enabled' + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + + It 'Should return desired results when client settings exist firewall Domain, Private and Public' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnPubPrivDom } -ParameterFilter { $Setting -eq 'PowerManagement' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.Enable | Should -Be -ExpectedValue $true + $result.AllowUserToOptOutFromPowerPlan | Should -Be -ExpectedValue $true + $result.EnableWakeupProxy | Should -Be -ExpectedValue $true + $result.WakeupProxyPort | Should -Be -ExpectedValue 40 + $result.WakeOnLanPort | Should -Be -ExpectedValue 41 + $result.FirewallExceptionForWakeupProxy | Should -Be -ExpectedValue @('Domain','Private','Public') + $result.WakeupProxyDirectAccessPrefix | Should -Be -ExpectedValue @('fe80::6013:b219:6a1b:4767') + $result.NetworkWakeupOption | Should -Be -ExpectedValue 'Enabled' + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + + It 'Should return desired result when client setting policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.Enable | Should -Be -ExpectedValue $null + $result.AllowUserToOptOutFromPowerPlan | Should -Be -ExpectedValue $null + $result.EnableWakeupProxy | Should -Be -ExpectedValue $null + $result.WakeupProxyPort | Should -Be -ExpectedValue $null + $result.WakeOnLanPort | Should -Be -ExpectedValue $null + $result.FirewallExceptionForWakeupProxy | Should -Be -ExpectedValue $null + $result.WakeupProxyDirectAccessPrefix | Should -Be -ExpectedValue $null + $result.NetworkWakeupOption | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Absent' + $result.ClientType | Should -Be -ExpectedValue $null + } + + It 'Should return desired result when client setting policy exist but power management is not configured' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $null } -ParameterFilter { $Setting -eq 'PowerManagement' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.Enable | Should -Be -ExpectedValue $null + $result.AllowUserToOptOutFromPowerPlan | Should -Be -ExpectedValue $null + $result.EnableWakeupProxy | Should -Be -ExpectedValue $null + $result.WakeupProxyPort | Should -Be -ExpectedValue $null + $result.WakeOnLanPort | Should -Be -ExpectedValue $null + $result.FirewallExceptionForWakeupProxy | Should -Be -ExpectedValue $null + $result.WakeupProxyDirectAccessPrefix | Should -Be -ExpectedValue $null + $result.NetworkWakeupOption | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsPower\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + AllowUserToOptOutFromPowerPlan = $true + EnableWakeupProxy = $true + WakeupProxyPort = 41 + WakeOnLanPort = 42 + FirewallExceptionForWakeupProxy = @('Domain','Private') + WakeupProxyDirectAccessPrefix = @('fe80::6013:b219:6a1b:4768','fe80::6013:b219:6a1b:4767') + NetworkWakeupOption = 'Enabled' + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + AllowUserToOptOutFromPowerPlan = $true + EnableWakeupProxy = $true + WakeupProxyPort = 41 + WakeOnLanPort = 42 + FirewallExceptionForWakeupProxy = @('Private','Domain') + WakeupProxyDirectAccessPrefix = @('fe80::6013:b219:6a1b:4767','fe80::6013:b219:6a1b:4768') + NetworkWakeupOption = 'Enabled' + } + + Mock -CommandName Set-CMClientSettingPowerManagement + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $inputMisMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + AllowUserToOptOutFromPowerPlan = $true + EnableWakeupProxy = $true + WakeupProxyPort = 42 + WakeOnLanPort = 43 + FirewallExceptionForWakeupProxy = @('Private','Public') + WakeupProxyDirectAccessPrefix = @('fe80::6013:b219:6a1b:4767','fe80::6013:b219:6a1b:4769') + NetworkWakeupOption = 'Enabled' + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + AllowUserToOptOutFromPowerPlan = $null + EnableWakeupProxy = $null + WakeupProxyPort = $null + WakeOnLanPort = $null + FirewallExceptionForWakeupProxy = $null + WakeupProxyDirectAccessPrefix = $null + NetworkWakeupOption = $null + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingPowerManagement -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when settings mismatch' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputMisMatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingPowerManagement -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when return is not configured' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingPowerManagement -Exactly -Times 1 -Scope It + } + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ConfigureBranchCache = $null + EnableBranchCache = $null + MaxBranchCacheSizePercent = $null + ConfigureCacheSize = $null + MaxCacheSize = $null + MaxCacheSizePercent = $null + EnableSuperPeer = $null + BroadcastPort = $null + DownloadPort = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $absentMsg = 'Client Policy setting ClientTest does not exist, and will need to be created prior to making client setting changes.' + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + AllowUserToOptOutFromPowerPlan = $null + EnableWakeupProxy = $null + WakeupProxyPort = $null + WakeOnLanPort = $null + FirewallExceptionForWakeupProxy = $null + WakeupProxyDirectAccessPrefix = $null + NetworkWakeupOption = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $wrongClientType = 'Client Settings for power management only applies to Default and Device Client settings.' + + $inputNetworkWakeUp = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + NetworkWakeUpOption = 'Disabled' + WakeOnLanPort = 40 + } + + $networkWakeUpMsg = 'In order to set WakeOnLanPort you must specify NetworkWakeUpOption Enabled and also set EnableWakeUpProxy true.' + + $inputEnableWakeUpProxy = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EnableWakeUpProxy = $false + WakeupProxyPort = 41 + } + + $disableWakeUpProxyMsg = 'In order to set WakeUpProxyPort, FirewallExceptionForWakeupProxy, or WakeupProxyDirectAccessPrefix, EnableWakeUpProxy must be set to $true.' + + $inputBadFirewall = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EnableWakeUpProxy = $true + NetworkWakeUpOption = 'Enabled' + FirewallExceptionForWakeupProxy = @('None','Domain') + } + + $firewallMsg = 'When specifying FirewallExceptionForWakeupProxy and specifying None, you can not specify any other firewall exceptions.' + } + + It 'Should throw and call expected commands when client policy is absent' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $absentMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingPowerManagement -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when Client Policy Settings are user targeted' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $wrongClientType + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingPowerManagement -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when when network wake up options is disabled and specifying WakeOnLanPort' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + { Set-TargetResource @inputNetworkWakeUp } | Should -Throw -ExpectedMessage $networkWakeUpMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingPowerManagement -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when EnableWakeUpProxy is false and specifying WakeupProxyPort' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + { Set-TargetResource @inputEnableWakeUpProxy } | Should -Throw -ExpectedMessage $disableWakeUpProxyMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingPowerManagement -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when FirewallExceptionForWakeupProxy contains None and another firewall setting' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + { Set-TargetResource @inputBadFirewall } | Should -Throw -ExpectedMessage $firewallMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingPowerManagement -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsPower\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + AllowUserToOptOutFromPowerPlan = $true + EnableWakeupProxy = $true + WakeupProxyPort = 41 + WakeOnLanPort = 42 + FirewallExceptionForWakeupProxy = @('Domain','Private') + WakeupProxyDirectAccessPrefix = @('fe80::6013:b219:6a1b:4768','fe80::6013:b219:6a1b:4767') + NetworkWakeupOption = 'Enabled' + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + AllowUserToOptOutFromPowerPlan = $null + EnableWakeupProxy = $null + WakeupProxyPort = $null + WakeOnLanPort = $null + FirewallExceptionForWakeupProxy = $null + WakeupProxyDirectAccessPrefix = $null + NetworkWakeupOption = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + AllowUserToOptOutFromPowerPlan = $null + EnableWakeupProxy = $null + WakeupProxyPort = $null + WakeOnLanPort = $null + FirewallExceptionForWakeupProxy = $null + WakeupProxyDirectAccessPrefix = $null + NetworkWakeupOption = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + AllowUserToOptOutFromPowerPlan = $null + EnableWakeupProxy = $null + WakeupProxyPort = $null + WakeOnLanPort = $null + FirewallExceptionForWakeupProxy = $null + WakeupProxyDirectAccessPrefix = $null + NetworkWakeupOption = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + AllowUserToOptOutFromPowerPlan = $true + EnableWakeupProxy = $true + WakeupProxyPort = 41 + WakeOnLanPort = 42 + FirewallExceptionForWakeupProxy = @('Private','Domain') + WakeupProxyDirectAccessPrefix = @('fe80::6013:b219:6a1b:4767','fe80::6013:b219:6a1b:4768') + NetworkWakeupOption = 'Enabled' + } + + $inputMisMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + AllowUserToOptOutFromPowerPlan = $true + EnableWakeupProxy = $true + WakeupProxyPort = 42 + WakeOnLanPort = 43 + FirewallExceptionForWakeupProxy = @('Private','Domain','Public') + WakeupProxyDirectAccessPrefix = @('fe80::6013:b219:6a1b:4767','fe80::6013:b219:6a1b:4769') + NetworkWakeupOption = 'Enabled' + } + + $inputNetworkWakeUp = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + NetworkWakeUpOption = 'Disabled' + WakeOnLanPort = 40 + } + + $inputEnableWakeUpProxy = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EnableWakeUpProxy = $false + WakeupProxyPort = 41 + } + + $inputBadFirewall = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EnableWakeUpProxy = $true + NetworkWakeUpOption = 'Enabled' + FirewallExceptionForWakeupProxy = @('None','Domain') + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false when settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputMisMatch | Should -Be $false + } + + It 'Should return desired result false return is notconfigured' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when client policy settings does not exist' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + Test-TargetResource @inputMisMatch | Should -Be $false + } + + It 'Should return desired result false when client policy settings is user based' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + Test-TargetResource @inputMisMatch | Should -Be $false + } + + It 'Should return desired result false when network wake up options is disabled and specifying WakeOnLanPort' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputNetworkWakeUp | Should -Be $false + } + + It 'Should return desired result false when EnableWakeUpProxy is false and specifying WakeupProxyPort' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputEnableWakeUpProxy | Should -Be $false + } + + It 'Should return desired result false when FirewallExceptionForWakeupProxy contains None and another firewall setting' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputBadFirewall | Should -Be $false + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/CMClientSettingsRemoteTools.tests.ps1 b/tests/Unit/CMClientSettingsRemoteTools.tests.ps1 new file mode 100644 index 00000000..4e4bad65 --- /dev/null +++ b/tests/Unit/CMClientSettingsRemoteTools.tests.ps1 @@ -0,0 +1,1143 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettingsRemoteTools' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsRemoteTools\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $cimFullControl = New-Object -TypeName PSObject -Property @{ + 'SiteCode' = 'Lab' + 'ItemType' = 'Client Component' + 'FileType' = 2 + 'ItemName' = 'Remote Control' + 'Props' = @( + @{ + 'PropertyName' = 'Enable RA' + 'Value' = 1 + } + @{ + 'PropertyName' = 'Allow RA Unsolicited Control' + 'Value' = 1 + } + @{ + 'PropertyName' = 'Allow RA Unsolicited View' + 'Value' = 1 + } + ) + } + + $cimViewOnly = New-Object -TypeName PSObject -Property @{ + 'SiteCode' = 'Lab' + 'ItemType' = 'Client Component' + 'FileType' = 2 + 'ItemName' = 'Remote Control' + 'Props' = @( + @{ + PropertyName = 'Enable RA' + Value = 1 + } + @{ + PropertyName = 'Allow RA Unsolicited Control' + Value = 0 + } + @{ + PropertyName = 'Allow RA Unsolicited View' + Value = 1 + } + ) + } + + $cimNone = New-Object -TypeName PSObject -Property @{ + 'SiteCode' = 'Lab' + 'ItemType' = 'Client Component' + 'FileType' = 2 + 'ItemName' = 'Remote Control' + 'Props' = @( + @{ + PropertyName = 'Enable RA' + Value = 0 + } + @{ + PropertyName = 'Allow RA Unsolicited Control' + Value = 0 + } + @{ + PropertyName = 'Allow RA Unsolicited View' + Value = 0 + } + ) + } + + $clientReturnNone = @{ + FirewallExceptionProfiles = 0 + AllowClientChange = $true + AllowRemCtrlToUnattended = $true + PermissionRequired = $true + ClipboardAccessPermissionRequired = $true + AllowLocalAdminToDoRemoteControl = $true + AccessLevel = 2 + PermittedViewers = @('RemoteGroup1','RemoteGroup2') + RemCtrlTaskbarIcon = $true + RemCtrlConnectionBar = $true + AudibleSignal = 1 + ManageRA = $true + EnforceRAandTSSettings = $true + RemoteAssistanceAccessLevel = 'FullControl' + ManageTS = $true + EnableTS = $true + TSUserAuthentication = $true + } + + $clientReturnPublic = @{ + FirewallExceptionProfiles = 9 + AllowClientChange = $true + AllowRemCtrlToUnattended = $true + PermissionRequired = $true + ClipboardAccessPermissionRequired = $true + AllowLocalAdminToDoRemoteControl = $true + AccessLevel = 2 + PermittedViewers = @('RemoteGroup1','RemoteGroup2') + RemCtrlTaskbarIcon = $true + RemCtrlConnectionBar = $true + AudibleSignal = 1 + ManageRA = $true + EnforceRAandTSSettings = $true + RemoteAssistanceAccessLevel = 'FullControl' + ManageTS = $true + EnableTS = $true + TSUserAuthentication = $true + } + + $clientReturnPrivate = @{ + FirewallExceptionProfiles = 10 + AllowClientChange = $true + AllowRemCtrlToUnattended = $true + PermissionRequired = $true + ClipboardAccessPermissionRequired = $true + AllowLocalAdminToDoRemoteControl = $true + AccessLevel = 2 + PermittedViewers = @('RemoteGroup1','RemoteGroup2') + RemCtrlTaskbarIcon = $true + RemCtrlConnectionBar = $true + AudibleSignal = 1 + ManageRA = $true + EnforceRAandTSSettings = $true + RemoteAssistanceAccessLevel = 'FullControl' + ManageTS = $true + EnableTS = $true + TSUserAuthentication = $true + } + + $clientReturnPubPriv = @{ + FirewallExceptionProfiles = 11 + AllowClientChange = $true + AllowRemCtrlToUnattended = $true + PermissionRequired = $true + ClipboardAccessPermissionRequired = $true + AllowLocalAdminToDoRemoteControl = $true + AccessLevel = 2 + PermittedViewers = @('RemoteGroup1','RemoteGroup2') + RemCtrlTaskbarIcon = $true + RemCtrlConnectionBar = $true + AudibleSignal = 1 + ManageRA = $true + EnforceRAandTSSettings = $true + RemoteAssistanceAccessLevel = 'FullControl' + ManageTS = $true + EnableTS = $true + TSUserAuthentication = $true + } + + $clientReturnDomain = @{ + FirewallExceptionProfiles = 12 + AllowClientChange = $true + AllowRemCtrlToUnattended = $true + PermissionRequired = $true + ClipboardAccessPermissionRequired = $true + AllowLocalAdminToDoRemoteControl = $true + AccessLevel = 2 + PermittedViewers = @('RemoteGroup1','RemoteGroup2') + RemCtrlTaskbarIcon = $true + RemCtrlConnectionBar = $true + AudibleSignal = 1 + ManageRA = $true + EnforceRAandTSSettings = $true + RemoteAssistanceAccessLevel = 'FullControl' + ManageTS = $true + EnableTS = $true + TSUserAuthentication = $true + } + + $clientReturnPubDom = @{ + FirewallExceptionProfiles = 13 + AllowClientChange = $true + AllowRemCtrlToUnattended = $true + PermissionRequired = $true + ClipboardAccessPermissionRequired = $true + AllowLocalAdminToDoRemoteControl = $true + AccessLevel = 2 + PermittedViewers = @('RemoteGroup1','RemoteGroup2') + RemCtrlTaskbarIcon = $true + RemCtrlConnectionBar = $true + AudibleSignal = 1 + ManageRA = $true + EnforceRAandTSSettings = $true + RemoteAssistanceAccessLevel = 'FullControl' + ManageTS = $true + EnableTS = $true + TSUserAuthentication = $true + } + + $clientReturnPrivDom = @{ + FirewallExceptionProfiles = 14 + AllowClientChange = $true + AllowRemCtrlToUnattended = $true + PermissionRequired = $true + ClipboardAccessPermissionRequired = $true + AllowLocalAdminToDoRemoteControl = $true + AccessLevel = 2 + PermittedViewers = @('RemoteGroup1','RemoteGroup2') + RemCtrlTaskbarIcon = $true + RemCtrlConnectionBar = $true + AudibleSignal = 1 + ManageRA = $true + EnforceRAandTSSettings = $true + RemoteAssistanceAccessLevel = 'FullControl' + ManageTS = $true + EnableTS = $true + TSUserAuthentication = $true + } + + $clientReturnPubPrivDom = @{ + FirewallExceptionProfiles = 15 + AllowClientChange = $true + AllowRemCtrlToUnattended = $true + PermissionRequired = $true + ClipboardAccessPermissionRequired = $true + AllowLocalAdminToDoRemoteControl = $true + AccessLevel = 2 + PermittedViewers = @('RemoteGroup1','RemoteGroup2') + RemCtrlTaskbarIcon = $true + RemCtrlConnectionBar = $true + AudibleSignal = 1 + ManageRA = $true + EnforceRAandTSSettings = $true + RemoteAssistanceAccessLevel = 'FullControl' + ManageTS = $true + EnableTS = $true + TSUserAuthentication = $true + } + + $clientType = @{ + SiteCode = 'Lab' + Type = 1 + } + + $clientTypeDefault = @{ + Type = 0 + SiteCode = 'Lab' + } + + $getInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + } + + $getInputDefault = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Agent' + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When retrieving Client Policy Settings for Remote Tools' { + + It 'Should return desired results when client settings exist firewall none' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnNone } -ParameterFilter { $Setting -eq 'RemoteTools' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.FirewallExceptionProfile | Should -Be -ExpectedValue $null + $result.AllowClientChange | Should -Be -ExpectedValue $null + $result.AllowUnattendedComputer | Should -Be -ExpectedValue $null + $result.PromptUserForPermission | Should -Be -ExpectedValue $null + $result.PromptUserForClipboardPermission | Should -Be -ExpectedValue $null + $result.GrantPermissionToLocalAdministrator | Should -Be -ExpectedValue $null + $result.AccessLevel | Should -Be -ExpectedValue $null + $result.PermittedViewer | Should -Be -ExpectedValue $null + $result.ShowNotificationIconOnTaskbar | Should -Be -ExpectedValue $null + $result.ShowSessionConnectionBar | Should -Be -ExpectedValue $null + $result.AudibleSignal | Should -Be -ExpectedValue $null + $result.ManageUnsolicitedRemoteAssistance | Should -Be -ExpectedValue $null + $result.ManageSolicitedRemoteAssistance | Should -Be -ExpectedValue $null + $result.RemoteAssistanceAccessLevel | Should -Be -ExpectedValue $null + $result.ManageRemoteDesktopSetting | Should -Be -ExpectedValue $null + $result.AllowPermittedViewer | Should -Be -ExpectedValue $null + $result.RequireAuthentication | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + $result.RemoteToolsStatus | Should -Be -ExpectedValue 'Disabled' + } + + It 'Should return desired results when client settings exist firewall Public' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientTypeDefault } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnPublic } -ParameterFilter { $Setting -eq 'RemoteTools' } + Mock -CommandName Get-CimInstance -MockWith { $cimFullControl } + + $result = Get-TargetResource @getInputDefault + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Agent' + $result.FirewallExceptionProfile | Should -Be -ExpectedValue 'Public' + $result.AllowClientChange | Should -Be -ExpectedValue $true + $result.AllowUnattendedComputer | Should -Be -ExpectedValue $true + $result.PromptUserForPermission | Should -Be -ExpectedValue $true + $result.PromptUserForClipboardPermission | Should -Be -ExpectedValue $true + $result.GrantPermissionToLocalAdministrator | Should -Be -ExpectedValue $true + $result.AccessLevel | Should -Be -ExpectedValue 'FullControl' + $result.PermittedViewer | Should -Be -ExpectedValue @('RemoteGroup1','RemoteGroup2') + $result.ShowNotificationIconOnTaskbar | Should -Be -ExpectedValue $true + $result.ShowSessionConnectionBar | Should -Be -ExpectedValue $true + $result.AudibleSignal | Should -Be -ExpectedValue 'PlaySoundAtBeginAndEnd' + $result.ManageUnsolicitedRemoteAssistance | Should -Be -ExpectedValue $true + $result.ManageSolicitedRemoteAssistance | Should -Be -ExpectedValue $true + $result.RemoteAssistanceAccessLevel | Should -Be -ExpectedValue 'FullControl' + $result.ManageRemoteDesktopSetting | Should -Be -ExpectedValue $true + $result.AllowPermittedViewer | Should -Be -ExpectedValue $true + $result.RequireAuthentication | Should -Be -ExpectedValue $true + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + $result.RemoteToolsStatus | Should -Be -ExpectedValue 'Enabled' + } + + It 'Should return desired results when client settings exist firewall Private' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientTypeDefault } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnPrivate } -ParameterFilter { $Setting -eq 'RemoteTools' } + Mock -CommandName Get-CimInstance -MockWith { $cimViewOnly } + + $result = Get-TargetResource @getInputDefault + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Agent' + $result.FirewallExceptionProfile | Should -Be -ExpectedValue 'Private' + $result.AllowClientChange | Should -Be -ExpectedValue $true + $result.AllowUnattendedComputer | Should -Be -ExpectedValue $true + $result.PromptUserForPermission | Should -Be -ExpectedValue $true + $result.PromptUserForClipboardPermission | Should -Be -ExpectedValue $true + $result.GrantPermissionToLocalAdministrator | Should -Be -ExpectedValue $true + $result.AccessLevel | Should -Be -ExpectedValue 'FullControl' + $result.PermittedViewer | Should -Be -ExpectedValue @('RemoteGroup1','RemoteGroup2') + $result.ShowNotificationIconOnTaskbar | Should -Be -ExpectedValue $true + $result.ShowSessionConnectionBar | Should -Be -ExpectedValue $true + $result.AudibleSignal | Should -Be -ExpectedValue 'PlaySoundAtBeginAndEnd' + $result.ManageUnsolicitedRemoteAssistance | Should -Be -ExpectedValue $true + $result.ManageSolicitedRemoteAssistance | Should -Be -ExpectedValue $true + $result.RemoteAssistanceAccessLevel | Should -Be -ExpectedValue 'RemoteViewing' + $result.ManageRemoteDesktopSetting | Should -Be -ExpectedValue $true + $result.AllowPermittedViewer | Should -Be -ExpectedValue $true + $result.RequireAuthentication | Should -Be -ExpectedValue $true + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + $result.RemoteToolsStatus | Should -Be -ExpectedValue 'Enabled' + } + + It 'Should return desired results when client settings exist firewall Private and Public' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientTypeDefault } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnPubPriv } -ParameterFilter { $Setting -eq 'RemoteTools' } + Mock -CommandName Get-CimInstance -MockWith { $cimNone } + + $result = Get-TargetResource @getInputDefault + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Agent' + $result.FirewallExceptionProfile | Should -Be -ExpectedValue 'Private','Public' + $result.AllowClientChange | Should -Be -ExpectedValue $true + $result.AllowUnattendedComputer | Should -Be -ExpectedValue $true + $result.PromptUserForPermission | Should -Be -ExpectedValue $true + $result.PromptUserForClipboardPermission | Should -Be -ExpectedValue $true + $result.GrantPermissionToLocalAdministrator | Should -Be -ExpectedValue $true + $result.AccessLevel | Should -Be -ExpectedValue 'FullControl' + $result.PermittedViewer | Should -Be -ExpectedValue @('RemoteGroup1','RemoteGroup2') + $result.ShowNotificationIconOnTaskbar | Should -Be -ExpectedValue $true + $result.ShowSessionConnectionBar | Should -Be -ExpectedValue $true + $result.AudibleSignal | Should -Be -ExpectedValue 'PlaySoundAtBeginAndEnd' + $result.ManageUnsolicitedRemoteAssistance | Should -Be -ExpectedValue $true + $result.ManageSolicitedRemoteAssistance | Should -Be -ExpectedValue $true + $result.RemoteAssistanceAccessLevel | Should -Be -ExpectedValue 'None' + $result.ManageRemoteDesktopSetting | Should -Be -ExpectedValue $true + $result.AllowPermittedViewer | Should -Be -ExpectedValue $true + $result.RequireAuthentication | Should -Be -ExpectedValue $true + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + $result.RemoteToolsStatus | Should -Be -ExpectedValue 'Enabled' + } + + It 'Should return desired results when client settings exist firewall Domain' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnDomain } -ParameterFilter { $Setting -eq 'RemoteTools' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.FirewallExceptionProfile | Should -Be -ExpectedValue 'Domain' + $result.AllowClientChange | Should -Be -ExpectedValue $true + $result.AllowUnattendedComputer | Should -Be -ExpectedValue $true + $result.PromptUserForPermission | Should -Be -ExpectedValue $true + $result.PromptUserForClipboardPermission | Should -Be -ExpectedValue $true + $result.GrantPermissionToLocalAdministrator | Should -Be -ExpectedValue $true + $result.AccessLevel | Should -Be -ExpectedValue 'FullControl' + $result.PermittedViewer | Should -Be -ExpectedValue @('RemoteGroup1','RemoteGroup2') + $result.ShowNotificationIconOnTaskbar | Should -Be -ExpectedValue $true + $result.ShowSessionConnectionBar | Should -Be -ExpectedValue $true + $result.AudibleSignal | Should -Be -ExpectedValue 'PlaySoundAtBeginAndEnd' + $result.ManageUnsolicitedRemoteAssistance | Should -Be -ExpectedValue $true + $result.ManageSolicitedRemoteAssistance | Should -Be -ExpectedValue $true + $result.RemoteAssistanceAccessLevel | Should -Be -ExpectedValue 'FullControl' + $result.ManageRemoteDesktopSetting | Should -Be -ExpectedValue $true + $result.AllowPermittedViewer | Should -Be -ExpectedValue $true + $result.RequireAuthentication | Should -Be -ExpectedValue $true + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + $result.RemoteToolsStatus | Should -Be -ExpectedValue 'Enabled' + } + + It 'Should return desired results when client settings exist firewall Public and Domain' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnPubDom } -ParameterFilter { $Setting -eq 'RemoteTools' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.FirewallExceptionProfile | Should -Be -ExpectedValue 'Public','Domain' + $result.AllowClientChange | Should -Be -ExpectedValue $true + $result.AllowUnattendedComputer | Should -Be -ExpectedValue $true + $result.PromptUserForPermission | Should -Be -ExpectedValue $true + $result.PromptUserForClipboardPermission | Should -Be -ExpectedValue $true + $result.GrantPermissionToLocalAdministrator | Should -Be -ExpectedValue $true + $result.AccessLevel | Should -Be -ExpectedValue 'FullControl' + $result.PermittedViewer | Should -Be -ExpectedValue @('RemoteGroup1','RemoteGroup2') + $result.ShowNotificationIconOnTaskbar | Should -Be -ExpectedValue $true + $result.ShowSessionConnectionBar | Should -Be -ExpectedValue $true + $result.AudibleSignal | Should -Be -ExpectedValue 'PlaySoundAtBeginAndEnd' + $result.ManageUnsolicitedRemoteAssistance | Should -Be -ExpectedValue $true + $result.ManageSolicitedRemoteAssistance | Should -Be -ExpectedValue $true + $result.RemoteAssistanceAccessLevel | Should -Be -ExpectedValue 'FullControl' + $result.ManageRemoteDesktopSetting | Should -Be -ExpectedValue $true + $result.AllowPermittedViewer | Should -Be -ExpectedValue $true + $result.RequireAuthentication | Should -Be -ExpectedValue $true + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + $result.RemoteToolsStatus | Should -Be -ExpectedValue 'Enabled' + } + + It 'Should return desired results when client settings exist firewall Private and Domain' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnPrivDom } -ParameterFilter { $Setting -eq 'RemoteTools' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.FirewallExceptionProfile | Should -Be -ExpectedValue 'Domain','Private' + $result.AllowClientChange | Should -Be -ExpectedValue $true + $result.AllowUnattendedComputer | Should -Be -ExpectedValue $true + $result.PromptUserForPermission | Should -Be -ExpectedValue $true + $result.PromptUserForClipboardPermission | Should -Be -ExpectedValue $true + $result.GrantPermissionToLocalAdministrator | Should -Be -ExpectedValue $true + $result.AccessLevel | Should -Be -ExpectedValue 'FullControl' + $result.PermittedViewer | Should -Be -ExpectedValue @('RemoteGroup1','RemoteGroup2') + $result.ShowNotificationIconOnTaskbar | Should -Be -ExpectedValue $true + $result.ShowSessionConnectionBar | Should -Be -ExpectedValue $true + $result.AudibleSignal | Should -Be -ExpectedValue 'PlaySoundAtBeginAndEnd' + $result.ManageUnsolicitedRemoteAssistance | Should -Be -ExpectedValue $true + $result.ManageSolicitedRemoteAssistance | Should -Be -ExpectedValue $true + $result.RemoteAssistanceAccessLevel | Should -Be -ExpectedValue 'FullControl' + $result.ManageRemoteDesktopSetting | Should -Be -ExpectedValue $true + $result.AllowPermittedViewer | Should -Be -ExpectedValue $true + $result.RequireAuthentication | Should -Be -ExpectedValue $true + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + $result.RemoteToolsStatus | Should -Be -ExpectedValue 'Enabled' + } + + It 'Should return desired results when client settings exist firewall Domain, Private and Public' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnPubPrivDom } -ParameterFilter { $Setting -eq 'RemoteTools' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.FirewallExceptionProfile | Should -Be -ExpectedValue 'Domain','Private','Public' + $result.AllowClientChange | Should -Be -ExpectedValue $true + $result.AllowUnattendedComputer | Should -Be -ExpectedValue $true + $result.PromptUserForPermission | Should -Be -ExpectedValue $true + $result.PromptUserForClipboardPermission | Should -Be -ExpectedValue $true + $result.GrantPermissionToLocalAdministrator | Should -Be -ExpectedValue $true + $result.AccessLevel | Should -Be -ExpectedValue 'FullControl' + $result.PermittedViewer | Should -Be -ExpectedValue @('RemoteGroup1','RemoteGroup2') + $result.ShowNotificationIconOnTaskbar | Should -Be -ExpectedValue $true + $result.ShowSessionConnectionBar | Should -Be -ExpectedValue $true + $result.AudibleSignal | Should -Be -ExpectedValue 'PlaySoundAtBeginAndEnd' + $result.ManageUnsolicitedRemoteAssistance | Should -Be -ExpectedValue $true + $result.ManageSolicitedRemoteAssistance | Should -Be -ExpectedValue $true + $result.RemoteAssistanceAccessLevel | Should -Be -ExpectedValue 'FullControl' + $result.ManageRemoteDesktopSetting | Should -Be -ExpectedValue $true + $result.AllowPermittedViewer | Should -Be -ExpectedValue $true + $result.RequireAuthentication | Should -Be -ExpectedValue $true + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + $result.RemoteToolsStatus | Should -Be -ExpectedValue 'Enabled' + } + + It 'Should return desired result when client setting policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.FirewallExceptionProfile | Should -Be -ExpectedValue $null + $result.AllowClientChange | Should -Be -ExpectedValue $null + $result.AllowUnattendedComputer | Should -Be -ExpectedValue $null + $result.PromptUserForPermission | Should -Be -ExpectedValue $null + $result.PromptUserForClipboardPermission | Should -Be -ExpectedValue $null + $result.GrantPermissionToLocalAdministrator | Should -Be -ExpectedValue $null + $result.AccessLevel | Should -Be -ExpectedValue $null + $result.PermittedViewer | Should -Be -ExpectedValue $null + $result.ShowNotificationIconOnTaskbar | Should -Be -ExpectedValue $null + $result.ShowSessionConnectionBar | Should -Be -ExpectedValue $null + $result.AudibleSignal | Should -Be -ExpectedValue $null + $result.ManageUnsolicitedRemoteAssistance | Should -Be -ExpectedValue $null + $result.ManageSolicitedRemoteAssistance | Should -Be -ExpectedValue $null + $result.RemoteAssistanceAccessLevel | Should -Be -ExpectedValue $null + $result.ManageRemoteDesktopSetting | Should -Be -ExpectedValue $null + $result.AllowPermittedViewer | Should -Be -ExpectedValue $null + $result.RequireAuthentication | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Absent' + $result.ClientType | Should -Be -ExpectedValue $null + $result.RemoteToolsStatus | Should -Be -ExpectedValue $null + } + + It 'Should return desired result when client setting policy exist but remote tools is not configured' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $null } -ParameterFilter { $Setting -eq 'RemoteTools' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.FirewallExceptionProfile | Should -Be -ExpectedValue $null + $result.AllowClientChange | Should -Be -ExpectedValue $null + $result.AllowUnattendedComputer | Should -Be -ExpectedValue $null + $result.PromptUserForPermission | Should -Be -ExpectedValue $null + $result.PromptUserForClipboardPermission | Should -Be -ExpectedValue $null + $result.GrantPermissionToLocalAdministrator | Should -Be -ExpectedValue $null + $result.AccessLevel | Should -Be -ExpectedValue $null + $result.PermittedViewer | Should -Be -ExpectedValue $null + $result.ShowNotificationIconOnTaskbar | Should -Be -ExpectedValue $null + $result.ShowSessionConnectionBar | Should -Be -ExpectedValue $null + $result.AudibleSignal | Should -Be -ExpectedValue $null + $result.ManageUnsolicitedRemoteAssistance | Should -Be -ExpectedValue $null + $result.ManageSolicitedRemoteAssistance | Should -Be -ExpectedValue $null + $result.RemoteAssistanceAccessLevel | Should -Be -ExpectedValue $null + $result.ManageRemoteDesktopSetting | Should -Be -ExpectedValue $null + $result.AllowPermittedViewer | Should -Be -ExpectedValue $null + $result.RequireAuthentication | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + $result.RemoteToolsStatus | Should -Be -ExpectedValue $null + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsRemoteTools\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + FirewallExceptionProfile = @('Domain') + AllowClientChange = $true + AllowUnattendedComputer = $true + PromptUserForPermission = $true + PromptUserForClipboardPermission = $true + GrantPermissionToLocalAdministrator = $true + AccessLevel = 'FullControl' + PermittedViewer = @('RemoteGroup1','RemoteGroup2') + ShowNotificationIconOnTaskbar = $true + ShowSessionConnectionBar = $true + AudibleSignal = 'PlaySoundAtBeginAndEnd' + ManageUnsolicitedRemoteAssistance = $true + ManageSolicitedRemoteAssistance = $true + RemoteAssistanceAccessLevel = 'FullControl' + ManageRemoteDesktopSetting = $true + AllowPermittedViewer = $true + RequireAuthentication = $true + ClientSettingStatus = 'Present' + ClientType = 'Device' + RemoteToolsStatus = 'Enabled' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + FirewallExceptionProfile = @('Domain') + AllowClientChange = $true + AllowUnattendedComputer = $true + PromptUserForPermission = $true + PromptUserForClipboardPermission = $true + GrantPermissionToLocalAdministrator = $true + AccessLevel = 'FullControl' + PermittedViewer = @('RemoteGroup1','RemoteGroup2') + ShowNotificationIconOnTaskbar = $true + ShowSessionConnectionBar = $true + AudibleSignal = 'PlaySoundAtBeginAndEnd' + ManageUnsolicitedRemoteAssistance = $true + ManageSolicitedRemoteAssistance = $true + RemoteAssistanceAccessLevel = 'FullControl' + ManageRemoteDesktopSetting = $true + AllowPermittedViewer = $true + RequireAuthentication = $true + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + FirewallExceptionProfile = $null + AllowClientChange = $null + AllowUnattendedComputer = $null + PromptUserForPermission = $null + PromptUserForClipboardPermission = $null + GrantPermissionToLocalAdministrator = $null + AccessLevel = $null + PermittedViewer = $null + ShowNotificationIconOnTaskbar = $null + ShowSessionConnectionBar = $null + AudibleSignal = $null + ManageUnsolicitedRemoteAssistance = $null + ManageSolicitedRemoteAssistance = $null + RemoteAssistanceAccessLevel = $null + ManageRemoteDesktopSetting = $null + AllowPermittedViewer = $null + RequireAuthentication = $null + ClientSettingStatus = 'Present' + ClientType = 'Default' + RemoteToolsStatus = $null + } + + Mock -CommandName Set-CMClientSettingRemoteTool + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $inputMisMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + FirewallExceptionProfile = @('Domain','Public') + AllowClientChange = $false + AllowUnattendedComputer = $false + PromptUserForPermission = $false + PromptUserForClipboardPermission = $true + GrantPermissionToLocalAdministrator = $true + AccessLevel = 'FullControl' + PermittedViewer = @('RemoteGroup3','RemoteGroup4') + ShowNotificationIconOnTaskbar = $true + ShowSessionConnectionBar = $true + AudibleSignal = 'PlaySoundAtBeginAndEnd' + ManageUnsolicitedRemoteAssistance = $true + ManageSolicitedRemoteAssistance = $true + RemoteAssistanceAccessLevel = 'FullControl' + ManageRemoteDesktopSetting = $false + AllowPermittedViewer = $true + } + + $inputFirewallMisMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + FirewallExceptionProfile = @('Public') + } + + $inputRequireAuth = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + FirewallExceptionProfile = 'Domain','Public' + ManageRemoteDesktopSetting = $true + AllowPermittedViewer = $false + RequireAuthentication = $true + } + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingRemoteTool -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when settings mismatch' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputMisMatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingRemoteTool -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when firewall settings mismatch' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputFirewallMisMatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingRemoteTool -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when return is not configured' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingRemoteTool -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when setting AllowPrermitted user to false and specifying RequireAuth' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputRequireAuth + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingRemoteTool -Exactly -Times 1 -Scope It + } + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + FirewallExceptionProfile = $null + AllowClientChange = $null + AllowUnattendedComputer = $null + PromptUserForPermission = $null + PromptUserForClipboardPermission = $null + GrantPermissionToLocalAdministrator = $null + AccessLevel = $null + PermittedViewer = $null + ShowNotificationIconOnTaskbar = $null + ShowSessionConnectionBar = $null + AudibleSignal = $null + ManageUnsolicitedRemoteAssistance = $null + ManageSolicitedRemoteAssistance = $null + RemoteAssistanceAccessLevel = $null + ManageRemoteDesktopSetting = $null + AllowPermittedViewer = $null + RequireAuthentication = $null + ClientSettingStatus = 'Absent' + ClientType = $null + RemoteToolsStatus = $null + } + + $absentMsg = 'Client Policy setting ClientTest does not exist, and will need to be created prior to making client setting changes.' + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + FirewallExceptionProfile = $null + AllowClientChange = $null + AllowUnattendedComputer = $null + PromptUserForPermission = $null + PromptUserForClipboardPermission = $null + GrantPermissionToLocalAdministrator = $null + AccessLevel = $null + PermittedViewer = $null + ShowNotificationIconOnTaskbar = $null + ShowSessionConnectionBar = $null + AudibleSignal = $null + ManageUnsolicitedRemoteAssistance = $null + ManageSolicitedRemoteAssistance = $null + RemoteAssistanceAccessLevel = $null + ManageRemoteDesktopSetting = $null + AllowPermittedViewer = $null + RequireAuthentication = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + RemoteToolsStatus = $null + } + + $wrongClientType = 'Client Settings for remote tools only applies to Default and Device Client settings.' + + $returnDisabled = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + FirewallExceptionProfile = $null + AllowClientChange = $null + AllowUnattendedComputer = $null + PromptUserForPermission = $null + PromptUserForClipboardPermission = $null + GrantPermissionToLocalAdministrator = $null + AccessLevel = $null + PermittedViewer = $null + ShowNotificationIconOnTaskbar = $null + ShowSessionConnectionBar = $null + AudibleSignal = $null + ManageUnsolicitedRemoteAssistance = $null + ManageSolicitedRemoteAssistance = $null + RemoteAssistanceAccessLevel = $null + ManageRemoteDesktopSetting = $null + AllowPermittedViewer = $null + RequireAuthentication = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + RemoteToolsStatus = 'Disabled' + } + + $remoteToolsDisabled = 'Remote tools is currenly disabled and must be enabled to set settings for Remote Tools.' + + $inputNotConfiguredMissingFirewall = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ManageRemoteDesktopSetting = $true + } + + $missingFireWall = 'ClientSettingName: ClientTest, is currently not configured. FirewallExceptionProfile must be specified to configure additional settings.' + + } + + It 'Should throw and call expected commands when client policy is absent' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $absentMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingRemoteTool -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when Client Policy Settings are user targeted' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $wrongClientType + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingRemoteTool -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when Remote tools policy is disabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnDisabled } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $remoteToolsDisabled + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingRemoteTool -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when client setting is not configured and not specifying FirewallExceptionProfile' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + { Set-TargetResource @inputNotConfiguredMissingFirewall } | Should -Throw -ExpectedMessage $missingFireWall + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingRemoteTool -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsRemoteTools\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + FirewallExceptionProfile = @('Domain') + AllowClientChange = $true + AllowUnattendedComputer = $true + PromptUserForPermission = $true + PromptUserForClipboardPermission = $true + GrantPermissionToLocalAdministrator = $true + AccessLevel = 'FullControl' + PermittedViewer = @('RemoteGroup1','RemoteGroup2') + ShowNotificationIconOnTaskbar = $true + ShowSessionConnectionBar = $true + AudibleSignal = 'PlaySoundAtBeginAndEnd' + ManageUnsolicitedRemoteAssistance = $true + ManageSolicitedRemoteAssistance = $true + RemoteAssistanceAccessLevel = 'FullControl' + ManageRemoteDesktopSetting = $true + AllowPermittedViewer = $true + RequireAuthentication = $true + ClientSettingStatus = 'Present' + ClientType = 'Device' + RemoteToolsStatus = 'Enabled' + } + + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + FirewallExceptionProfile = $null + AllowClientChange = $null + AllowUnattendedComputer = $null + PromptUserForPermission = $null + PromptUserForClipboardPermission = $null + GrantPermissionToLocalAdministrator = $null + AccessLevel = $null + PermittedViewer = $null + ShowNotificationIconOnTaskbar = $null + ShowSessionConnectionBar = $null + AudibleSignal = $null + ManageUnsolicitedRemoteAssistance = $null + ManageSolicitedRemoteAssistance = $null + RemoteAssistanceAccessLevel = $null + ManageRemoteDesktopSetting = $null + AllowPermittedViewer = $null + RequireAuthentication = $null + ClientSettingStatus = 'Absent' + ClientType = $null + RemoteToolsStatus = $null + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + FirewallExceptionProfile = $null + AllowClientChange = $null + AllowUnattendedComputer = $null + PromptUserForPermission = $null + PromptUserForClipboardPermission = $null + GrantPermissionToLocalAdministrator = $null + AccessLevel = $null + PermittedViewer = $null + ShowNotificationIconOnTaskbar = $null + ShowSessionConnectionBar = $null + AudibleSignal = $null + ManageUnsolicitedRemoteAssistance = $null + ManageSolicitedRemoteAssistance = $null + RemoteAssistanceAccessLevel = $null + ManageRemoteDesktopSetting = $null + AllowPermittedViewer = $null + RequireAuthentication = $null + ClientSettingStatus = 'Present' + ClientType = 'Default' + RemoteToolsStatus = $null + } + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + FirewallExceptionProfile = $null + AllowClientChange = $null + AllowUnattendedComputer = $null + PromptUserForPermission = $null + PromptUserForClipboardPermission = $null + GrantPermissionToLocalAdministrator = $null + AccessLevel = $null + PermittedViewer = $null + ShowNotificationIconOnTaskbar = $null + ShowSessionConnectionBar = $null + AudibleSignal = $null + ManageUnsolicitedRemoteAssistance = $null + ManageSolicitedRemoteAssistance = $null + RemoteAssistanceAccessLevel = $null + ManageRemoteDesktopSetting = $null + AllowPermittedViewer = $null + RequireAuthentication = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + RemoteToolsStatus = $null + } + + $returnDisabled = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + FirewallExceptionProfile = $null + AllowClientChange = $null + AllowUnattendedComputer = $null + PromptUserForPermission = $null + PromptUserForClipboardPermission = $null + GrantPermissionToLocalAdministrator = $null + AccessLevel = $null + PermittedViewer = $null + ShowNotificationIconOnTaskbar = $null + ShowSessionConnectionBar = $null + AudibleSignal = $null + ManageUnsolicitedRemoteAssistance = $null + ManageSolicitedRemoteAssistance = $null + RemoteAssistanceAccessLevel = $null + ManageRemoteDesktopSetting = $null + AllowPermittedViewer = $null + RequireAuthentication = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + RemoteToolsStatus = 'Disabled' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + FirewallExceptionProfile = 'Domain' + AllowClientChange = $true + AllowUnattendedComputer = $true + PromptUserForPermission = $true + PromptUserForClipboardPermission = $true + GrantPermissionToLocalAdministrator = $true + AccessLevel = 'FullControl' + PermittedViewer = @('RemoteGroup1','RemoteGroup2') + ShowNotificationIconOnTaskbar = $true + ShowSessionConnectionBar = $true + AudibleSignal = 'PlaySoundAtBeginAndEnd' + ManageUnsolicitedRemoteAssistance = $true + ManageSolicitedRemoteAssistance = $true + RemoteAssistanceAccessLevel = 'FullControl' + ManageRemoteDesktopSetting = $true + } + + $inputMisMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + FirewallExceptionProfile = 'Domain','Public' + AllowClientChange = $false + AllowUnattendedComputer = $false + PromptUserForPermission = $false + PromptUserForClipboardPermission = $true + GrantPermissionToLocalAdministrator = $true + AccessLevel = 'FullControl' + PermittedViewer = @('RemoteGroup3','RemoteGroup4') + ShowNotificationIconOnTaskbar = $true + ShowSessionConnectionBar = $true + AudibleSignal = 'PlaySoundAtBeginAndEnd' + ManageUnsolicitedRemoteAssistance = $true + ManageSolicitedRemoteAssistance = $true + RemoteAssistanceAccessLevel = 'FullControl' + ManageRemoteDesktopSetting = $false + AllowPermittedViewer = $true + } + + $inputRequireAuth = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + FirewallExceptionProfile = 'Domain','Public' + ManageRemoteDesktopSetting = $true + AllowPermittedViewer = $false + RequireAuthentication = $true + } + + $inputNotConfiguredMissingFirewall = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ManageRemoteDesktopSetting = $true + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false when settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputMisMatch | Should -Be $false + } + + It 'Should return desired result false return is notconfigured' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when client policy settings does not exist' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + Test-TargetResource @inputMisMatch | Should -Be $false + } + + It 'Should return desired result false when client policy settings is user based' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + Test-TargetResource @inputMisMatch | Should -Be $false + } + + It 'Should return desired result false when remote tools is disabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnDisabled } + + Test-TargetResource @inputMisMatch | Should -Be $false + } + + It 'Should return desired result false and warn when setting AllowPrermitted user to false and specifying RequireAuth' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputRequireAuth | Should -Be $false + } + + It 'Should return desired result false and warn client setting is not configured and not specifying FirewallExceptionProfile' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Test-TargetResource @inputNotConfiguredMissingFirewall | Should -Be $false + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/CMClientSettingsSoftwareCenter.tests.ps1 b/tests/Unit/CMClientSettingsSoftwareCenter.tests.ps1 new file mode 100644 index 00000000..9c23185f --- /dev/null +++ b/tests/Unit/CMClientSettingsSoftwareCenter.tests.ps1 @@ -0,0 +1,778 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettingsSoftwareCenter' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsSoftwareCenter\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $test = ' + 1.0 + + + + + + + + + + false + true + + + Test + #CB4154 + false + + false + false + + ' + + $softwareCenterReturn = @{ + SC_UserPortal = 0 + SC_Old_Branding = 1 + SettingsXml = $test + } + + $softwareCenterCustomizeReturn = @{ + SC_UserPortal = 0 + SC_Old_Branding = 0 + SettingsXml = $null + } + + $companyPortalReturn = @{ + SC_UserPortal = 1 + SC_Old_Branding = 0 + SettingsXml = $null + } + + $clientType = @{ + Type = 1 + } + + $getInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $true + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When retrieving Client Policy Settings for Client Cache' { + + It 'Should return desired results when client settings and software center customization exists' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $softwareCenterReturn } -ParameterFilter { $Setting -eq 'SoftwareCenter' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.EnableCustomize | Should -Be -ExpectedValue $true + $result.CompanyName | Should -Be -ExpectedValue 'Test' + $result.ColorScheme | Should -Be -ExpectedValue '#CB4154' + $result.HideApplicationCatalogLink | Should -Be -ExpectedValue $false + $result.HideInstalledApplication | Should -Be -ExpectedValue $true + $result.HideUnapprovedApplication | Should -Be -ExpectedValue $false + $result.EnableApplicationsTab | Should -Be -ExpectedValue $true + $result.EnableUpdatesTab | Should -Be -ExpectedValue $true + $result.EnableOperatingSystemsTab | Should -Be -ExpectedValue $true + $result.EnableStatusTab | Should -Be -ExpectedValue $true + $result.EnableComplianceTab | Should -Be -ExpectedValue $true + $result.EnableOptionsTab | Should -Be -ExpectedValue $true + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + $result.PortalType | Should -Be -ExpectedValue 'Software Center' + } + + It 'Should return desired results when client settings and software center customization is not set' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $softwareCenterCustomizeReturn } -ParameterFilter { $Setting -eq 'SoftwareCenter' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.EnableCustomize | Should -Be -ExpectedValue $false + $result.CompanyName | Should -Be -ExpectedValue $null + $result.ColorScheme | Should -Be -ExpectedValue $null + $result.HideApplicationCatalogLink | Should -Be -ExpectedValue $null + $result.HideInstalledApplication | Should -Be -ExpectedValue $null + $result.HideUnapprovedApplication | Should -Be -ExpectedValue $null + $result.EnableApplicationsTab | Should -Be -ExpectedValue $null + $result.EnableUpdatesTab | Should -Be -ExpectedValue $null + $result.EnableOperatingSystemsTab | Should -Be -ExpectedValue $null + $result.EnableStatusTab | Should -Be -ExpectedValue $null + $result.EnableComplianceTab | Should -Be -ExpectedValue $null + $result.EnableOptionsTab | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + $result.PortalType | Should -Be -ExpectedValue 'Software Center' + } + + It 'Should return desired results when client settings and company portal is set' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $companyPortalReturn } -ParameterFilter { $Setting -eq 'SoftwareCenter' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.EnableCustomize | Should -Be -ExpectedValue $null + $result.CompanyName | Should -Be -ExpectedValue $null + $result.ColorScheme | Should -Be -ExpectedValue $null + $result.HideApplicationCatalogLink | Should -Be -ExpectedValue $null + $result.HideInstalledApplication | Should -Be -ExpectedValue $null + $result.HideUnapprovedApplication | Should -Be -ExpectedValue $null + $result.EnableApplicationsTab | Should -Be -ExpectedValue $null + $result.EnableUpdatesTab | Should -Be -ExpectedValue $null + $result.EnableOperatingSystemsTab | Should -Be -ExpectedValue $null + $result.EnableStatusTab | Should -Be -ExpectedValue $null + $result.EnableComplianceTab | Should -Be -ExpectedValue $null + $result.EnableOptionsTab | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + $result.PortalType | Should -Be -ExpectedValue 'Company Portal' + } + + It 'Should return desired result when client setting policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.EnableCustomize | Should -Be -ExpectedValue $null + $result.CompanyName | Should -Be -ExpectedValue $null + $result.ColorScheme | Should -Be -ExpectedValue $null + $result.HideApplicationCatalogLink | Should -Be -ExpectedValue $null + $result.HideInstalledApplication | Should -Be -ExpectedValue $null + $result.HideUnapprovedApplication | Should -Be -ExpectedValue $null + $result.EnableApplicationsTab | Should -Be -ExpectedValue $null + $result.EnableUpdatesTab | Should -Be -ExpectedValue $null + $result.EnableOperatingSystemsTab | Should -Be -ExpectedValue $null + $result.EnableStatusTab | Should -Be -ExpectedValue $null + $result.EnableComplianceTab | Should -Be -ExpectedValue $null + $result.EnableOptionsTab | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Absent' + $result.ClientType | Should -Be -ExpectedValue $null + $result.PortalType | Should -Be -ExpectedValue $null + } + + It 'Should return desired result when client setting policy exist but software center is not configured' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientType } + Mock -CommandName Get-CMClientSetting -MockWith { $null } -ParameterFilter { $Setting -eq 'SoftwareCenter' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.EnableCustomize | Should -Be -ExpectedValue $null + $result.CompanyName | Should -Be -ExpectedValue $null + $result.ColorScheme | Should -Be -ExpectedValue $null + $result.HideApplicationCatalogLink | Should -Be -ExpectedValue $null + $result.HideInstalledApplication | Should -Be -ExpectedValue $null + $result.HideUnapprovedApplication | Should -Be -ExpectedValue $null + $result.EnableApplicationsTab | Should -Be -ExpectedValue $null + $result.EnableUpdatesTab | Should -Be -ExpectedValue $null + $result.EnableOperatingSystemsTab | Should -Be -ExpectedValue $null + $result.EnableStatusTab | Should -Be -ExpectedValue $null + $result.EnableComplianceTab | Should -Be -ExpectedValue $null + $result.EnableOptionsTab | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsSoftwareCenter\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $true + CompanyName = 'Test' + ColorScheme = '#CB4154' + HideApplicationCatalogLink = $false + HideInstalledApplication = $true + HideUnapprovedApplication = $false + EnableApplicationsTab = $true + EnableUpdatesTab = $true + EnableOperatingSystemsTab = $true + EnableStatusTab = $true + EnableComplianceTab = $true + EnableOptionsTab = $true + ClientSettingStatus = 'Present' + ClientType = 'Device' + PortalType = 'Software Center' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $true + CompanyName = 'Test' + ColorScheme = '#CB4154' + HideApplicationCatalogLink = $false + HideInstalledApplication = $true + HideUnapprovedApplication = $false + EnableApplicationsTab = $true + EnableUpdatesTab = $true + EnableOperatingSystemsTab = $true + EnableStatusTab = $true + EnableComplianceTab = $true + EnableOptionsTab = $true + } + + $inputTabsDisabled = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $true + EnableApplicationsTab = $false + EnableUpdatesTab = $false + EnableOperatingSystemsTab = $false + EnableStatusTab = $false + EnableOptionsTab = $false + } + + Mock -CommandName Set-CMClientSettingSoftwareCenter + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $null + CompanyName = $null + ColorScheme = $null + HideApplicationCatalogLink = $null + HideInstalledApplication = $null + HideUnapprovedApplication = $null + EnableApplicationsTab = $null + EnableUpdatesTab = $null + EnableOperatingSystemsTab = $null + EnableStatusTab = $null + EnableComplianceTab = $null + EnableOptionsTab = $null + ClientSettingStatus = 'Present' + ClientType = 'Default' + PortalType = 'Software Center' + } + + $inputMisMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $true + CompanyName = 'Test' + ColorScheme = '#CB4155' + HideApplicationCatalogLink = $true + HideInstalledApplication = $false + HideUnapprovedApplication = $true + EnableApplicationsTab = $true + EnableUpdatesTab = $true + EnableOperatingSystemsTab = $true + EnableStatusTab = $true + EnableComplianceTab = $true + EnableOptionsTab = $true + } + + $inputCustomizeDisabled = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $false + EnableOptionsTab = $true + } + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareCenter -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when settings mismatch' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputMisMatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareCenter -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when settings tabs mismatch' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputTabsDisabled + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareCenter -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when return is not configured' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareCenter -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when expected EnableCustomize to be disabled and currently enabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputCustomizeDisabled + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareCenter -Exactly -Times 1 -Scope It + } + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $null + CompanyName = $null + ColorScheme = $null + HideApplicationCatalogLink = $null + HideInstalledApplication = $null + HideUnapprovedApplication = $null + EnableApplicationsTab = $null + EnableUpdatesTab = $null + EnableOperatingSystemsTab = $null + EnableStatusTab = $null + EnableComplianceTab = $null + EnableOptionsTab = $null + ClientSettingStatus = 'Absent' + ClientType = $null + PortalType = $null + } + + $absentMsg = 'Client Policy setting ClientTest does not exist, and will need to be created prior to making client setting changes.' + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $null + CompanyName = $null + ColorScheme = $null + HideApplicationCatalogLink = $null + HideInstalledApplication = $null + HideUnapprovedApplication = $null + EnableApplicationsTab = $null + EnableUpdatesTab = $null + EnableOperatingSystemsTab = $null + EnableStatusTab = $null + EnableComplianceTab = $null + EnableOptionsTab = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + PortalType = $null + } + + $wrongClientType = 'Client Settings for Software Center only applies to default and device client settings.' + + $returnCompanyPortal = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $null + CompanyName = $null + ColorScheme = $null + HideApplicationCatalogLink = $null + HideInstalledApplication = $null + HideUnapprovedApplication = $null + EnableApplicationsTab = $null + EnableUpdatesTab = $null + EnableOperatingSystemsTab = $null + EnableStatusTab = $null + EnableComplianceTab = $null + EnableOptionsTab = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + PortalType = 'Company Portal' + } + + $portalErrorMsg = 'Software Center is currently set to use Company Portal in order to modify these settings, you must manually set client policy to Software Center.' + + $inputBadColorScheme = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $true + ColorScheme = '1#CB415Z' + } + + $colorSchemeErrorMsg = 'ColorSchema is not formated correct: 1#CB415Z, example format would be #CB4154.' + + $returnTabsMisconfigured = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $true + CompanyName = 'Test' + ColorScheme = '#CB4154' + HideApplicationCatalogLink = $false + HideInstalledApplication = $true + HideUnapprovedApplication = $false + EnableApplicationsTab = $true + EnableUpdatesTab = $true + EnableOperatingSystemsTab = $true + EnableStatusTab = $true + EnableComplianceTab = $false + EnableOptionsTab = $true + ClientSettingStatus = 'Present' + ClientType = 'Device' + PortalType = 'Software Center' + } + + $tabMsg = 'With the settings specified all Tabs will be put into a disabled state, you must have at least one tab enabled.' + } + + It 'Should throw and call expected commands when client policy is absent' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $absentMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareCenter -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when Client Policy Settings are user targeted' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $wrongClientType + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareCenter -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when software center is set to use company portal' { + Mock -CommandName Get-TargetResource -MockWith { $returnCompanyPortal } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $portalErrorMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareCenter -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when specified colorscheme is malformed' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + { Set-TargetResource @inputBadColorScheme } | Should -Throw -ExpectedMessage $colorSchemeErrorMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareCenter -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when the combination of current state and specified state all tabs are disabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnTabsMisconfigured } + + { Set-TargetResource @inputTabsDisabled } | Should -Throw -ExpectedMessage $tabMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareCenter -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsSoftwareCenter\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $true + CompanyName = 'Test' + ColorScheme = '#CB4154' + HideApplicationCatalogLink = $false + HideInstalledApplication = $true + HideUnapprovedApplication = $false + EnableApplicationsTab = $true + EnableUpdatesTab = $true + EnableOperatingSystemsTab = $true + EnableStatusTab = $true + EnableComplianceTab = $true + EnableOptionsTab = $true + ClientSettingStatus = 'Present' + ClientType = 'Device' + PortalType = 'Software Center' + } + + $returnTabsMisconfigured = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $true + CompanyName = 'Test' + ColorScheme = '#CB4154' + HideApplicationCatalogLink = $false + HideInstalledApplication = $true + HideUnapprovedApplication = $false + EnableApplicationsTab = $true + EnableUpdatesTab = $true + EnableOperatingSystemsTab = $true + EnableStatusTab = $true + EnableComplianceTab = $false + EnableOptionsTab = $true + ClientSettingStatus = 'Present' + ClientType = 'Device' + PortalType = 'Software Center' + } + + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $null + CompanyName = $null + ColorScheme = $null + HideApplicationCatalogLink = $null + HideInstalledApplication = $null + HideUnapprovedApplication = $null + EnableApplicationsTab = $null + EnableUpdatesTab = $null + EnableOperatingSystemsTab = $null + EnableStatusTab = $null + EnableComplianceTab = $null + EnableOptionsTab = $null + ClientSettingStatus = 'Absent' + ClientType = $null + PortalType = $null + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $null + CompanyName = $null + ColorScheme = $null + HideApplicationCatalogLink = $null + HideInstalledApplication = $null + HideUnapprovedApplication = $null + EnableApplicationsTab = $null + EnableUpdatesTab = $null + EnableOperatingSystemsTab = $null + EnableStatusTab = $null + EnableComplianceTab = $null + EnableOptionsTab = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + PortalType = 'Software Center' + } + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $null + CompanyName = $null + ColorScheme = $null + HideApplicationCatalogLink = $null + HideInstalledApplication = $null + HideUnapprovedApplication = $null + EnableApplicationsTab = $null + EnableUpdatesTab = $null + EnableOperatingSystemsTab = $null + EnableStatusTab = $null + EnableComplianceTab = $null + EnableOptionsTab = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + PortalType = $null + } + + $returnCompanyPortal = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $null + CompanyName = $null + ColorScheme = $null + HideApplicationCatalogLink = $null + HideInstalledApplication = $null + HideUnapprovedApplication = $null + EnableApplicationsTab = $null + EnableUpdatesTab = $null + EnableOperatingSystemsTab = $null + EnableStatusTab = $null + EnableComplianceTab = $null + EnableOptionsTab = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + PortalType = 'Company Portal' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $true + CompanyName = 'Test' + ColorScheme = '#CB4154' + HideApplicationCatalogLink = $false + HideInstalledApplication = $true + HideUnapprovedApplication = $false + EnableApplicationsTab = $true + EnableUpdatesTab = $true + EnableOperatingSystemsTab = $true + EnableStatusTab = $true + EnableComplianceTab = $true + EnableOptionsTab = $true + } + + $inputTabsDisabled = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $true + EnableApplicationsTab = $false + EnableUpdatesTab = $false + EnableOperatingSystemsTab = $false + EnableStatusTab = $false + EnableOptionsTab = $false + } + + $inputMisMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $true + CompanyName = 'Test' + ColorScheme = '#CB4155' + HideApplicationCatalogLink = $true + HideInstalledApplication = $false + HideUnapprovedApplication = $true + EnableApplicationsTab = $true + EnableUpdatesTab = $true + EnableOperatingSystemsTab = $true + EnableStatusTab = $true + EnableComplianceTab = $true + EnableOptionsTab = $true + } + + $inputCustomizeDisabled = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $false + EnableOptionsTab = $true + } + + $inputBadColorScheme = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + EnableCustomize = $true + ColorScheme = '1#CB415Z' + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false when settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputMisMatch | Should -Be $false + } + + It 'Should return desired result false return is notconfigured' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when client policy settings does not exist' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + Test-TargetResource @inputMisMatch | Should -Be $false + } + + It 'Should return desired result false when client policy settings is user based' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + Test-TargetResource @inputMisMatch | Should -Be $false + } + + It 'Should return desired result false when expecting EnableCustomize set to disabled and is enabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputCustomizeDisabled | Should -Be $false + } + + It 'Should return desired result false when ColorScheme is malformed' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputBadColorScheme | Should -Be $false + } + + It 'Should return desired result false when software center setting is set to use company portal' { + Mock -CommandName Get-TargetResource -MockWith { $returnCompanyPortal } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when Tabs are all set to disabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnTabsMisconfigured } + + Test-TargetResource @inputTabsDisabled | Should -Be $false + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/CMClientSettingsSoftwareDeployment.tests.ps1 b/tests/Unit/CMClientSettingsSoftwareDeployment.tests.ps1 new file mode 100644 index 00000000..88ce3a63 --- /dev/null +++ b/tests/Unit/CMClientSettingsSoftwareDeployment.tests.ps1 @@ -0,0 +1,467 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettingsSoftwareDeployment' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsSoftwareDeployment\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $clientReturn = @{ + Type = 0 + } + + $settingsReturn = @{ + EvaluationSchedule = 'DA159CC000280400' + } + + $cmScheduleReturn = @{ + MinuteDuration = $null + RecurInterval = 1 + WeekOrder = $null + HourDuration = $null + Start = '9/21/2021 16:54' + DayOfWeek = $null + ScheduleType = 'MonthlyByDay' + MonthDay = 0 + DayDuration = $null + } + + $getInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + Mock -CommandName Get-CMSchedule -MockWith { $cmScheduleReturn } + } + + Context 'When retrieving Client Policy Settings for software deployment' { + + It 'Should return desired results when client settings exist' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $settingsReturn } -ParameterFilter { $Setting -eq 'SoftwareDeployment' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Start | Should -Be -ExpectedValue '9/21/2021 16:54' + $result.ScheduleType | Should -Be -ExpectedValue 'MonthlyByDay' + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue 0 + $result.RecurInterval | Should -Be -ExpectedValue 1 + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired result when client setting policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Start | Should -Be -ExpectedValue $null + $result.ScheduleType | Should -Be -ExpectedValue $null + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue $null + $result.RecurInterval | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Absent' + $result.ClientType | Should -Be -ExpectedValue $null + } + + It 'Should return desired result when client setting policy exist but software deployment is not configured' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $null } -ParameterFilter { $Setting -eq 'SoftwareDeployment' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Start | Should -Be -ExpectedValue $null + $result.ScheduleType | Should -Be -ExpectedValue $null + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue $null + $result.RecurInterval | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsSoftwareDeployment\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $returnPresentDevice = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Start = '9/21/2021 16:54' + ScheduleType = 'MonthlyByWeek' + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + DayofMonth = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnPresentDefault = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Start = '9/21/2021 16:54' + ScheduleType = 'MonthlyByDay' + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = 0 + RecurInterval = 1 + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ScheduleType = 'MonthlyByWeek' + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + Mock -CommandName Set-CMClientSettingSoftwareDeployment + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $inputPresentMismatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ScheduleType = 'Days' + RecurInterval = 10 + } + + $cmScheduleInput = @{ + RecurCount = 1 + RecurInterval = 'Days' + } + + Mock -CommandName Set-CMSchedule -MockWith { $cmScheduleInput } + Mock -CommandName New-CMSchedule + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule -MockWith { $true } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareDeployment -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when settings do not match for device' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule -MockWith { $false } + + Set-TargetResource @inputPresentMismatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareDeployment -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when settings do not match for default' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + Mock -CommandName Test-CMSchedule -MockWith { $false } + + Set-TargetResource @inputPresentMismatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareDeployment -Exactly -Times 1 -Scope It + } + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $absentMsg = 'Client Policy setting ClientTest does not exist, and will need to be created prior to making client setting changes.' + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserTest' + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $clientTypeError = 'Client Settings for software deployment only applies to Default and Device client settings.' + + $inputInvalidSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + $scheduleError = 'In order to create a schedule you must specify ScheduleType.' + + Mock -CommandName Test-CMSchedule + Mock -CommandName Set-CMSchedule + Mock -CommandName New-CMSchedule + } + + It 'Should throw and call expected commands when client policy does not exist' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $absentMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareDeployment -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when client policy is a user policy' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $clientTypeError + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareDeployment -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when not specifying a schedule type with schedule settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + + { Set-TargetResource @inputInvalidSchedule } | Should -Throw -ExpectedMessage $scheduleError + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareDeployment -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsSoftwareDeployment\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresentDevice = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Start = '9/21/2021 16:54' + ScheduleType = 'MonthlyByWeek' + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + DayofMonth = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnPresentDefault = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Start = '9/21/2021 16:54' + ScheduleType = 'MonthlyByDay' + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = 0 + RecurInterval = 1 + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserTest' + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ScheduleType = 'MonthlyByWeek' + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + $inputPresentMismatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ScheduleType = 'Days' + RecurInterval = 10 + } + + $inputInvalidSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Test-TargetResource @inputPresentMismatch | Should -Be $false + } + + It 'Should return desired result false when client policy does not exist' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when client policy is user based' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when not specifying a schedule type' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + + Test-TargetResource @inputInvalidSchedule | Should -Be $false + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/CMClientSettingsSoftwareInventory.tests.ps1 b/tests/Unit/CMClientSettingsSoftwareInventory.tests.ps1 new file mode 100644 index 00000000..a0583b6b --- /dev/null +++ b/tests/Unit/CMClientSettingsSoftwareInventory.tests.ps1 @@ -0,0 +1,607 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettingsSoftwareInventory' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - CMClientSettingsSoftwareInventory\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $clientReturn = @{ + Type = 0 + } + + $siProductReturn = @{ + Enabled = $true + Schedule = 'DA159CC000280400' + ReportOptions = 1 + } + + $siFileReturn = @{ + Enabled = $true + Schedule = 'DA159CC000280400' + ReportOptions = 2 + } + + $siProductFileReturn = @{ + Enabled = $true + Schedule = 'DA159CC000280400' + ReportOptions = 7 + } + + $cmScheduleReturn = @{ + MinuteDuration = $null + RecurInterval = 1 + WeekOrder = $null + HourDuration = $null + Start = '9/21/2021 16:54' + DayOfWeek = $null + ScheduleType = 'MonthlyByDay' + MonthDay = 0 + DayDuration = $null + } + + $getInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + Mock -CommandName Get-CMSchedule -MockWith { $cmScheduleReturn } + } + + Context 'When retrieving Client Policy Settings for software inventory' { + + It 'Should return desired results when client settings exist and Product Only' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $siProductReturn } -ParameterFilter { $Setting -eq 'SoftwareInventory' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $true + $result.ReportOption | Should -Be -ExpectedValue 'ProductOnly' + $result.Start | Should -Be -ExpectedValue '9/21/2021 16:54' + $result.ScheduleType | Should -Be -ExpectedValue 'MonthlyByDay' + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue 0 + $result.RecurInterval | Should -Be -ExpectedValue 1 + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired results when client settings exist and Files Only' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $siFileReturn } -ParameterFilter { $Setting -eq 'SoftwareInventory' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $true + $result.ReportOption | Should -Be -ExpectedValue 'FileOnly' + $result.Start | Should -Be -ExpectedValue '9/21/2021 16:54' + $result.ScheduleType | Should -Be -ExpectedValue 'MonthlyByDay' + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue 0 + $result.RecurInterval | Should -Be -ExpectedValue 1 + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired results when client settings exist and Full detail' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $siProductFileReturn } -ParameterFilter { $Setting -eq 'SoftwareInventory' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $true + $result.ReportOption | Should -Be -ExpectedValue 'FullDetail' + $result.Start | Should -Be -ExpectedValue '9/21/2021 16:54' + $result.ScheduleType | Should -Be -ExpectedValue 'MonthlyByDay' + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue 0 + $result.RecurInterval | Should -Be -ExpectedValue 1 + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired result when client setting policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $null + $result.ReportOption | Should -Be -ExpectedValue $null + $result.Start | Should -Be -ExpectedValue $null + $result.ScheduleType | Should -Be -ExpectedValue $null + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue $null + $result.RecurInterval | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Absent' + $result.ClientType | Should -Be -ExpectedValue $null + } + + It 'Should return desired result when client setting policy exist but software inventory settings is not configured' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $null } -ParameterFilter { $Setting -eq 'SoftwareInventory' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $null + $result.ReportOption | Should -Be -ExpectedValue $null + $result.Start | Should -Be -ExpectedValue $null + $result.ScheduleType | Should -Be -ExpectedValue $null + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue $null + $result.RecurInterval | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + } + } + + Describe 'ConfigMgrCBDsc - CMClientSettingsSoftwareInventory\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $returnPresentDevice = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ReportOption = 'FullDetail' + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnPresentDefault = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + ReportOption = 'FullDetail' + Start = '9/21/2021 16:54' + ScheduleType = 'MonthlyByDay' + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = 0 + RecurInterval = 1 + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ReportOption = 'FullDetail' + } + + Mock -CommandName Set-CMClientSettingSoftwareInventory + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + EnableUserDataAndProfile = $null + Start = $null + ReportOption = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnEnabledFalse = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $false + ReportOption = $null + EnableUserDataAndProfile = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $inputPresentDisable = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $false + ReportOption = 'ProductOnly' + ScheduleType = 'Weekly' + DayOfWeek = 'Sunday' + RecurInterval = 1 + } + + $inputSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + ScheduleType = 'MonthlyByWeek' + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + $inputDeviceSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ScheduleType = 'Days' + RecurInterval = 10 + } + + $cmScheduleInput = @{ + RecurCount = 1 + RecurInterval = 'Days' + } + + Mock -CommandName Set-CMSchedule -MockWith { $cmScheduleInput } + Mock -CommandName New-CMSchedule + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareInventory -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when current state disabled and desired is enabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnEnabledFalse } + Mock -CommandName Test-CMSchedule + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareInventory -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when settings do not match and disabling' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule + + Set-TargetResource @inputPresentDisable + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareInventory -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when schedule does not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + Mock -CommandName Test-CMSchedule -MockWith { $false } + + Set-TargetResource @inputSchedule + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareInventory -Exactly -Times 1 -Scope It + } + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + ReportOption = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $absentMsg = 'Client Policy setting ClientTest does not exist, and will need to be created prior to making client setting changes.' + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserTest' + Enable = $null + ReportOption = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $clientTypeError = 'Client Settings for software inventory settings only applies to Default and Device client settings.' + + $inputInvalidSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + $scheduleError = 'In order to create a schedule you must specify ScheduleType.' + + Mock -CommandName Test-CMSchedule + Mock -CommandName Set-CMSchedule + Mock -CommandName New-CMSchedule + } + + It 'Should throw and call expected commands when client policy does not exist' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $absentMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareInventory -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when client policy is a user policy' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $clientTypeError + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareInventory -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when not specifying a schedule type with schedule settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + + { Set-TargetResource @inputInvalidSchedule } | Should -Throw -ExpectedMessage $scheduleError + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareInventory -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - CMClientSettingsSoftwareInventory\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ReportOption = 'FullDetail' + Start = '9/21/2021 16:54' + ScheduleType = 'MonthlyByDay' + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = 0 + RecurInterval = 1 + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + ReportOption = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + ReportOption = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserTest' + Enable = $null + ReportOption = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ReportOption = 'FullDetail' + } + + $inputPresentMismatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $false + ReportOption = 'ProductOnly' + } + + $inputSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ScheduleType = 'MonthlyByWeek' + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + $inputInvalidSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + $inputDeviceSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ScheduleType = 'Days' + RecurInterval = 10 + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputPresentMismatch | Should -Be $false + } + + It 'Should return desired result false when schedule does not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputSchedule | Should -Be $false + } + + It 'Should return desired result false when client policy does not exist' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when client policy is user based' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when not specifying a schedule type' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputInvalidSchedule | Should -Be $false + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/CMClientSettingsSoftwareMetering.tests.ps1 b/tests/Unit/CMClientSettingsSoftwareMetering.tests.ps1 new file mode 100644 index 00000000..0ddca88f --- /dev/null +++ b/tests/Unit/CMClientSettingsSoftwareMetering.tests.ps1 @@ -0,0 +1,553 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettingsSoftwareMetering' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - CMClientSettingsSoftwareMetering\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $clientReturn = @{ + Type = 0 + } + + $smReturn = @{ + Enabled = $true + DataCollectionSchedule = 'DA159CC000280400' + } + + $cmScheduleReturn = @{ + MinuteDuration = $null + RecurInterval = 1 + WeekOrder = $null + HourDuration = $null + Start = '9/21/2021 16:54' + DayOfWeek = $null + ScheduleType = 'MonthlyByDay' + MonthDay = 0 + DayDuration = $null + } + + $getInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + Mock -CommandName Get-CMSchedule -MockWith { $cmScheduleReturn } + } + + Context 'When retrieving Client Policy Settings for software metering' { + + It 'Should return desired results when client settings exist' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $smReturn } -ParameterFilter { $Setting -eq 'SoftwareMetering' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $true + $result.Start | Should -Be -ExpectedValue '9/21/2021 16:54' + $result.ScheduleType | Should -Be -ExpectedValue 'MonthlyByDay' + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue 0 + $result.RecurInterval | Should -Be -ExpectedValue 1 + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired result when client setting policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $null + $result.Start | Should -Be -ExpectedValue $null + $result.ScheduleType | Should -Be -ExpectedValue $null + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue $null + $result.RecurInterval | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Absent' + $result.ClientType | Should -Be -ExpectedValue $null + } + + It 'Should return desired result when client setting policy exist but software metering settings is not configured' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $null } -ParameterFilter { $Setting -eq 'SoftwareMetering' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $null + $result.Start | Should -Be -ExpectedValue $null + $result.ScheduleType | Should -Be -ExpectedValue $null + $result.DayOfWeek | Should -Be -ExpectedValue $null + $result.MonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.DayofMonth | Should -Be -ExpectedValue $null + $result.RecurInterval | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + } + } + + Describe 'ConfigMgrCBDsc - CMClientSettingsSoftwareMetering\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $returnPresentDevice = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnPresentDefault = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + Start = '9/21/2021 16:54' + ScheduleType = 'MonthlyByDay' + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = 0 + RecurInterval = 1 + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + } + + Mock -CommandName Set-CMClientSettingSoftwareMetering + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + EnableUserDataAndProfile = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnEnabledFalse = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $false + EnableUserDataAndProfile = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $inputPresentDisable = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $false + ScheduleType = 'Weekly' + DayOfWeek = 'Sunday' + RecurInterval = 1 + } + + $inputSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + ScheduleType = 'MonthlyByWeek' + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + $inputDeviceSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ScheduleType = 'Days' + RecurInterval = 10 + } + + $cmScheduleInput = @{ + RecurCount = 1 + RecurInterval = 'Days' + } + + Mock -CommandName Set-CMSchedule -MockWith { $cmScheduleInput } + Mock -CommandName New-CMSchedule + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareMetering -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when current state disabled and desired is enabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnEnabledFalse } + Mock -CommandName Test-CMSchedule + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareMetering -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when settings do not match and disabling' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule + + Set-TargetResource @inputPresentDisable + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareMetering -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when schedule does not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + Mock -CommandName Test-CMSchedule -MockWith { $false } + + Set-TargetResource @inputSchedule + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareMetering -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when trying to modify schedule on device collection and all other settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule + + Set-TargetResource @inputDeviceSchedule + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareMetering -Exactly -Times 0 -Scope It + } + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $absentMsg = 'Client Policy setting ClientTest does not exist, and will need to be created prior to making client setting changes.' + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserTest' + Enable = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $clientTypeError = 'Client Settings for software metering settings only applies to Default and Device client settings.' + + $inputInvalidSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + $scheduleError = 'In order to create a schedule you must specify ScheduleType.' + + Mock -CommandName Test-CMSchedule + Mock -CommandName Set-CMSchedule + Mock -CommandName New-CMSchedule + } + + It 'Should throw and call expected commands when client policy does not exist' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $absentMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareMetering -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when client policy is a user policy' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $clientTypeError + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareMetering -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when not specifying a schedule type with schedule settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + + { Set-TargetResource @inputInvalidSchedule } | Should -Throw -ExpectedMessage $scheduleError + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareMetering -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - CMClientSettingsSoftwareMetering\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + Start = '9/21/2021 16:54' + ScheduleType = 'MonthlyByDay' + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = 0 + RecurInterval = 1 + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserTest' + Enable = $null + Start = $null + ScheduleType = $null + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = $null + RecurInterval = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + } + + $inputPresentMismatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $false + ScheduleType = 'Days' + RecurInterval = 1 + } + + $inputSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ScheduleType = 'MonthlyByWeek' + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + $inputInvalidSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + DayOfWeek = 'Monday' + MonthlyWeekOrder = 'Second' + RecurInterval = 1 + } + + $inputDeviceSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ScheduleType = 'Days' + RecurInterval = 10 + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputPresentMismatch | Should -Be $false + } + + It 'Should return desired result false when schedule does not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputSchedule | Should -Be $false + } + + It 'Should return desired result false when client policy does not exist' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when client policy is user based' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when not specifying a schedule type' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputInvalidSchedule | Should -Be $false + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/CMClientSettingsSoftwareUpdate.tests.ps1 b/tests/Unit/CMClientSettingsSoftwareUpdate.tests.ps1 new file mode 100644 index 00000000..fdca97a3 --- /dev/null +++ b/tests/Unit/CMClientSettingsSoftwareUpdate.tests.ps1 @@ -0,0 +1,1084 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettingsSoftwareUpdate' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsSoftwareUpdate\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $clientReturn = @{ + Type = 0 + } + + $clientReturnFalse = @{ + Enabled = $false + ScanSchedule = 1 + EvaluationSchedule = 2 + AssignmentBatchingTimeout = 0 + EnableExpressUpdates = $true + ExpressUpdatesPort = 8005 + O365Management = 2 + EnableThirdPartyUpdates = $true + } + + $clientReturnEnforceFalse = @{ + Enabled = $true + ScanSchedule = 1 + EvaluationSchedule = 2 + AssignmentBatchingTimeout = 0 + EnableExpressUpdates = $true + ExpressUpdatesPort = 8005 + O365Management = 2 + EnableThirdPartyUpdates = $true + } + + $clientReturnEnforceDays = @{ + Enabled = $true + ScanSchedule = 1 + EvaluationSchedule = 2 + AssignmentBatchingTimeout = 345600 + EnableExpressUpdates = $true + ExpressUpdatesPort = 8005 + O365Management = 1 + EnableThirdPartyUpdates = $true + } + + $clientReturnEnforceHours = @{ + Enabled = $true + ScanSchedule = 1 + EvaluationSchedule = 2 + AssignmentBatchingTimeout = 14400 + EnableExpressUpdates = $true + ExpressUpdatesPort = 8005 + O365Management = 0 + EnableThirdPartyUpdates = $true + } + + $cmScheduleReturnScan = @{ + MinuteDuration = $null + RecurInterval = 1 + WeekOrder = $null + HourDuration = $null + Start = '9/21/2021 16:54' + DayOfWeek = $null + ScheduleType = 'Hours' + MonthDay = $null + DayDuration = $null + } + + $cmScheduleReturnEval = @{ + MinuteDuration = $null + RecurInterval = 2 + WeekOrder = $null + HourDuration = $null + Start = '9/21/2021 16:54' + DayOfWeek = $null + ScheduleType = 'Hours' + MonthDay = $null + DayDuration = $null + } + + $getInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + Mock -CommandName Get-CMSchedule -MockWith { $cmScheduleReturnScan } -ParameterFilter { $ScheduleString -eq '1' } + Mock -CommandName Get-CMSchedule -MockWith { $cmScheduleReturnEval } -ParameterFilter { $ScheduleString -eq '2' } + } + + Context 'When retrieving Client Policy Settings for hardware settings' { + + It 'Should return desired results when enabled and EnforceManatory is false' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnEnforceFalse } -ParameterFilter { $Setting -eq 'SoftwareUpdates' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $true + $result.ScanStart | Should -Be -ExpectedValue '9/21/2021 16:54' + $result.ScanScheduleType | Should -Be -ExpectedValue 'Hours' + $result.ScanDayOfWeek | Should -Be -ExpectedValue $null + $result.ScanMonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.ScanDayofMonth | Should -Be -ExpectedValue $null + $result.ScanRecurInterval | Should -Be -ExpectedValue 1 + $result.EvalStart | Should -Be -ExpectedValue '9/21/2021 16:54' + $result.EvalScheduleType | Should -Be -ExpectedValue 'Hours' + $result.EvalDayOfWeek | Should -Be -ExpectedValue $null + $result.EvalMonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.EvalDayofMonth | Should -Be -ExpectedValue $null + $result.EvalRecurInterval | Should -Be -ExpectedValue 2 + $result.EnforceMandatory | Should -Be -ExpectedValue $false + $result.TimeUnit | Should -Be -ExpectedValue $null + $result.BatchingTimeout | Should -Be -ExpectedValue $null + $result.EnableDeltaDownload | Should -Be -ExpectedValue $true + $result.DeltaDownloadPort | Should -Be -ExpectedValue 8005 + $result.Office365ManagementType | Should -Be -ExpectedValue 'No' + $result.EnableThirdPartyUpdates | Should -Be -ExpectedValue $true + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired results when enabled and EnforceManatory is true and TimeUnit is days' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnEnforceDays } -ParameterFilter { $Setting -eq 'SoftwareUpdates' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $true + $result.ScanStart | Should -Be -ExpectedValue '9/21/2021 16:54' + $result.ScanScheduleType | Should -Be -ExpectedValue 'Hours' + $result.ScanDayOfWeek | Should -Be -ExpectedValue $null + $result.ScanMonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.ScanDayofMonth | Should -Be -ExpectedValue $null + $result.ScanRecurInterval | Should -Be -ExpectedValue 1 + $result.EvalStart | Should -Be -ExpectedValue '9/21/2021 16:54' + $result.EvalScheduleType | Should -Be -ExpectedValue 'Hours' + $result.EvalDayOfWeek | Should -Be -ExpectedValue $null + $result.EvalMonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.EvalDayofMonth | Should -Be -ExpectedValue $null + $result.EvalRecurInterval | Should -Be -ExpectedValue 2 + $result.EnforceMandatory | Should -Be -ExpectedValue $true + $result.TimeUnit | Should -Be -ExpectedValue 'Days' + $result.BatchingTimeout | Should -Be -ExpectedValue 4 + $result.EnableDeltaDownload | Should -Be -ExpectedValue $true + $result.DeltaDownloadPort | Should -Be -ExpectedValue 8005 + $result.Office365ManagementType | Should -Be -ExpectedValue 'Yes' + $result.EnableThirdPartyUpdates | Should -Be -ExpectedValue $true + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired results when enabled and EnforceManatory is true and TimeUnit is hours' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnEnforceHours } -ParameterFilter { $Setting -eq 'SoftwareUpdates' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $true + $result.ScanStart | Should -Be -ExpectedValue '9/21/2021 16:54' + $result.ScanScheduleType | Should -Be -ExpectedValue 'Hours' + $result.ScanDayOfWeek | Should -Be -ExpectedValue $null + $result.ScanMonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.ScanDayofMonth | Should -Be -ExpectedValue $null + $result.ScanRecurInterval | Should -Be -ExpectedValue 1 + $result.EvalStart | Should -Be -ExpectedValue '9/21/2021 16:54' + $result.EvalScheduleType | Should -Be -ExpectedValue 'Hours' + $result.EvalDayOfWeek | Should -Be -ExpectedValue $null + $result.EvalMonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.EvalDayofMonth | Should -Be -ExpectedValue $null + $result.EvalRecurInterval | Should -Be -ExpectedValue 2 + $result.EnforceMandatory | Should -Be -ExpectedValue $true + $result.TimeUnit | Should -Be -ExpectedValue 'Hours' + $result.BatchingTimeout | Should -Be -ExpectedValue 4 + $result.EnableDeltaDownload | Should -Be -ExpectedValue $true + $result.DeltaDownloadPort | Should -Be -ExpectedValue 8005 + $result.Office365ManagementType | Should -Be -ExpectedValue 'NotConfigured' + $result.EnableThirdPartyUpdates | Should -Be -ExpectedValue $true + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired result when software update is disabled' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturnFalse } -ParameterFilter { $Setting -eq 'SoftwareUpdates' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $false + $result.ScanStart | Should -Be -ExpectedValue $null + $result.ScanScheduleType | Should -Be -ExpectedValue $null + $result.ScanDayOfWeek | Should -Be -ExpectedValue $null + $result.ScanMonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.ScanDayofMonth | Should -Be -ExpectedValue $null + $result.ScanRecurInterval | Should -Be -ExpectedValue $null + $result.EvalStart | Should -Be -ExpectedValue $null + $result.EvalScheduleType | Should -Be -ExpectedValue $null + $result.EvalDayOfWeek | Should -Be -ExpectedValue $null + $result.EvalMonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.EvalDayofMonth | Should -Be -ExpectedValue $null + $result.EvalRecurInterval | Should -Be -ExpectedValue $null + $result.EnforceMandatory | Should -Be -ExpectedValue $null + $result.TimeUnit | Should -Be -ExpectedValue $null + $result.BatchingTimeout | Should -Be -ExpectedValue $null + $result.EnableDeltaDownload | Should -Be -ExpectedValue $null + $result.DeltaDownloadPort | Should -Be -ExpectedValue $null + $result.Office365ManagementType | Should -Be -ExpectedValue $null + $result.EnableThirdPartyUpdates | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired result when client setting policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $null + $result.ScanStart | Should -Be -ExpectedValue $null + $result.ScanScheduleType | Should -Be -ExpectedValue $null + $result.ScanDayOfWeek | Should -Be -ExpectedValue $null + $result.ScanMonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.ScanDayofMonth | Should -Be -ExpectedValue $null + $result.ScanRecurInterval | Should -Be -ExpectedValue $null + $result.EvalStart | Should -Be -ExpectedValue $null + $result.EvalScheduleType | Should -Be -ExpectedValue $null + $result.EvalDayOfWeek | Should -Be -ExpectedValue $null + $result.EvalMonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.EvalDayofMonth | Should -Be -ExpectedValue $null + $result.EvalRecurInterval | Should -Be -ExpectedValue $null + $result.EnforceMandatory | Should -Be -ExpectedValue $null + $result.TimeUnit | Should -Be -ExpectedValue $null + $result.BatchingTimeout | Should -Be -ExpectedValue $null + $result.EnableDeltaDownload | Should -Be -ExpectedValue $null + $result.DeltaDownloadPort | Should -Be -ExpectedValue $null + $result.Office365ManagementType | Should -Be -ExpectedValue $null + $result.EnableThirdPartyUpdates | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Absent' + $result.ClientType | Should -Be -ExpectedValue $null + } + + It 'Should return desired result when client setting policy exist but software updates is not configured' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } + Mock -CommandName Get-CMClientSetting -MockWith { $null } -ParameterFilter { $Setting -eq 'SoftwareUpdates' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.Enable | Should -Be -ExpectedValue $null + $result.ScanStart | Should -Be -ExpectedValue $null + $result.ScanScheduleType | Should -Be -ExpectedValue $null + $result.ScanDayOfWeek | Should -Be -ExpectedValue $null + $result.ScanMonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.ScanDayofMonth | Should -Be -ExpectedValue $null + $result.ScanRecurInterval | Should -Be -ExpectedValue $null + $result.EvalStart | Should -Be -ExpectedValue $null + $result.EvalScheduleType | Should -Be -ExpectedValue $null + $result.EvalDayOfWeek | Should -Be -ExpectedValue $null + $result.EvalMonthlyWeekOrder | Should -Be -ExpectedValue $null + $result.EvalDayofMonth | Should -Be -ExpectedValue $null + $result.EvalRecurInterval | Should -Be -ExpectedValue $null + $result.EnforceMandatory | Should -Be -ExpectedValue $null + $result.TimeUnit | Should -Be -ExpectedValue $null + $result.BatchingTimeout | Should -Be -ExpectedValue $null + $result.EnableDeltaDownload | Should -Be -ExpectedValue $null + $result.DeltaDownloadPort | Should -Be -ExpectedValue $null + $result.Office365ManagementType | Should -Be -ExpectedValue $null + $result.EnableThirdPartyUpdates | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsSoftwareUpdate\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $returnPresentDevice = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ScanStart = '9/21/2021 16:54' + ScanScheduleType = 'Hours' + ScanDayOfWeek = $null + ScanMonthlyWeekOrder = $null + ScanDayofMonth = $null + ScanRecurInterval = 1 + EvalStart = '9/21/2021 16:54' + EvalScheduleType = 'Hours' + EvalDayOfWeek = $null + EvalMonthlyWeekOrder = $null + EvalDayofMonth = $null + EvalRecurInterval = 2 + EnforceMandatory = $true + TimeUnit = 'Days' + BatchingTimeout = 4 + EnableDeltaDownload = $true + DeltaDownloadPort = 8005 + Office365ManagementType = 'Yes' + EnableThirdPartyUpdates = $true + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ScanStart = '9/21/2021 16:54' + ScanScheduleType = 'Hours' + ScanRecurInterval = 1 + EvalStart = '9/21/2021 16:54' + EvalScheduleType = 'Hours' + EvalRecurInterval = 2 + EnforceMandatory = $true + TimeUnit = 'Days' + BatchingTimeout = 4 + EnableDeltaDownload = $true + DeltaDownloadPort = 8005 + Office365ManagementType = 'Yes' + EnableThirdPartyUpdates = $true + } + + Mock -CommandName Set-CMClientSettingSoftwareUpdate + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $inputPresentDefault = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + ScanStart = '9/21/2021 16:54' + ScanScheduleType = 'Hours' + ScanRecurInterval = 1 + EvalStart = '9/21/2021 16:54' + EvalScheduleType = 'Hours' + EvalRecurInterval = 2 + EnforceMandatory = $true + TimeUnit = 'Days' + BatchingTimeout = 4 + EnableDeltaDownload = $true + DeltaDownloadPort = 8005 + Office365ManagementType = 'No' + EnableThirdPartyUpdates = $true + } + + $returnDisabled = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $false + ScanStart = $null + ScanScheduleType = $null + ScanDayOfWeek = $null + ScanMonthlyWeekOrder = $null + ScanDayofMonth = $null + ScanRecurInterval = $null + EvalStart = $null + EvalScheduleType = $null + EvalDayOfWeek = $null + EvalMonthlyWeekOrder = $null + EvalDayofMonth = $null + EvalRecurInterval = $null + EnforceMandatory = $null + TimeUnit = $null + BatchingTimeout = $null + EnableDeltaDownload = $null + DeltaDownloadPort = $null + Office365ManagementType = $null + EnableThirdPartyUpdates = $null + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $returnNotConfigured = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $null + ScanStart = $null + ScanScheduleType = $null + ScanDayOfWeek = $null + ScanMonthlyWeekOrder = $null + ScanDayofMonth = $null + ScanRecurInterval = $null + EvalStart = $null + EvalScheduleType = $null + EvalDayOfWeek = $null + EvalMonthlyWeekOrder = $null + EvalDayofMonth = $null + EvalRecurInterval = $null + EnforceMandatory = $null + TimeUnit = $null + BatchingTimeout = $null + EnableDeltaDownload = $null + DeltaDownloadPort = $null + Office365ManagementType = $null + EnableThirdPartyUpdates = $null + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $inputPersentMismatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ScanStart = '9/21/2021 16:54' + ScanScheduleType = 'Hours' + ScanRecurInterval = 2 + EvalStart = '9/21/2021 16:54' + EvalScheduleType = 'Hours' + EvalRecurInterval = 3 + EnforceMandatory = $true + TimeUnit = 'Hours' + BatchingTimeout = 5 + EnableDeltaDownload = $true + DeltaDownloadPort = 8006 + Office365ManagementType = 'NotConfigured' + EnableThirdPartyUpdates = $false + } + + $inputDisableExtraParams = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $false + Office365ManagementType = 'NotConfigured' + EnableThirdPartyUpdates = $false + } + + $inputDeltaHoursExtra = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EnforceMandatory = $true + TimeUnit = 'Hours' + BatchingTimeout = 40 + } + + $inputDeltaHoursEnforceDisabled = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EnforceMandatory = $false + TimeUnit = 'Hours' + BatchingTimeout = 5 + } + + $inputEnableDeltaFalse = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EnableDeltaDownload = $false + DeltaDownloadPort = 8005 + } + + $cmScheduleInput = @{ + RecurCount = 1 + RecurInterval = 'Days' + } + + Mock -CommandName Set-CMSchedule -MockWith { $cmScheduleInput } + Mock -CommandName New-CMSchedule -MockWith { $cmScheduleInput } + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule -MockWith { $true } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 2 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareUpdate -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule -MockWith { $false } + + Set-TargetResource @inputPersentMismatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 2 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 2 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 2 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareUpdate -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when current state is not configured' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfigured } + Mock -CommandName Test-CMSchedule -MockWith { $false } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 2 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 2 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 2 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareUpdate -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when current state is disabled and enabling' { + Mock -CommandName Get-TargetResource -MockWith { $returnDisabled } + Mock -CommandName Test-CMSchedule -MockWith { $false } + + Set-TargetResource @inputPresentDefault + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 2 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 2 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 2 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareUpdate -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when settings to disabled and currently enabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule + + Set-TargetResource @inputDisableExtraParams + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareUpdate -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when setting EnabledDelta to false and specifying DeltaDownloadPort' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule + + Set-TargetResource @inputEnableDeltaFalse + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareUpdate -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when TimeUnit is hours and BatchingTimeout is above 23' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule + + Set-TargetResource @inputDeltaHoursExtra + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareUpdate -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when setting EnforceMandatory to false and specifying TimeUnit or BatchingTimeout' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + Mock -CommandName Test-CMSchedule + + Set-TargetResource @inputDeltaHoursEnforceDisabled + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareUpdate -Exactly -Times 1 -Scope It + } + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + ScanStart = $null + ScanScheduleType = $null + ScanDayOfWeek = $null + ScanMonthlyWeekOrder = $null + ScanDayofMonth = $null + ScanRecurInterval = $null + EvalStart = $null + EvalScheduleType = $null + EvalDayOfWeek = $null + EvalMonthlyWeekOrder = $null + EvalDayofMonth = $null + EvalRecurInterval = $null + EnforceMandatory = $null + TimeUnit = $null + BatchingTimeout = $null + EnableDeltaDownload = $null + DeltaDownloadPort = $null + Office365ManagementType = $null + EnableThirdPartyUpdates = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $absentMsg = 'Client Policy setting ClientTest does not exist, and will need to be created prior to making client setting changes.' + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserTest' + Enable = $null + ScanStart = $null + ScanScheduleType = $null + ScanDayOfWeek = $null + ScanMonthlyWeekOrder = $null + ScanDayofMonth = $null + ScanRecurInterval = $null + EvalStart = $null + EvalScheduleType = $null + EvalDayOfWeek = $null + EvalMonthlyWeekOrder = $null + EvalDayofMonth = $null + EvalRecurInterval = $null + EnforceMandatory = $null + TimeUnit = $null + BatchingTimeout = $null + EnableDeltaDownload = $null + DeltaDownloadPort = $null + Office365ManagementType = $null + EnableThirdPartyUpdates = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $clientTypeError = 'Client Settings for software update only applies to Default and Device client settings.' + + $inputInvalidScanSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ScanDayOfWeek = 'Monday' + ScanMonthlyWeekOrder = 'Second' + ScanRecurInterval = 1 + } + + $inputInvalidEvalSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EvalDayOfWeek = 'Monday' + EvalMonthlyWeekOrder = 'Second' + EvalRecurInterval = 1 + } + + $scheduleError = 'In order to create a schedule you must specify ScheduleType.' + + $inputDeltaTrue = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EnforceMandatory = $true + TimeUnit = 'Hours' + } + + $missingInPut = 'When settings EnforceMandatory to true you must specify both TimeUnit and BatchingTimeOut.' + + Mock -CommandName Test-CMSchedule + Mock -CommandName Set-CMSchedule + Mock -CommandName New-CMSchedule + } + + It 'Should throw and call expected commands when client policy does not exist' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $absentMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareUpdate -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when client policy is a user policy' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $clientTypeError + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareUpdate -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when not specifying a schedule type with scan schedule settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + + { Set-TargetResource @inputInvalidScanSchedule } | Should -Throw -ExpectedMessage $scheduleError + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareUpdate -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when not specifying a schedule type with eval schedule settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + + { Set-TargetResource @inputInvalidEvalSchedule } | Should -Throw -ExpectedMessage $scheduleError + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareUpdate -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when enforce is set to true and missing BatchTimeOut' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + + { Set-TargetResource @inputDeltaTrue } | Should -Throw -ExpectedMessage $missingInPut + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Test-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSchedule -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMClientSettingSoftwareUpdate -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsSoftwareUpdate\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresentDevice = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ScanStart = '9/21/2021 16:54' + ScanScheduleType = 'Hours' + ScanDayOfWeek = $null + ScanMonthlyWeekOrder = $null + ScanDayofMonth = $null + ScanRecurInterval = 1 + EvalStart = '9/21/2021 16:54' + EvalScheduleType = 'Hours' + EvalDayOfWeek = $null + EvalMonthlyWeekOrder = $null + EvalDayofMonth = $null + EvalRecurInterval = 2 + EnforceMandatory = $true + TimeUnit = 'Days' + BatchingTimeout = 4 + EnableDeltaDownload = $true + DeltaDownloadPort = 8005 + Office365ManagementType = 'Yes' + EnableThirdPartyUpdates = $true + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnDisabled = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + Enable = $false + ScanStart = $null + ScanScheduleType = $null + ScanDayOfWeek = $null + ScanMonthlyWeekOrder = $null + ScanDayofMonth = $null + ScanRecurInterval = $null + EvalStart = $null + EvalScheduleType = $null + EvalDayOfWeek = $null + EvalMonthlyWeekOrder = $null + EvalDayofMonth = $null + EvalRecurInterval = $null + EnforceMandatory = $null + TimeUnit = $null + BatchingTimeout = $null + EnableDeltaDownload = $null + DeltaDownloadPort = $null + Office365ManagementType = $null + EnableThirdPartyUpdates = $null + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $null + ScanStart = $null + ScanScheduleType = $null + ScanDayOfWeek = $null + ScanMonthlyWeekOrder = $null + ScanDayofMonth = $null + ScanRecurInterval = $null + EvalStart = $null + EvalScheduleType = $null + EvalDayOfWeek = $null + EvalMonthlyWeekOrder = $null + EvalDayofMonth = $null + EvalRecurInterval = $null + EnforceMandatory = $null + TimeUnit = $null + BatchingTimeout = $null + EnableDeltaDownload = $null + DeltaDownloadPort = $null + Office365ManagementType = $null + EnableThirdPartyUpdates = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserTest' + Enable = $null + ScanStart = $null + ScanScheduleType = $null + ScanDayOfWeek = $null + ScanMonthlyWeekOrder = $null + ScanDayofMonth = $null + ScanRecurInterval = $null + EvalStart = $null + EvalScheduleType = $null + EvalDayOfWeek = $null + EvalMonthlyWeekOrder = $null + EvalDayofMonth = $null + EvalRecurInterval = $null + EnforceMandatory = $null + TimeUnit = $null + BatchingTimeout = $null + EnableDeltaDownload = $null + DeltaDownloadPort = $null + Office365ManagementType = $null + EnableThirdPartyUpdates = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ScanStart = '9/21/2021 16:54' + ScanScheduleType = 'Hours' + ScanRecurInterval = 1 + EvalStart = '9/21/2021 16:54' + EvalScheduleType = 'Hours' + EvalRecurInterval = 2 + EnforceMandatory = $true + TimeUnit = 'Days' + BatchingTimeout = 4 + EnableDeltaDownload = $true + DeltaDownloadPort = 8005 + Office365ManagementType = 'Yes' + EnableThirdPartyUpdates = $true + } + + $inputPersentMismatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ScanStart = '9/21/2021 16:54' + ScanScheduleType = 'Hours' + ScanRecurInterval = 2 + EvalStart = '9/21/2021 16:54' + EvalScheduleType = 'Hours' + EvalRecurInterval = 3 + EnforceMandatory = $true + TimeUnit = 'Hours' + BatchingTimeout = 5 + EnableDeltaDownload = $true + DeltaDownloadPort = 8006 + Office365ManagementType = 'No' + EnableThirdPartyUpdates = $false + } + + $inputInvalidScanSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + ScanDayOfWeek = 'Monday' + ScanMonthlyWeekOrder = 'Second' + ScanRecurInterval = 1 + } + + $inputInvalidEvalSchedule = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EvalDayOfWeek = 'Monday' + EvalMonthlyWeekOrder = 'Second' + EvalRecurInterval = 1 + } + + $inputDisable = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $false + } + + $inputDisableExtraParams = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $false + Office365ManagementType = 'No' + EnableThirdPartyUpdates = $false + } + + $inputDeltaTrue = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EnforceMandatory = $true + TimeUnit = 'Hours' + } + + $inputDeltaHoursExtra = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EnforceMandatory = $true + TimeUnit = 'Hours' + BatchingTimeout = 40 + } + + $inputDeltaHoursMissingEnforce = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + TimeUnit = 'Hours' + BatchingTimeout = 5 + } + + $inputEnableDeltaFalse = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + Enable = $true + EnableDeltaDownload = $false + DeltaDownloadPort = 8005 + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false when settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Test-TargetResource @inputPersentMismatch | Should -Be $false + } + + It 'Should return desired result false when specifying a scan schedule with no ScheduleType' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Test-TargetResource @inputInvalidScanSchedule | Should -Be $false + } + + It 'Should return desired result false when specifying an eval schedule with no ScheduleType' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Test-TargetResource @inputInvalidEvalSchedule | Should -Be $false + } + + It 'Should return desired result false when enabled and expected disabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Test-TargetResource @inputDisable | Should -Be $false + } + + It 'Should return desired result false when enabled and expected disabled and adding unneeded params' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Test-TargetResource @inputDisableExtraParams | Should -Be $false + } + + It 'Should return desired result false when enforce is set to true and missing BatchTimeOut' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Test-TargetResource @inputDeltaTrue | Should -Be $false + } + + It 'Should return desired result false when enforce is set to true TimeUnit set to hours and BatchTimeOut is over 23' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Test-TargetResource @inputDeltaHoursExtra | Should -Be $false + } + + It 'Should return desired result true when enforce is set to false and TimeUnit and BatchTimeOut is specified and do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Test-TargetResource @inputDeltaHoursMissingEnforce | Should -Be $true + } + + It 'Should return desired result false when EnableDelta is set to false and specifying DeltaDownloadPort' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Test-TargetResource @inputEnableDeltaFalse | Should -Be $false + } + + It 'Should return desired result false when client setting specified is for user settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when client setting is absent' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + Test-TargetResource @inputPresent | Should -Be $false + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/CMClientSettingsStateMessaging.tests.ps1 b/tests/Unit/CMClientSettingsStateMessaging.tests.ps1 new file mode 100644 index 00000000..8922504e --- /dev/null +++ b/tests/Unit/CMClientSettingsStateMessaging.tests.ps1 @@ -0,0 +1,325 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettingsStateMessaging' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsStateMessaging\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $clientReturn = @{ + BulkSendInterval = 200 + } + + $clientCheck = @{ + Type = 1 + } + + $getInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When retrieving Client Policy Settings for State Messaging' { + + It 'Should return desired results when client settings exist' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientCheck } + Mock -CommandName Get-CMClientSetting -MockWith { $clientReturn } -ParameterFilter { $Setting -eq 'StateMessaging' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.ReportingCycleMins | Should -Be -ExpectedValue 200 + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + + It 'Should return desired result when client setting policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.ReportingCycleMins | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Absent' + $result.ClientType | Should -Be -ExpectedValue $null + } + + It 'Should return desired result when client setting policy exist but state messaging is not configured' { + Mock -CommandName Get-CMClientSetting -MockWith { $clientCheck } + Mock -CommandName Get-CMClientSetting -MockWith { $null } -ParameterFilter { $Setting -eq 'StateMessaging' } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.ReportingCycleMins | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsStateMessaging\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ReportingCycleMins = 200 + } + + Mock -CommandName Set-CMClientSettingStateMessaging + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ReportingCycleMins = 200 + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnPresentDefaultClient = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + ReportingCycleMins = 300 + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ReportingCycleMins = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $inputStateMisMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ReportingCycleMins = 400 + } + + $inputStateDefaultClient = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + ReportingCycleMins = 100 + } + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingStateMessaging -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingStateMessaging -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when changing state messaging' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Set-TargetResource @inputStateMisMatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingStateMessaging -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when changing state messaging for default client settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefaultClient } + + Set-TargetResource @inputStateDefaultClient + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingStateMessaging -Exactly -Times 1 -Scope It + } + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ReportingCycleMins = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $absentMsg = 'Client Policy setting ClientTest does not exist, and will need to be created prior to making client setting changes.' + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientUser' + ReportingCycleMins = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $wrongClientType = 'Client Settings for state messaging only applies to Default and Device Client settings.' + } + + It 'Should throw and call expected commands when setting command when disabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $absentMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingStateMessaging -Exactly -Times 0 -Scope It + } + + It 'Should throw and call expected commands when client policy settings is user based' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $wrongClientType + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingStateMessaging -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsStateMessaging\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ReportingCycleMins = 200 + ClientSettingStatus = 'Present' + } + + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ReportingCycleMins = $null + ClientSettingStatus = 'Absent' + } + + $returnNotConfig = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ReportingCycleMins = $null + ClientSettingStatus = 'Present' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ReportingCycleMins = 200 + } + + $inputStateMisMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + ReportingCycleMins = 300 + } + + $returnUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientUser' + ReportingCycleMins = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when client policy exists but does not set state messaging settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnNotConfig } + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result false when state messaging settings do not match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresent } + + Test-TargetResource @inputStateMisMatch | Should -Be $false + } + + It 'Should return desired result false when trying to apply settings to a user based client policy' { + Mock -CommandName Get-TargetResource -MockWith { $returnUser } + + Test-TargetResource @inputPresent | Should -Be $false + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/CMClientSettingsUserDeviceAffinity.tests.ps1 b/tests/Unit/CMClientSettingsUserDeviceAffinity.tests.ps1 new file mode 100644 index 00000000..68959209 --- /dev/null +++ b/tests/Unit/CMClientSettingsUserDeviceAffinity.tests.ps1 @@ -0,0 +1,409 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMClientSettingsUserDeviceAffinity' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsUserDeviceAffinity\Get-TargetResource' -Tag 'Get' { + BeforeAll { + $returnTypeDefault = @{ + Type = 0 + } + + $returnTypeDevice = @{ + Type = 1 + } + + $returnTypeUser = @{ + Type = 2 + } + + $returnClient = @{ + ConsoleMinutes = 200 + IntervalDays = 100 + AllowUserAffinity = $true + AutoApproveAffinity = $true + } + + $getDefaultInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + } + + $getDeviceInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'ClientTest' + } + + $getUserInput = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserTest' + } + + $clientSettingReturn = @{ + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When retrieving Client Policy Settings for User Device Affinity' { + + It 'Should return desired results when client settings exist for default client policy' { + Mock -CommandName Get-CMClientSetting -MockWith { $returnTypeDefault } + Mock -CommandName Get-CMClientSetting -MockWith { $returnClient } -ParameterFilter { $Setting -eq 'UserAndDeviceAffinity' } + + $result = Get-TargetResource @getDefaultInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'Default Client Agent Settings' + $result.LogOnThresholdMins | Should -Be -ExpectedValue 200 + $result.UsageThresholdDays | Should -Be -ExpectedValue 100 + $result.AutoApproveAffinity | Should -Be -ExpectedValue $true + $result.AllowUserAffinity | Should -Be -ExpectedValue $true + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Default' + } + + It 'Should return desired results when client settings exist for device client policy' { + Mock -CommandName Get-CMClientSetting -MockWith { $returnTypeDevice } + Mock -CommandName Get-CMClientSetting -MockWith { $returnClient } -ParameterFilter { $Setting -eq 'UserAndDeviceAffinity' } + + $result = Get-TargetResource @getDeviceInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'ClientTest' + $result.LogOnThresholdMins | Should -Be -ExpectedValue 200 + $result.UsageThresholdDays | Should -Be -ExpectedValue 100 + $result.AutoApproveAffinity | Should -Be -ExpectedValue $true + $result.AllowUserAffinity | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'Device' + } + + It 'Should return desired results when client settings exist for User client policy' { + Mock -CommandName Get-CMClientSetting -MockWith { $returnTypeUser } + Mock -CommandName Get-CMClientSetting -MockWith { $returnClient } -ParameterFilter { $Setting -eq 'UserAndDeviceAffinity' } + + $result = Get-TargetResource @getUserInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'UserTest' + $result.LogOnThresholdMins | Should -Be -ExpectedValue $null + $result.UsageThresholdDays | Should -Be -ExpectedValue $null + $result.AutoApproveAffinity | Should -Be -ExpectedValue $null + $result.AllowUserAffinity | Should -Be -ExpectedValue $true + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Present' + $result.ClientType | Should -Be -ExpectedValue 'User' + } + + It 'Should return desired results when client policy does not exist' { + Mock -CommandName Get-CMClientSetting + + $result = Get-TargetResource @getUserInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.ClientSettingName | Should -Be -ExpectedValue 'UserTest' + $result.LogOnThresholdMins | Should -Be -ExpectedValue $null + $result.UsageThresholdDays | Should -Be -ExpectedValue $null + $result.AutoApproveAffinity | Should -Be -ExpectedValue $null + $result.AllowUserAffinity | Should -Be -ExpectedValue $null + $result.ClientSettingStatus | Should -Be -ExpectedValue 'Absent' + $result.ClientType | Should -Be -ExpectedValue $null + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsUserDeviceAffinity\Set-TargetResource' -Tag 'Set' { + BeforeAll { + $inputDeviceMisMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'TestClient' + LogOnThresholdMins = 100 + UsageThresholdDays = 50 + AutoApproveAffinity = $false + AllowUserAffinity = $true + } + + Mock -CommandName Set-CMClientSettingUserAndDeviceAffinity + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When Set-TargetResource runs successfully' { + BeforeEach { + $returnPresentDefault = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + LogOnThresholdMins = 200 + UsageThresholdDays = 100 + AutoApproveAffinity = $true + AllowUserAffinity = $true + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + LogOnThresholdMins = 200 + UsageThresholdDays = 100 + AutoApproveAffinity = $true + AllowUserAffinity = $true + } + + $inputDefaultMisMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + LogOnThresholdMins = 100 + UsageThresholdDays = 50 + AutoApproveAffinity = $false + AllowUserAffinity = $false + } + + $returnPresentDevice = @{ + SiteCode = 'Lab' + ClientSettingName = 'TestClient' + LogOnThresholdMins = 200 + UsageThresholdDays = 100 + AutoApproveAffinity = $true + AllowUserAffinity = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $returnPresentUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserClient' + LogOnThresholdMins = $null + UsageThresholdDays = $null + AutoApproveAffinity = $null + AllowUserAffinity = $true + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $inputUserMisMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'TestClient' + LogOnThresholdMins = 100 + UsageThresholdDays = 50 + AutoApproveAffinity = $false + AllowUserAffinity = $false + } + } + + It 'Should call expected commands when settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + + Set-TargetResource @inputPresent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingUserAndDeviceAffinity -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when making changes to device policy settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Set-TargetResource @inputDeviceMisMatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingUserAndDeviceAffinity -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when making changes to user policy settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentUser } + + Set-TargetResource @inputUserMisMatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingUserAndDeviceAffinity -Exactly -Times 1 -Scope It + } + + It 'Should call expected commands when making changes to default policy settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + + Set-TargetResource @inputDefaultMisMatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingUserAndDeviceAffinity -Exactly -Times 1 -Scope It + } + + } + + Context 'When running Set-TargetResource should throw' { + BeforeEach { + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'TestClient' + LogOnThresholdMins = $null + UsageThresholdDays = $null + AutoApproveAffinity = $null + AllowUserAffinity = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + $absentMsg = 'Client Policy setting TestClient does not exist, and will need to be created prior to making client setting changes.' + } + + It 'Should throw and call expected commands when setting command when disabled' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + { Set-TargetResource @inputDeviceMisMatch } | Should -Throw -ExpectedMessage $absentMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMClientSettingUserAndDeviceAffinity -Exactly -Times 0 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMClientSettingsUserDeviceAffinity\Test-TargetResource' -Tag 'Test' { + BeforeAll { + $returnPresentDefault = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + LogOnThresholdMins = 200 + UsageThresholdDays = 100 + AutoApproveAffinity = $true + AllowUserAffinity = $true + ClientSettingStatus = 'Present' + ClientType = 'Default' + } + + $inputPresent = @{ + SiteCode = 'Lab' + ClientSettingName = 'Default Client Agent Settings' + LogOnThresholdMins = 200 + UsageThresholdDays = 100 + AutoApproveAffinity = $true + AllowUserAffinity = $true + } + + $returnPresentDevice = @{ + SiteCode = 'Lab' + ClientSettingName = 'TestClient' + LogOnThresholdMins = 200 + UsageThresholdDays = 100 + AutoApproveAffinity = $true + AllowUserAffinity = $null + ClientSettingStatus = 'Present' + ClientType = 'Device' + } + + $inputDeviceMisMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'TestClient' + LogOnThresholdMins = 100 + UsageThresholdDays = 50 + AutoApproveAffinity = $false + AllowUserAffinity = $true + } + + $returnPresentUser = @{ + SiteCode = 'Lab' + ClientSettingName = 'UserClient' + LogOnThresholdMins = $null + UsageThresholdDays = $null + AutoApproveAffinity = $null + AllowUserAffinity = $true + ClientSettingStatus = 'Present' + ClientType = 'User' + } + + $inputUserMisMatch = @{ + SiteCode = 'Lab' + ClientSettingName = 'TestClient' + LogOnThresholdMins = 100 + UsageThresholdDays = 50 + AutoApproveAffinity = $false + AllowUserAffinity = $false + } + + $returnAbsent = @{ + SiteCode = 'Lab' + ClientSettingName = 'TestClient' + LogOnThresholdMins = $null + UsageThresholdDays = $null + AutoApproveAffinity = $null + AllowUserAffinity = $null + ClientSettingStatus = 'Absent' + ClientType = $null + } + + Mock -CommandName Set-Location + Mock -CommandName Import-ConfigMgrPowerShellModule + } + + Context 'When running Test-TargetResource' { + + It 'Should return desired result true settings match' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDefault } + + Test-TargetResource @inputPresent | Should -Be $true + } + + It 'Should return desired result false when modifying device settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentDevice } + + Test-TargetResource @inputDeviceMisMatch | Should -Be $false + } + + It 'Should return desired result false when modifying user settings' { + Mock -CommandName Get-TargetResource -MockWith { $returnPresentUser } + + Test-TargetResource @inputUserMisMatch | Should -Be $false + } + + It 'Should return desired result false when client policy is absent' { + Mock -CommandName Get-TargetResource -MockWith { $returnAbsent } + + Test-TargetResource @inputPresent | Should -Be $false + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/ConfigMgrCBDsc.ReverseDsc.tests.ps1 b/tests/Unit/ConfigMgrCBDsc.ReverseDsc.tests.ps1 index 7cf93fd4..46056bb1 100644 --- a/tests/Unit/ConfigMgrCBDsc.ReverseDsc.tests.ps1 +++ b/tests/Unit/ConfigMgrCBDsc.ReverseDsc.tests.ps1 @@ -427,6 +427,1472 @@ InModuleScope $script:subModuleName { } ) } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettings' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'Type' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'Description' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'SecurityScopes' + PropertyType = '[string[]]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'SecurityScopesToInclude' + PropertyType = '[string[]]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'SecurityScopesToExclude' + PropertyType = '[string[]]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'Ensure' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettingsBits' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'EnableBitsMaxBandwidth' + PropertyType = '[bool]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'MaxBandwidthBeginHr' + PropertyType = '[uint32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'MaxBandwidthEndHr' + PropertyType = '[uint32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'MaxTransferRateOnSchedule' + PropertyType = 'UInt32' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EnableDownloadOffSchedule' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'MaxTransferRateOffSchedule' + PropertyType = '[uint32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettingsClientCache' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ConfigureBranchCache' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EnableBranchCache' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'MaxBranchCacheSizePercent' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'ConfigureCacheSize' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'MaxCacheSize' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'MaxCacheSizePercent' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EnableSuperPeer' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'BroadcastPort' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DownloadPort' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettingsClientPolicy' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'PolicyPollingMins' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EnableUserPolicy' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EnableUserPolicyOnInternet' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EnableUserPolicyOnTS' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettingsCloudService' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'AllowCloudDistributionPoint' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'AutoAzureADJoin' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'AllowCloudManagementGateway' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettingsCompliance' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'Enable' + PropertyType = '[bool]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'EnableUserDataAndProfile' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'MonthlyWeekOrder' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'RecurInterval' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'ScheduleType' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'Start' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DayOfMonth' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DayOfWeek' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettingsComputerAgent' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'InitialReminderHr' + PropertyType = '[uint32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'InterimReminderHr' + PropertyType = '[uint32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'FinalReminderMins' + PropertyType = '[uint32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'BrandingTitle' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'UseNewSoftwareCenter' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EnableHealthAttestation' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'UseOnPremisesHealthAttestation' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'InstallRestriction' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'SuspendBitLocker' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EnableThirdPartyOrchestration' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PowerShellExecutionPolicy' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DisplayNewProgramNotification' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettingsDelivery' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'Enable' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettingsHardware' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'Enable' + PropertyType = '[bool]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'MaxRandomDelayMins' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'MonthlyWeekOrder' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'RecurInterval' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'ScheduleType' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'Start' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DayOfMonth' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DayOfWeek' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'CollectMifFile' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'MaxThirdPartyMifSize' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettingsMetered' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'MeteredNetworkUsage' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettingsPower' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'Enable' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'AllowUserToOptOutFromPowerPlan' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'NetworkWakeUpOption' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EnableWakeUpProxy' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'WakeupProxyPort' + PropertyType = '[uint32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'WakeOnLanPort' + PropertyType = '[uint32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'FirewallExceptionForWakeupProxy' + PropertyType = '[string[]]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'WakeupProxyDirectAccessPrefix' + PropertyType = '[string[]]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettingsRemoteTools' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'FirewallExceptionProfile' + PropertyType = '[string[]]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'AllowClientChange' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'AllowUnattendedComputer' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PromptUserForPermission' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PromptUserForClipboardPermission' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'GrantPermissionToLocalAdministrator' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'AccessLevel' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PermittedViewer' + PropertyType = '[string[]]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'ShowNotificationIconOnTaskbar' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'ShowSessionConnectionBar' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'AudibleSignal' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'ManageUnsolicitedRemoteAssistance' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'ManageSolicitedRemoteAssistance' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'RemoteAssistanceAccessLevel' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'ManageRemoteDesktopSetting' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'AllowPermittedViewer' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'RequireAuthentication' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettingsSoftwareCenter' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'EnableCustomize' + PropertyType = '[bool]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'CompanyName' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'ColorScheme' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'HideApplicationCatalogLink' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'HideInstalledApplication' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'HideUnapprovedApplication' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EnableApplicationsTab' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EnableUpdatesTab' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EnableOperatingSystemsTab' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EnableStatusTab' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EnableComplianceTab' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EnableOptionsTab' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettingsSoftwareDeployment' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'MonthlyWeekOrder' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'RecurInterval' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'ScheduleType' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'Start' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DayOfMonth' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DayOfWeek' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettingsSoftwareInventory' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'Enable' + PropertyType = '[bool]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ReportOption' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'MonthlyWeekOrder' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'RecurInterval' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'ScheduleType' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'Start' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DayOfMonth' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DayOfWeek' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettingsSoftwareMetering' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'Enable' + PropertyType = '[bool]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'MonthlyWeekOrder' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'RecurInterval' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'ScheduleType' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'Start' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DayOfMonth' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DayOfWeek' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettingsSoftwareUpdate' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'Enable' + PropertyType = '[bool]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ScanMonthlyWeekOrder' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'ScanRecurInterval' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'ScanScheduleType' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'ScanStart' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'ScanDayOfMonth' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'ScanDayOfWeek' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EvalMonthlyWeekOrder' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EvalRecurInterval' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EvalScheduleType' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EvalStart' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EvalDayOfMonth' + PropertyType = '[UInt32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EvalDayOfWeek' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EnforceMandatory' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'TimeUnit' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'BatchingTimeOut' + PropertyType = '[uint32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EnableDeltaDownload' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DeltaDownloadPort' + PropertyType = '[uint32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'Office365ManagementType' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'EnableThirdPartyUpdates' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettingsStateMessaging' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ReportingCycleMins' + PropertyType = '[uint32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } + @{ + ImplementedAs = 'PowerShell' + Name = 'CMClientSettingsUserDeviceAffinity' + ModuleName = 'ConfigMgrCBDsc' + Version = '1.0.1' + Properties = @( + @{ + Name = 'SiteCode' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'ClientSettingName' + PropertyType = '[string]' + IsMandatory = $true + Values = '{}' + } + @{ + Name = 'LogOnThresholdMins' + PropertyType = '[uint32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'UsageThresholdDays' + PropertyType = '[uint32]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'AutoApproveAffinity' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'AllowUserAffinity' + PropertyType = '[bool]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'DependsOn' + PropertyType = '[string]' + IsMandatory = $false + Values = '{}' + } + @{ + Name = 'PsDscRunAsCredential' + PropertyType = '[PSCredential]' + IsMandatory = $false + Values = '{}' + } + ) + } @{ ImplementedAs = 'PowerShell' Name = 'CMClientStatusSettings' @@ -3800,80 +5266,518 @@ InModuleScope $script:subModuleName { ) } - $getUserDiscoveryDisabled = @{ - SiteCode = 'Lab' - Props = @( - @{ - PropertyName = 'Settings' - Value1 = 'INACTIVE' - } - ) + $getUserDiscoveryDisabled = @{ + SiteCode = 'Lab' + Props = @( + @{ + PropertyName = 'Settings' + Value1 = 'INACTIVE' + } + ) + } + + $invokeUserDiscoveryEnabled = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ADContainers = @('LDAP://OU=DC,DC=contoso,DC=com') + ADContainersToExclude = $null + ADContainersToInclude = $null + DeltaDiscoveryMins = 30 + Enabled = $true + EnableDeltaDiscovery = $true + ScheduleCount = 40 + ScheduleInterval = 'Minutes' + SiteCode = 'Lab' + PSComputerName = 'localhost' + } + + $invokeUserDiscoveryDisabled = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ADContainers = $null + ADContainersToExclude = $null + ADContainersToInclude = $null + DeltaDiscoveryMins = $null + Enabled = $false + EnableDeltaDiscovery = $false + ScheduleCount = $null + ScheduleInterval = $null + SiteCode = 'Lab' + PSComputerName = 'localhost' + } + + $testAll = @{ + SiteCode = 'Lab' + Include = 'All' + Exclude = @('PullDistributionPoint','PxeDistributionPoint','SiteMaintenance', + 'BoundaryGroups','MaintenanceWindow') + DataFile = 'TestDrive:\tmp.psd1' + ConfigOutputPath = 'TestDrive:\temp.ps1' + MofOutPutPath = 'TestDrive:\' + } + + $maintenanceWindow = @{ + SiteCode = 'Lab' + Include = 'MaintenanceWindow' + } + + $getCMMaintenanceWindow = @{ + IsEnabled = $true + IsGMT = $false + Name = 'WeeklyMW' + RecurrenceType = 2 + ServiceWindowType = 5 + } + + $invokeCMMaintenanceWindows = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + CollectionName = 'TestCollection' + CollectionStatus = 'Present' + DayOfMonth = $null + DayOfWeek = 'Tuesday' + Description = 'Occurs every 1 weeks on Tuesday effective 2/1/2021 12:00 AM' + Ensure = 'Present' + HourDuration = 1 + IsEnabled = $true + MinuteDuration = $null + MonthlyWeekOrder = $null + Name = 'Test' + RecurInterval = 1 + ScheduleType = 'Weekly' + ServiceWindowsType = 'Any' + SiteCode = 'Lab' + Start = '2/1/2021 00:00' + PSComputerName = 'localhost' + } + + $boundaryGroup = @{ + SiteCode = 'Lab' + Include = 'BoundaryGroups' + } + + $getCMBoundaryGroup = @{ + Name = 'TestBoundary' + } + + $invokeCMBoundaryGroup = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + BoundaryGroup = 'TestBoundary' + Ensure = 'Present' + SecurityScopes = @('Default') + SecurityScopesToExclude = $null + SecurityScopesToInclude = $null + SiteCode = 'Lab' + PSComputerName = 'localhost' + } + + $configFileOnly = @{ + SiteCode = 'Lab' + Include = 'ConfigFileOnly' + DataFile = 'TestDrive:\tmp.psd1' + ConfigOutputPath = 'TestDrive:\temp.ps1' + MofOutPutPath = 'TestDrive:\' + } + + $getCMClientSettingsDefault = @( + @{ + Name = 'Default Client Agent Settings' + Type = 0 + } + ) + + $getCMClientSettingsDevice = @( + @{ + Name = 'ClientTest' + Type = 1 + } + ) + + $getCMClientSettingsUser = @( + @{ + Name = 'TestUser' + Type = 2 + } + ) + + $clientSettingsDevice = @{ + SiteCode = 'Lab' + Include = 'ClientSettings' + } + + $invokeCMClientSettings = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'ClientTest' + Description = 'Test Client Policy' + Ensure = 'Present' + SecurityScopes = @('Scope1','Scope2') + SecurityScopesToInclude = $null + SecurityScopesToExclude = $null + Type = 'Device' + SiteCode = 'Lab' + PSComputerName = 'localhost' + } + + $invokeCMClientSettingsBits = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'Default Client Agent Settings' + EnableBitsMaxBandwidth = $true + MaxBandwidthBeginHr = 1 + MaxBandwidthEndHr = 23 + MaxTransferRateOnSchedule = 100 + EnableDownloadOffSchedule = $true + MaxTransferRateOffSchedule = 1000 + ClientSettingStatus = 'Present' + ClientType = 'Default' + SiteCode = 'Lab' + PSComputerName = 'localhost' + } + + $invokeCMClientSettingsClientCache = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'Default Client Agent Settings' + ConfigureBranchCache = $true + EnableBranchCache = $true + MaxBranchCacheSizePercent = 20 + ConfigureCacheSize = $true + MaxCacheSize = 1048576 + MaxCacheSizePercent = 80 + EnableSuperPeer = $true + BroadcastPort = 8006 + DownloadPort = 8003 + ClientSettingStatus = 'Present' + ClientType = 'Default' + SiteCode = 'Lab' + PSComputerName = 'localhost' + } + + $invokeCMClientSettingsClientPolicy = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'Default Client Agent Settings' + PolicyPollingMins = 60 + EnableUserPolicy = $true + EnableUserPolicyOnInternet = $false + EnableUserPolicyOnTS = $true + ClientSettingStatus = 'Present' + ClientType = 'Default' + SiteCode = 'Lab' + PSComputerName = 'localhost' + } + + $invokeCMClientSettingsCloudService = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'Default Client Agent Settings' + AllowCloudDistributionPoint = $true + AutoAzureADJoin = $true + AllowCloudManagementGateway = $true + ClientSettingStatus = 'Present' + ClientType = 'Default' + SiteCode = 'Lab' + PSComputerName = 'localhost' + } + + $clientSettingsCloudUser = @{ + SiteCode = 'Lab' + Include = 'ClientSettingsCloudService' + } + + $invokeCMClientSettingsCloudServiceUser = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'TestUser' + AllowCloudDistributionPoint = $true + AutoAzureADJoin = $null + AllowCloudManagementGateway = $null + ClientSettingStatus = 'Present' + ClientType = 'User' + SiteCode = 'Lab' + PSComputerName = 'localhost' + } + + $invokeCMClientSettingsCompliance = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + EnableUserDataAndProfile = $true + Start = '9/21/2021 16:54' + ScheduleType = 'MonthlyByDay' + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = 0 + RecurInterval = 1 + ClientSettingStatus = 'Present' + ClientType = 'Default' + SiteCode = 'Lab' + PSComputerName = 'localhost' + } + + $invokeCMClientSettingsComputerAgent = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'Default Client Agent Settings' + InitialReminderHr = 5 + InterimReminderHr = 1 + FinalReminderMins = 20 + BrandingTitle = 'Test Client' + UseNewSoftwareCenter = $true + EnableHealthAttestation = $true + UseOnPremisesHealthAttestation = $true + InstallRestriction = 'OnlyAdministrators' + SuspendBitLocker = 'Never' + EnableThirdPartyOrchestration = 'Yes' + PowerShellExecutionPolicy = 'Bypass' + DisplayNewProgramNotification = $true + ClientSettingStatus = 'Present' + ClientType = 'Default' + SiteCode = 'Lab' + PSComputerName = 'localhost' + } + + $invokeCMClientSettingsDelivery = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + ClientSettingStatus = 'Present' + ClientType = 'Default' + SiteCode = 'Lab' + PSComputerName = 'localhost' + } + + $invokeCMClientSettingsHardwareDefault = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + MaxRandomDelayMins = 30 + Start = '9/21/2021 16:54' + ScheduleType = 'MonthlyByDay' + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = 0 + RecurInterval = 1 + CollectMifFile = 'None' + MaxThirdPartyMifSize = 5119 + ClientSettingStatus = 'Present' + ClientType = 'Default' + SiteCode = 'Lab' + PSComputerName = 'localhost' + } + + $clientSettingsHardwareDevice = @{ + SiteCode = 'Lab' + Include = 'ClientSettingsHardware' + } + + $invokeCMClientSettingsHardwareDevice = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'ClientTest' + Enable = $true + MaxRandomDelayMins = 30 + Start = '9/21/2021 16:54' + ScheduleType = 'MonthlyByDay' + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = 0 + RecurInterval = 1 + ClientSettingStatus = 'Present' + ClientType = 'Device' + SiteCode = 'Lab' + PSComputerName = 'localhost' + } + + $invokeCMClientSettingsMetered = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'Default Client Agent Settings' + MeteredNetworkUsage = 'Allow' + ClientSettingStatus = 'Present' + ClientType = 'Default' + SiteCode = 'Lab' + PSComputerName = 'localhost' } - $invokeUserDiscoveryEnabled = @{ - ConfigurationName = $null - DependsOn = $null - ModuleName = 'ConfigMgrCBDsc' - ModuleVersion = 1.0.1 - PsDscRunAsCredential = $null - ResourceId = $null - SourceInfo = $null - ADContainers = @('LDAP://OU=DC,DC=contoso,DC=com') - ADContainersToExclude = $null - ADContainersToInclude = $null - DeltaDiscoveryMins = 30 - Enabled = $true - EnableDeltaDiscovery = $true - ScheduleCount = 40 - ScheduleInterval = 'Minutes' - SiteCode = 'Lab' - PSComputerName = 'localhost' + $invokeCMClientSettingsPower = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + AllowUserToOptOutFromPowerPlan = $false + NetworkWakeUpOption = 'Enabled' + EnableWakeUpProxy = $true + WakeupProxyPort = 51 + WakeOnLanPort = 50 + FirewallExceptionForWakeupProxy = 'None' + WakeupProxyDirectAccessPrefix = $null + ClientSettingStatus = 'Present' + ClientType = 'Default' + SiteCode = 'Lab' + PSComputerName = 'localhost' } - $invokeUserDiscoveryDisabled = @{ - ConfigurationName = $null - DependsOn = $null - ModuleName = 'ConfigMgrCBDsc' - ModuleVersion = 1.0.1 - PsDscRunAsCredential = $null - ResourceId = $null - SourceInfo = $null - ADContainers = $null - ADContainersToExclude = $null - ADContainersToInclude = $null - DeltaDiscoveryMins = $null - Enabled = $false - EnableDeltaDiscovery = $false - ScheduleCount = $null - ScheduleInterval = $null - SiteCode = 'Lab' - PSComputerName = 'localhost' + $getCMClientSettingRemoteTools = @{ + FirewallExceptionProfiles = 12 } - $testAll = @{ - SiteCode = 'Lab' - Include = 'All' - Exclude = @('PullDistributionPoint','PxeDistributionPoint','SiteMaintenance', - 'BoundaryGroups','MaintenanceWindow') - DataFile = 'TestDrive:\tmp.psd1' - ConfigOutputPath = 'TestDrive:\temp.ps1' - MofOutPutPath = 'TestDrive:\' + $invokeCMClientSettingsRemoteTools = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'Default Client Agent Settings' + FirewallExceptionProfile = 'Domain' + AllowClientChange = $true + AllowUnattendedComputer = $true + PromptUserForPermission = $true + PromptUserForClipboardPermission = $true + GrantPermissionToLocalAdministrator = $true + AccessLevel = 'FullControl' + PermittedViewer = @('Group1','Group2') + ShowNotificationIconOnTaskbar = $true + ShowSessionConnectionBar = $true + AudibleSignal = 'PlayNoSound' + ManageUnsolicitedRemoteAssistance = $true + ManageSolicitedRemoteAssistance = $true + RemoteAssistanceAccessLevel = 'FullControl' + ManageRemoteDesktopSetting = $true + AllowPermittedViewer = $true + RequireAuthentication = $true + ClientSettingStatus = 'Present' + ClientType = 'Default' + RemoteToolsStatus = 'Enabled' + SiteCode = 'Lab' + PSComputerName = 'localhost' } - $maintenanceWindow = @{ - SiteCode = 'Lab' - Include = 'MaintenanceWindow' + $getCMClientSettingSoftwareCenter = @{ + SC_UserPortal = 0 } - $getCMMaintenanceWindow = @{ - IsEnabled = $true - IsGMT = $false - Name = 'WeeklyMW' - RecurrenceType = 2 - ServiceWindowType = 5 + $invokeCMClientSettingsSoftwareCenter = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'Default Client Agent Settings' + EnableCustomize = $true + CompanyName = 'Test Company' + ColorScheme = '#CB4154' + HideApplicationCatalogLink = $true + HideInstalledApplication = $true + HideUnapprovedApplication = $true + EnableApplicationsTab = $true + EnableUpdatesTab = $true + EnableOperatingSystemsTab = $true + EnableStatusTab = $true + EnableComplianceTab = $true + EnableOptionsTab = $true + ClientSettingStatus = 'Present' + ClientType = 'Default' + PortalType = 'Software Center' + SiteCode = 'Lab' + PSComputerName = 'localhost' } - $invokeCMMaintenanceWindows = @{ + $invokeCMClientSettingsSoftwareDeployment = @{ ConfigurationName = $null DependsOn = $null ModuleName = 'ConfigMgrCBDsc' @@ -3881,35 +5785,65 @@ InModuleScope $script:subModuleName { PsDscRunAsCredential = $null ResourceId = $null SourceInfo = $null - CollectionName = 'TestCollection' - CollectionStatus = 'Present' - DayOfMonth = $null - DayOfWeek = 'Tuesday' - Description = 'Occurs every 1 weeks on Tuesday effective 2/1/2021 12:00 AM' - Ensure = 'Present' - HourDuration = 1 - IsEnabled = $true - MinuteDuration = $null + ClientSettingName = 'Default Client Agent Settings' + Start = '9/21/2021 16:54' + ScheduleType = 'MonthlyByDay' + DayOfWeek = $null MonthlyWeekOrder = $null - Name = 'Test' + DayofMonth = 0 RecurInterval = 1 - ScheduleType = 'Weekly' - ServiceWindowsType = 'Any' + ClientSettingStatus = 'Present' + ClientType = 'Default' SiteCode = 'Lab' - Start = '2/1/2021 00:00' PSComputerName = 'localhost' } - $boundaryGroup = @{ - SiteCode = 'Lab' - Include = 'BoundaryGroups' + $invokeCMClientSettingsSoftwareInventory = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + ReportOption = 'ProductOnly' + Start = '9/21/2021 16:54' + ScheduleType = 'MonthlyByDay' + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = 0 + RecurInterval = 1 + ClientSettingStatus = 'Present' + ClientType = 'Default' + SiteCode = 'Lab' + PSComputerName = 'localhost' } - $getCMBoundaryGroup = @{ - Name = 'TestBoundary' + $invokeCMClientSettingsSoftwareMetering = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + Start = '9/21/2021 16:54' + ScheduleType = 'MonthlyByDay' + DayOfWeek = $null + MonthlyWeekOrder = $null + DayofMonth = 0 + RecurInterval = 1 + ClientSettingStatus = 'Present' + ClientType = 'Default' + SiteCode = 'Lab' + PSComputerName = 'localhost' } - $invokeCMBoundaryGroup = @{ + $invokeCMClientSettingsSoftwareUpdate = @{ ConfigurationName = $null DependsOn = $null ModuleName = 'ConfigMgrCBDsc' @@ -3917,21 +5851,66 @@ InModuleScope $script:subModuleName { PsDscRunAsCredential = $null ResourceId = $null SourceInfo = $null - BoundaryGroup = 'TestBoundary' - Ensure = 'Present' - SecurityScopes = @('Default') - SecurityScopesToExclude = $null - SecurityScopesToInclude = $null + ClientSettingName = 'Default Client Agent Settings' + Enable = $true + ScanStart = '9/21/2021 16:54' + ScanScheduleType = 'MonthlyByDay' + ScanDayOfWeek = $null + ScanMonthlyWeekOrder = $null + ScanDayofMonth = 0 + ScanRecurInterval = 1 + EvalStart = '9/21/2021 16:54' + EvalScheduleType = 'Hours' + EvalDayOfWeek = $null + EvalMonthlyWeekOrder = $null + EvalDayofMonth = $null + EvalRecurInterval = 1 + EnforceMandatory = $true + TimeUnit = 'Days' + BatchingTimeOut = 2 + EnableDeltaDownload = $true + DeltaDownloadPort = 8005 + Office365ManagementType = 'Yes' + EnableThirdPartyUpdates = $true + ClientSettingStatus = 'Present' + ClientType = 'Default' SiteCode = 'Lab' PSComputerName = 'localhost' } - $configFileOnly = @{ - SiteCode = 'Lab' - Include = 'ConfigFileOnly' - DataFile = 'TestDrive:\tmp.psd1' - ConfigOutputPath = 'TestDrive:\temp.ps1' - MofOutPutPath = 'TestDrive:\' + $invokeCMClientSettingsStateMessaging = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'Default Client Agent Settings' + ReportingCycleMins = 100 + ClientSettingStatus = 'Present' + ClientType = 'Default' + SiteCode = 'Lab' + PSComputerName = 'localhost' + } + + $invokeCMClientSettingsUserDeviceAffinity = @{ + ConfigurationName = $null + DependsOn = $null + ModuleName = 'ConfigMgrCBDsc' + ModuleVersion = 1.0.1 + PsDscRunAsCredential = $null + ResourceId = $null + SourceInfo = $null + ClientSettingName = 'Default Client Agent Settings' + LogOnThresholdMins = 100 + UsageThresholdDays = 10 + AutoApproveAffinity = $true + AllowUserAffinity = $true + ClientSettingStatus = 'Present' + ClientType = 'Default' + SiteCode = 'Lab' + PSComputerName = 'localhost' } } @@ -3942,6 +5921,7 @@ InModuleScope $script:subModuleName { Mock -CommandName Get-CMAccount -MockWith { $cmAccounts } Mock -CommandName Get-CMAdministrativeUser -MockWith { $cmAdministrativeUsers } Mock -CommandName Get-CMAssetIntelligenceSynchronizationPoint -MockWith { $cmAssetIntellReturn } + Mock -CommandName Get-CMClientSetting Mock -CommandName Get-CMCollection -MockWith { $deviceCollectionsReturn } -ParameterFilter {$CollectionType -match 'Device'} Mock -CommandName Get-CMCollection -MockWith { $userCollectionsReturn } -ParameterFilter {$CollectionType -match 'User' } Mock -CommandName Get-CMDistributionPointGroup -MockWith { $distributionGroupReturn } @@ -4008,13 +5988,35 @@ InModuleScope $script:subModuleName { Mock -CommandName Get-CMDiscoveryMethod -MockWith { $getSystemDiscoveryEnabled } -ParameterFilter { $Name -eq 'ActiveDirectorySystemDiscovery' } Mock -CommandName Invoke-DscResource -MockWith { $invokeUserDiscoveryEnabled } -ParameterFilter { $Name -eq 'CMUserDiscovery' } Mock -CommandName Get-CMDiscoveryMethod -MockWith { $getUserDiscoveryEnabled } -ParameterFilter { $Name -eq 'ActiveDirectoryUserDiscovery' } + Mock -CommandName Get-CMClientSetting -MockWith { $getCMClientSettingsDefault } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsBits } -ParameterFilter { $Name -eq 'CMClientSettingsBits' } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsClientCache } -ParameterFilter { $Name -eq 'CMClientSettingsClientCache' } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsClientPolicy } -ParameterFilter { $Name -eq 'CMClientSettingsClientPolicy' } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsCloudService } -ParameterFilter { $Name -eq 'CMClientSettingsCloudService' } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsCompliance } -ParameterFilter { $Name -eq 'CMClientSettingsCompliance' } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsComputerAgent } -ParameterFilter { $Name -eq 'CMClientSettingsComputerAgent' } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsDelivery } -ParameterFilter { $Name -eq 'CMClientSettingsDelivery' } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsHardwareDefault } -ParameterFilter { $Name -eq 'CMClientSettingsHardware' } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsMetered } -ParameterFilter { $Name -eq 'CMClientSettingsMetered' } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsPower } -ParameterFilter { $Name -eq 'CMClientSettingsPower' } + Mock -CommandName Get-CMClientSetting -MockWith { $getCMClientSettingRemoteTools } -ParameterFilter { $Setting -eq 'RemoteTools' } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsRemoteTools } -ParameterFilter { $Name -eq 'CMClientSettingsRemoteTools' } + Mock -CommandName Get-CMClientSetting -MockWith { $getCMClientSettingSoftwareCenter } -ParameterFilter { $Setting -eq 'SoftwareCenter' } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsSoftwareCenter } -ParameterFilter { $Name -eq 'CMClientSettingsSoftwareCenter' } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsSoftwareDeployment } -ParameterFilter { $Name -eq 'CMClientSettingsSoftwareDeployment' } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsSoftwareInventory } -ParameterFilter { $Name -eq 'CMClientSettingsSoftwareInventory' } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsSoftwareMetering } -ParameterFilter { $Name -eq 'CMClientSettingsSoftwareMetering' } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsUpdate } -ParameterFilter { $Name -eq 'CMClientSettingsSoftwareUpdate' } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsStateMessaging } -ParameterFilter { $Name -eq 'CMClientSettingsStateMessaging' } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsUserDeviceAffinity } -ParameterFilter { $Name -eq 'CMClientSettingsUserDeviceAffinity' } $result = Set-ConfigMgrCBDscReverse @testAll $result | Should -BeOfType System.String Assert-MockCalled Get-CMAccount -Exactly -Times 1 -Scope It - Assert-MockCalled Invoke-DscResource -Exactly -Times 28 -Scope It + Assert-MockCalled Invoke-DscResource -Exactly -Times 46 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 1 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 19 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 2 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 1 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 2 -Scope It @@ -4049,6 +6051,7 @@ InModuleScope $script:subModuleName { Assert-MockCalled Invoke-DscResource -Exactly -Times 1 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It @@ -4082,6 +6085,7 @@ InModuleScope $script:subModuleName { Assert-MockCalled Invoke-DscResource -Exactly -Times 1 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It @@ -4115,6 +6119,7 @@ InModuleScope $script:subModuleName { Assert-MockCalled Invoke-DscResource -Exactly -Times 1 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It @@ -4148,6 +6153,7 @@ InModuleScope $script:subModuleName { Assert-MockCalled Invoke-DscResource -Exactly -Times 1 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It @@ -4181,6 +6187,7 @@ InModuleScope $script:subModuleName { Assert-MockCalled Invoke-DscResource -Exactly -Times 1 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It @@ -4214,6 +6221,7 @@ InModuleScope $script:subModuleName { Assert-MockCalled Invoke-DscResource -Exactly -Times 1 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It @@ -4247,6 +6255,7 @@ InModuleScope $script:subModuleName { Assert-MockCalled Invoke-DscResource -Exactly -Times 1 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It @@ -4280,6 +6289,7 @@ InModuleScope $script:subModuleName { Assert-MockCalled Invoke-DscResource -Exactly -Times 19 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It @@ -4313,6 +6323,7 @@ InModuleScope $script:subModuleName { Assert-MockCalled Invoke-DscResource -Exactly -Times 43 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It @@ -4346,6 +6357,7 @@ InModuleScope $script:subModuleName { Assert-MockCalled Invoke-DscResource -Exactly -Times 43 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It @@ -4379,6 +6391,7 @@ InModuleScope $script:subModuleName { Assert-MockCalled Invoke-DscResource -Exactly -Times 43 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It @@ -4412,6 +6425,7 @@ InModuleScope $script:subModuleName { Assert-MockCalled Invoke-DscResource -Exactly -Times 43 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It @@ -4445,6 +6459,7 @@ InModuleScope $script:subModuleName { Assert-MockCalled Invoke-DscResource -Exactly -Times 1 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It @@ -4478,6 +6493,7 @@ InModuleScope $script:subModuleName { Assert-MockCalled Invoke-DscResource -Exactly -Times 1 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It @@ -4511,6 +6527,7 @@ InModuleScope $script:subModuleName { Assert-MockCalled Invoke-DscResource -Exactly -Times 1 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It @@ -4544,6 +6561,7 @@ InModuleScope $script:subModuleName { Assert-MockCalled Invoke-DscResource -Exactly -Times 1 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It @@ -4579,6 +6597,7 @@ InModuleScope $script:subModuleName { Assert-MockCalled Invoke-DscResource -Exactly -Times 1 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 1 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It @@ -4612,6 +6631,7 @@ InModuleScope $script:subModuleName { Assert-MockCalled Invoke-DscResource -Exactly -Times 1 -Scope It Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It @@ -4633,6 +6653,108 @@ InModuleScope $script:subModuleName { Assert-MockCalled New-Configuration -Exactly -Times 0 -Scope It } + It 'Should return expected results and call expected commands for CMClientSettings' { + Mock -CommandName Get-DscResource -MockWith { $getDscResourceReturn } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettings } -ParameterFilter { $Name -eq 'CMClientSettings'} + Mock -CommandName Get-CMClientSetting -MockWith { $getCMClientSettingsDevice } + + $result = Set-ConfigMgrCBDscReverse @clientSettingsDevice + $result | Should -BeOfType System.String + $result | Should -Match "CMClientSettings" + Assert-MockCalled Get-CMAccount -Exactly -Times 0 -Scope It + Assert-MockCalled Invoke-DscResource -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMFallbackStatusPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMDiscoveryMethod -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMManagementPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMDistributionPointInfo -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMReportingServicePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMServiceConnectionPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMSiteDefinition -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMSiteSystemServer -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMSoftwareUpdatePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMMaintenanceWindow -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMBoundaryGroup -Exactly -Times 0 -Scope It + Assert-MockCalled Test-Path -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-Item -Exactly -Times 0 -Scope It + Assert-MockCalled Add-Content -Exactly -Times 0 -Scope It + Assert-MockCalled New-Configuration -Exactly -Times 0 -Scope It + } + + It 'Should return expected results and call expected commands for CMClientSettingsCloud User' { + Mock -CommandName Get-DscResource -MockWith { $getDscResourceReturn } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsCloudServiceUser } -ParameterFilter { $Name -eq 'CMClientSettingsCloudService'} + Mock -CommandName Get-CMClientSetting -MockWith { $getCMClientSettingsUser } + + $result = Set-ConfigMgrCBDscReverse @clientSettingsCloudUser + $result | Should -BeOfType System.String + $result | Should -Match "CMClientSettingsCloudService" + Assert-MockCalled Get-CMAccount -Exactly -Times 0 -Scope It + Assert-MockCalled Invoke-DscResource -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 2 -Scope It + Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMFallbackStatusPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMDiscoveryMethod -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMManagementPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMDistributionPointInfo -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMReportingServicePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMServiceConnectionPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMSiteDefinition -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMSiteSystemServer -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMSoftwareUpdatePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMMaintenanceWindow -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMBoundaryGroup -Exactly -Times 0 -Scope It + Assert-MockCalled Test-Path -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-Item -Exactly -Times 0 -Scope It + Assert-MockCalled Add-Content -Exactly -Times 0 -Scope It + Assert-MockCalled New-Configuration -Exactly -Times 0 -Scope It + } + + It 'Should return expected results and call expected commands for CMClientSettingsHardware device' { + Mock -CommandName Get-DscResource -MockWith { $getDscResourceReturn } + Mock -CommandName Invoke-DscResource -MockWith { $invokeCMClientSettingsHardwareDevice } -ParameterFilter { $Name -eq 'CMClientSettingsHardware'} + Mock -CommandName Get-CMClientSetting -MockWith { $getCMClientSettingsDevice } + + $result = Set-ConfigMgrCBDscReverse @clientSettingsHardwareDevice + $result | Should -BeOfType System.String + $result | Should -Match "CMClientSettingsHardware" + Assert-MockCalled Get-CMAccount -Exactly -Times 0 -Scope It + Assert-MockCalled Invoke-DscResource -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMAdministrativeUser -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMAssetIntelligenceSynchronizationPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMClientSetting -Exactly -Times 2 -Scope It + Assert-MockCalled Get-CMCollection -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMDistributionPointGroup -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMDistributionPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMFallbackStatusPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMDiscoveryMethod -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMManagementPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMDistributionPointInfo -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMReportingServicePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMSecurityScope -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMServiceConnectionPoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMSiteDefinition -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMSiteSystemServer -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMSoftwareUpdatePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMMaintenanceWindow -Exactly -Times 0 -Scope It + Assert-MockCalled Get-CMBoundaryGroup -Exactly -Times 0 -Scope It + Assert-MockCalled Test-Path -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-Item -Exactly -Times 0 -Scope It + Assert-MockCalled Add-Content -Exactly -Times 0 -Scope It + Assert-MockCalled New-Configuration -Exactly -Times 0 -Scope It + } + It 'Should return expected results and call expected commands for ConfigFileOnly' { Mock -CommandName Get-DscResource Mock -CommandName Invoke-DscResource diff --git a/tests/Unit/Stubs/ConfigMgrCBDscStub.psm1 b/tests/Unit/Stubs/ConfigMgrCBDscStub.psm1 index 252af451..d0759294 100644 --- a/tests/Unit/Stubs/ConfigMgrCBDscStub.psm1 +++ b/tests/Unit/Stubs/ConfigMgrCBDscStub.psm1 @@ -35811,6 +35811,9 @@ function Set-CMClientSettingClientPolicy [bool] ${EnableUserPolicyOnInternet}, + [bool] + ${EnableUserPolicyOnTS}, + [Parameter(ParameterSetName='SetDefaultSetting', Mandatory=$true)] [switch] ${DefaultSetting}, @@ -35888,7 +35891,6 @@ function Set-CMClientSettingComplianceSetting ( [Parameter(ParameterSetName='SetDefaultSetting')] [Alias('EvaluationSchedule')] - [PSTypeName('IResultObject#SMS_ScheduleToken')] [System.Object] ${Schedule}, @@ -36288,7 +36290,6 @@ function Set-CMClientSettingHardwareInventory ${Enable}, [Alias('InventorySchedule','HardwareInventorySchedule')] - [PSTypeName('IResultObject#SMS_ScheduleToken')] [System.Object] ${Schedule}, @@ -36402,6 +36403,9 @@ function Set-CMClientSettingPowerManagement [bool] ${EnableWakeupProxy}, + [string] + ${NetworkWakeupOption}, + [ValidateRange(1, 65535)] [int] ${WakeupProxyPort}, @@ -36545,7 +36549,7 @@ function Set-CMClientSettingSoftwareCenter [string] ${CompanyName}, - [System.Drawing.Color] + [string] ${ColorScheme}, [string] @@ -36619,7 +36623,6 @@ function Set-CMClientSettingSoftwareDeployment param ( [Alias('EvaluationSchedule')] - [PSTypeName('IResultObject#SMS_ScheduleToken')] [System.Object] ${Schedule}, @@ -36661,7 +36664,6 @@ function Set-CMClientSettingSoftwareInventory ${Enable}, [Alias('InventorySchedule','SoftwareInventorySchedule')] - [PSTypeName('IResultObject#SMS_ScheduleToken')] [System.Object] ${Schedule}, @@ -36798,12 +36800,10 @@ function Set-CMClientSettingSoftwareUpdate ${Enable}, [ValidateNotNullOrEmpty()] - [PSTypeName('IResultObject#SMS_ScheduleToken')] [System.Object] ${ScanSchedule}, [ValidateNotNullOrEmpty()] - [PSTypeName('IResultObject#SMS_ScheduleToken')] [System.Object] ${DeploymentEvaluationSchedule}, @@ -36816,6 +36816,15 @@ function Set-CMClientSettingSoftwareUpdate [System.Nullable[bool]] ${Office365ManagementType}, + [System.Nullable[bool]] + ${EnableDeltaDownload}, + + [int] + ${DeltaDownloadPort}, + + [System.Nullable[bool]] + ${EnableThirdPartyUpdates}, + [Parameter(ParameterSetName='SetDefaultSetting', Mandatory=$true)] [switch] ${DefaultSetting},