From ccb9908360f0bd40fbc3843a040b834a9b37353d Mon Sep 17 00:00:00 2001 From: hkystar35 <32749858+hkystar35@users.noreply.github.com> Date: Fri, 12 Jun 2020 14:03:48 -0600 Subject: [PATCH 1/3] Update ConfigMgrClientHealth.ps1 Added Function Update-ConfigStaticXML Added Update-ConfigStaticXML to Logging Added latest Windows OS version builds --- ConfigMgrClientHealth.ps1 | 182 +++++++++++++++++++++++++------------- 1 file changed, 120 insertions(+), 62 deletions(-) diff --git a/ConfigMgrClientHealth.ps1 b/ConfigMgrClientHealth.ps1 index dc0bafd..216b81b 100644 --- a/ConfigMgrClientHealth.ps1 +++ b/ConfigMgrClientHealth.ps1 @@ -1,52 +1,62 @@ <# -.SYNOPSIS - ConfigMgr Client Health is a tool that validates and automatically fixes errors on Windows computers managed by Microsoft Configuration Manager. -.EXAMPLE - .\ConfigMgrClientHealth.ps1 -Config .\Config.Xml -.EXAMPLE - \\cm01.rodland.lab\ClientHealth$\ConfigMgrClientHealth.ps1 -Config \\cm01.rodland.lab\ClientHealth$\Config.Xml -Webservice https://cm01.rodland.lab/ConfigMgrClientHealth -.PARAMETER Config - A single parameter specifying the path to the configuration XML file. -.PARAMETER Webservice - A single parameter specifying the URI to the ConfigMgr Client Health Webservice. -.DESCRIPTION - ConfigMgr Client Health detects and fixes following errors: - * ConfigMgr client is not installed. - * ConfigMgr client is assigned the correct site code. - * ConfigMgr client is upgraded to current version if not at specified minimum version. - * ConfigMgr client not able to forward state messages to management point. - * ConfigMgr client stuck in provisioning mode. - * ConfigMgr client maximum log file size. - * ConfigMgr client cache size. - * Corrupt WMI. - * Services for ConfigMgr client is not running or disabled. - * Other services can be specified to start and run and specific state. - * Hardware inventory is running at correct schedule - * Group Policy failes to update registry.pol - * Pending reboot blocking updates from installing - * ConfigMgr Client Update Handler is working correctly with registry.pol - * Windows Update Agent not working correctly, causing client not to receive patches. - * Windows Update Agent missing patches that fixes known bugs. -.NOTES - You should run this with at least local administrator rights. It is recommended to run this script under the SYSTEM context. - - DO NOT GIVE USERS WRITE ACCESS TO THIS FILE. LOCK IT DOWN ! - - Author: Anders Rødland - Blog: https://www.andersrodland.com - Twitter: @AndersRodland -.LINK - Full documentation: https://www.andersrodland.com/configmgr-client-health/ + .SYNOPSIS + ConfigMgr Client Health is a tool that validates and automatically fixes errors on Windows computers managed by Microsoft Configuration Manager. + + .DESCRIPTION + ConfigMgr Client Health detects and fixes following errors: + * ConfigMgr client is not installed. + * ConfigMgr client is assigned the correct site code. + * ConfigMgr client is upgraded to current version if not at specified minimum version. + * ConfigMgr client not able to forward state messages to management point. + * ConfigMgr client stuck in provisioning mode. + * ConfigMgr client maximum log file size. + * ConfigMgr client cache size. + * Corrupt WMI. + * Services for ConfigMgr client is not running or disabled. + * Other services can be specified to start and run and specific state. + * Hardware inventory is running at correct schedule + * Group Policy failes to update registry.pol + * Pending reboot blocking updates from installing + * ConfigMgr Client Update Handler is working correctly with registry.pol + * Windows Update Agent not working correctly, causing client not to receive patches. + * Windows Update Agent missing patches that fixes known bugs. + + .PARAMETER Config + A single parameter specifying the path to the configuration XML file. + + .PARAMETER Webservice + A single parameter specifying the URI to the ConfigMgr Client Health Webservice. + + .PARAMETER UpdateConfigStaticXMLURL + URL for hosted static Config.xml for updates. When used, once script is finished, will attempt to download this file and replace or create a local copy for use on the next run. + + .EXAMPLE + .\ConfigMgrClientHealth.ps1 -Config .\Config.Xml + + .EXAMPLE + \\cm01.rodland.lab\ClientHealth$\ConfigMgrClientHealth.ps1 -Config \\cm01.rodland.lab\ClientHealth$\Config.Xml -Webservice https://cm01.rodland.lab/ConfigMgrClientHealth + + .NOTES + You should run this with at least local administrator rights. It is recommended to run this script under the SYSTEM context. + + DO NOT GIVE USERS WRITE ACCESS TO THIS FILE. LOCK IT DOWN ! + + Author: Anders Rødland + Blog: https://www.andersrodland.com + Twitter: @AndersRodland + + .LINK + Full documentation: https://www.andersrodland.com/configmgr-client-health/ #> - -[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact="Medium")] -param( - [Parameter(HelpMessage='Path to XML Configuration File')] - [ValidateScript({Test-Path -Path $_ -PathType Leaf})] - [ValidatePattern('.xml$')] - [string]$Config, - [Parameter(HelpMessage='URI to ConfigMgr Client Health Webservice')] - [string]$Webservice +[CmdletBinding(ConfirmImpact = 'Medium', + SupportsShouldProcess = $true)] +PARAM +( + [Parameter(HelpMessage = 'Path to XML Configuration File')][ValidatePattern('.xml$')][ValidateScript({ + Test-Path -Path $_ -PathType Leaf + })][string]$Config, + [Parameter(HelpMessage = 'URI to ConfigMgr Client Health Webservice')][string]$Webservice, + [ValidateNotNullOrEmpty()][ValidatePattern('.xml$')]$UpdateConfigStaticXMLURL ) Begin { @@ -422,6 +432,9 @@ Begin { 16299 {$OSName = $OSName + " 1709"} 17134 {$OSName = $OSName + " 1803"} 17763 {$OSName = $OSName + " 1809"} + 18362 {$OSName = $OSName + " 1903"} + 18363 {$OSName = $OSName + " 1909"} + 19041 {$OSName = $OSName + " 2004"} default {$OSName = $OSName + " Insider Preview"} } } @@ -509,14 +522,12 @@ Begin { finally { Write-Output $obj } } - Function Get-ClientMaxLogHistory { try { $obj = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\CCM\Logging\@Global').LogMaxHistory } catch { $obj = 0 } finally { Write-Output $obj } } - Function Get-Domain { try { if ($PowerShellVersion -ge 6) { $obj = (Get-CimInstance Win32_ComputerSystem).Domain } @@ -673,7 +684,6 @@ Begin { } } - Function Test-BITS { Param([Parameter(Mandatory=$true)]$Log) @@ -758,7 +768,6 @@ Begin { else { $log.ClientInstalledReason += " $Message" } } - function Get-PendingReboot { $result = @{ CBSRebootPending =$false @@ -1040,6 +1049,9 @@ Begin { 16299 {$OSName = $OSName + " 1709"} 17134 {$OSName = $OSName + " 1803"} 17763 {$OSName = $OSName + " 1809"} + 18362 {$OSName = $OSName + " 1903"} + 18363 {$OSName = $OSName + " 1909"} + 19041 {$OSName = $OSName + " 2004"} default {$OSName = $OSName + " Insider Preview"} } } @@ -1788,7 +1800,6 @@ Begin { else { Write-Host "SMSTSMgr: OK"} } - # Windows Service Functions Function Test-Services { Param([Parameter(Mandatory=$false)]$Xml, $log, $Webservice, $ProfileID) @@ -2047,7 +2058,6 @@ Begin { } } - Function Test-CCMSoftwareDistribution { # TODO Implement this function Get-WmiObject -Class CCM_SoftwareDistributionClientConfig @@ -2245,7 +2255,6 @@ Begin { catch { Write-Warning "PolicyPlatform: RecompilePolicyPlatform failed!" } } - # Get the clients SiteName in Active Directory Function Get-ClientSiteName { try { @@ -2479,7 +2488,6 @@ Begin { } } - # Gather info about the computer Function Get-Info { if ($PowerShellVersion -ge 6) { @@ -3059,6 +3067,7 @@ Begin { PatchLevel = $UBR ClientInstalledReason = $null RebootApp = $RebootApp + UpdateConfigStaticXMLURL = $null } Write-Output $obj # Write-Verbose "End New-LogObject" @@ -3169,7 +3178,7 @@ Begin { $logfile = $logfile = Get-LogFileName Test-LogFileHistory -Logfile $logfile $text = "<--- ConfigMgr Client Health Check starting --->" - $text += $log | Select-Object Hostname, Operatingsystem, Architecture, Build, Model, InstallDate, OSUpdates, LastLoggedOnUser, ClientVersion, PSVersion, PSBuild, SiteCode, Domain, MaxLogSize, MaxLogHistory, CacheSize, Certificate, ProvisioningMode, DNS, PendingReboot, LastBootTime, OSDiskFreeSpace, Services, AdminShare, StateMessages, WUAHandler, WMI, RefreshComplianceState, ClientInstalled, Version, Timestamp, HWInventory, SWMetering, BITS, ClientSettings, PatchLevel, ClientInstalledReason | Out-String + $text += $log | Select-Object Hostname, Operatingsystem, Architecture, Build, Model, InstallDate, OSUpdates, LastLoggedOnUser, ClientVersion, PSVersion, PSBuild, SiteCode, Domain, MaxLogSize, MaxLogHistory, CacheSize, Certificate, ProvisioningMode, DNS, PendingReboot, LastBootTime, OSDiskFreeSpace, Services, AdminShare, StateMessages, WUAHandler, WMI, RefreshComplianceState, ClientInstalled, Version, Timestamp, HWInventory, SWMetering, BITS, ClientSettings, PatchLevel, ClientInstalledReason, UpdateConfigStaticXMLURL | Out-String $text = $text.replace("`t","") $text = $text.replace(" ","") $text = $text.replace(" :",":") @@ -3215,10 +3224,52 @@ Begin { $SCCMLogJobs = New-Object System.Data.DataTable [Void]$SCCMLogJobs.Columns.Add("File") [Void]$SCCMLogJobs.Columns.Add("Text") - + + # Update local config.xml from URL + FUNCTION Update-ConfigStaticXML { + <# + .SYNOPSIS + Updates or creates local config.xml file using URL source to overwrite + + .DESCRIPTION + Updates or creates local config.xml file using URL source to overwrite + + .PARAMETER ConfigStaticXMLURL + A description of the XMLURL parameter. + + .EXAMPLE + PS C:\> Update-ConfigStaticXML -ConfigStaticXMLURL $value1 + + .NOTES + Additional information about the function. + #> + + [CmdletBinding()] + PARAM + ( + [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][ValidatePattern('.xml$')]$ConfigStaticXMLURL, + [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][system.io.fileinfo]$Destination + ) + TRY { + $request = Invoke-WebRequest -Uri $ConfigStaticXMLURL -ErrorAction SilentlyContinue + $URIvalid = $true + } + CATCH { + $URIvalid = $false + } + + IF ($URIvalid) { + Start-BitsTransfer -Source $ConfigStaticXMLURL -Destination $destination.FullName + $Log.UpdateConfigStaticXMLURL = $ConfigStaticXMLURL + } + ELSE { + $Log.UpdateConfigStaticXMLURL = '[URI invalid or unreachable]' + $ConfigStaticXMLURL + } + } + } -Process { +PROCESS { Write-Verbose "Starting precheck. Determing if script will run or not." # Veriy script is running with administrative priveleges. If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) @@ -3486,8 +3537,14 @@ End { $Date = Get-Date Set-RegistryValue -Path $RegistryKey -Name $LastRunRegistryValueName -Value $Date Write-Output "Setting last ran to $($Date)" - - if ($LocalLogging -like 'true') { + + # Update Config.xml from HTTP/S source + IF ($PSBoundParameters.ContainsKey('UpdateConfigStaticXMLURL')) { + Write-Output 'Updating local config.xml from supplied URL' + Update-ConfigStaticXML -ConfigStaticXMLURL $UpdateConfigStaticXMLURL -Destination "$(Join-Path ($global:ScriptPath) "Config.xml")" + } + + IF ($LocalLogging -like 'true') { Write-Output 'Updating local logfile with results' Update-LogFile -Log $log -Mode 'Local' } @@ -3505,6 +3562,7 @@ End { if ($PSBoundParameters.ContainsKey('Webservice')) { Write-Output 'Updating SQL database with results using webservice' Update-Webservice -URI $Webservice -Log $Log - } - Write-Verbose "Client Health script finished" + } + + Write-Verbose "Client Health script finished" } From b62738913151baac9624cb8eed0402c72cc5f301 Mon Sep 17 00:00:00 2001 From: hkystar35 <32749858+hkystar35@users.noreply.github.com> Date: Fri, 12 Jun 2020 14:16:57 -0600 Subject: [PATCH 2/3] Revert "Update ConfigMgrClientHealth.ps1" This reverts commit ccb9908360f0bd40fbc3843a040b834a9b37353d. --- ConfigMgrClientHealth.ps1 | 182 +++++++++++++------------------------- 1 file changed, 62 insertions(+), 120 deletions(-) diff --git a/ConfigMgrClientHealth.ps1 b/ConfigMgrClientHealth.ps1 index 216b81b..dc0bafd 100644 --- a/ConfigMgrClientHealth.ps1 +++ b/ConfigMgrClientHealth.ps1 @@ -1,62 +1,52 @@ <# - .SYNOPSIS - ConfigMgr Client Health is a tool that validates and automatically fixes errors on Windows computers managed by Microsoft Configuration Manager. - - .DESCRIPTION - ConfigMgr Client Health detects and fixes following errors: - * ConfigMgr client is not installed. - * ConfigMgr client is assigned the correct site code. - * ConfigMgr client is upgraded to current version if not at specified minimum version. - * ConfigMgr client not able to forward state messages to management point. - * ConfigMgr client stuck in provisioning mode. - * ConfigMgr client maximum log file size. - * ConfigMgr client cache size. - * Corrupt WMI. - * Services for ConfigMgr client is not running or disabled. - * Other services can be specified to start and run and specific state. - * Hardware inventory is running at correct schedule - * Group Policy failes to update registry.pol - * Pending reboot blocking updates from installing - * ConfigMgr Client Update Handler is working correctly with registry.pol - * Windows Update Agent not working correctly, causing client not to receive patches. - * Windows Update Agent missing patches that fixes known bugs. - - .PARAMETER Config - A single parameter specifying the path to the configuration XML file. - - .PARAMETER Webservice - A single parameter specifying the URI to the ConfigMgr Client Health Webservice. - - .PARAMETER UpdateConfigStaticXMLURL - URL for hosted static Config.xml for updates. When used, once script is finished, will attempt to download this file and replace or create a local copy for use on the next run. - - .EXAMPLE - .\ConfigMgrClientHealth.ps1 -Config .\Config.Xml - - .EXAMPLE - \\cm01.rodland.lab\ClientHealth$\ConfigMgrClientHealth.ps1 -Config \\cm01.rodland.lab\ClientHealth$\Config.Xml -Webservice https://cm01.rodland.lab/ConfigMgrClientHealth - - .NOTES - You should run this with at least local administrator rights. It is recommended to run this script under the SYSTEM context. - - DO NOT GIVE USERS WRITE ACCESS TO THIS FILE. LOCK IT DOWN ! - - Author: Anders Rødland - Blog: https://www.andersrodland.com - Twitter: @AndersRodland - - .LINK - Full documentation: https://www.andersrodland.com/configmgr-client-health/ +.SYNOPSIS + ConfigMgr Client Health is a tool that validates and automatically fixes errors on Windows computers managed by Microsoft Configuration Manager. +.EXAMPLE + .\ConfigMgrClientHealth.ps1 -Config .\Config.Xml +.EXAMPLE + \\cm01.rodland.lab\ClientHealth$\ConfigMgrClientHealth.ps1 -Config \\cm01.rodland.lab\ClientHealth$\Config.Xml -Webservice https://cm01.rodland.lab/ConfigMgrClientHealth +.PARAMETER Config + A single parameter specifying the path to the configuration XML file. +.PARAMETER Webservice + A single parameter specifying the URI to the ConfigMgr Client Health Webservice. +.DESCRIPTION + ConfigMgr Client Health detects and fixes following errors: + * ConfigMgr client is not installed. + * ConfigMgr client is assigned the correct site code. + * ConfigMgr client is upgraded to current version if not at specified minimum version. + * ConfigMgr client not able to forward state messages to management point. + * ConfigMgr client stuck in provisioning mode. + * ConfigMgr client maximum log file size. + * ConfigMgr client cache size. + * Corrupt WMI. + * Services for ConfigMgr client is not running or disabled. + * Other services can be specified to start and run and specific state. + * Hardware inventory is running at correct schedule + * Group Policy failes to update registry.pol + * Pending reboot blocking updates from installing + * ConfigMgr Client Update Handler is working correctly with registry.pol + * Windows Update Agent not working correctly, causing client not to receive patches. + * Windows Update Agent missing patches that fixes known bugs. +.NOTES + You should run this with at least local administrator rights. It is recommended to run this script under the SYSTEM context. + + DO NOT GIVE USERS WRITE ACCESS TO THIS FILE. LOCK IT DOWN ! + + Author: Anders Rødland + Blog: https://www.andersrodland.com + Twitter: @AndersRodland +.LINK + Full documentation: https://www.andersrodland.com/configmgr-client-health/ #> -[CmdletBinding(ConfirmImpact = 'Medium', - SupportsShouldProcess = $true)] -PARAM -( - [Parameter(HelpMessage = 'Path to XML Configuration File')][ValidatePattern('.xml$')][ValidateScript({ - Test-Path -Path $_ -PathType Leaf - })][string]$Config, - [Parameter(HelpMessage = 'URI to ConfigMgr Client Health Webservice')][string]$Webservice, - [ValidateNotNullOrEmpty()][ValidatePattern('.xml$')]$UpdateConfigStaticXMLURL + +[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact="Medium")] +param( + [Parameter(HelpMessage='Path to XML Configuration File')] + [ValidateScript({Test-Path -Path $_ -PathType Leaf})] + [ValidatePattern('.xml$')] + [string]$Config, + [Parameter(HelpMessage='URI to ConfigMgr Client Health Webservice')] + [string]$Webservice ) Begin { @@ -432,9 +422,6 @@ Begin { 16299 {$OSName = $OSName + " 1709"} 17134 {$OSName = $OSName + " 1803"} 17763 {$OSName = $OSName + " 1809"} - 18362 {$OSName = $OSName + " 1903"} - 18363 {$OSName = $OSName + " 1909"} - 19041 {$OSName = $OSName + " 2004"} default {$OSName = $OSName + " Insider Preview"} } } @@ -522,12 +509,14 @@ Begin { finally { Write-Output $obj } } + Function Get-ClientMaxLogHistory { try { $obj = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\CCM\Logging\@Global').LogMaxHistory } catch { $obj = 0 } finally { Write-Output $obj } } + Function Get-Domain { try { if ($PowerShellVersion -ge 6) { $obj = (Get-CimInstance Win32_ComputerSystem).Domain } @@ -684,6 +673,7 @@ Begin { } } + Function Test-BITS { Param([Parameter(Mandatory=$true)]$Log) @@ -768,6 +758,7 @@ Begin { else { $log.ClientInstalledReason += " $Message" } } + function Get-PendingReboot { $result = @{ CBSRebootPending =$false @@ -1049,9 +1040,6 @@ Begin { 16299 {$OSName = $OSName + " 1709"} 17134 {$OSName = $OSName + " 1803"} 17763 {$OSName = $OSName + " 1809"} - 18362 {$OSName = $OSName + " 1903"} - 18363 {$OSName = $OSName + " 1909"} - 19041 {$OSName = $OSName + " 2004"} default {$OSName = $OSName + " Insider Preview"} } } @@ -1800,6 +1788,7 @@ Begin { else { Write-Host "SMSTSMgr: OK"} } + # Windows Service Functions Function Test-Services { Param([Parameter(Mandatory=$false)]$Xml, $log, $Webservice, $ProfileID) @@ -2058,6 +2047,7 @@ Begin { } } + Function Test-CCMSoftwareDistribution { # TODO Implement this function Get-WmiObject -Class CCM_SoftwareDistributionClientConfig @@ -2255,6 +2245,7 @@ Begin { catch { Write-Warning "PolicyPlatform: RecompilePolicyPlatform failed!" } } + # Get the clients SiteName in Active Directory Function Get-ClientSiteName { try { @@ -2488,6 +2479,7 @@ Begin { } } + # Gather info about the computer Function Get-Info { if ($PowerShellVersion -ge 6) { @@ -3067,7 +3059,6 @@ Begin { PatchLevel = $UBR ClientInstalledReason = $null RebootApp = $RebootApp - UpdateConfigStaticXMLURL = $null } Write-Output $obj # Write-Verbose "End New-LogObject" @@ -3178,7 +3169,7 @@ Begin { $logfile = $logfile = Get-LogFileName Test-LogFileHistory -Logfile $logfile $text = "<--- ConfigMgr Client Health Check starting --->" - $text += $log | Select-Object Hostname, Operatingsystem, Architecture, Build, Model, InstallDate, OSUpdates, LastLoggedOnUser, ClientVersion, PSVersion, PSBuild, SiteCode, Domain, MaxLogSize, MaxLogHistory, CacheSize, Certificate, ProvisioningMode, DNS, PendingReboot, LastBootTime, OSDiskFreeSpace, Services, AdminShare, StateMessages, WUAHandler, WMI, RefreshComplianceState, ClientInstalled, Version, Timestamp, HWInventory, SWMetering, BITS, ClientSettings, PatchLevel, ClientInstalledReason, UpdateConfigStaticXMLURL | Out-String + $text += $log | Select-Object Hostname, Operatingsystem, Architecture, Build, Model, InstallDate, OSUpdates, LastLoggedOnUser, ClientVersion, PSVersion, PSBuild, SiteCode, Domain, MaxLogSize, MaxLogHistory, CacheSize, Certificate, ProvisioningMode, DNS, PendingReboot, LastBootTime, OSDiskFreeSpace, Services, AdminShare, StateMessages, WUAHandler, WMI, RefreshComplianceState, ClientInstalled, Version, Timestamp, HWInventory, SWMetering, BITS, ClientSettings, PatchLevel, ClientInstalledReason | Out-String $text = $text.replace("`t","") $text = $text.replace(" ","") $text = $text.replace(" :",":") @@ -3224,52 +3215,10 @@ Begin { $SCCMLogJobs = New-Object System.Data.DataTable [Void]$SCCMLogJobs.Columns.Add("File") [Void]$SCCMLogJobs.Columns.Add("Text") - - # Update local config.xml from URL - FUNCTION Update-ConfigStaticXML { - <# - .SYNOPSIS - Updates or creates local config.xml file using URL source to overwrite - - .DESCRIPTION - Updates or creates local config.xml file using URL source to overwrite - - .PARAMETER ConfigStaticXMLURL - A description of the XMLURL parameter. - - .EXAMPLE - PS C:\> Update-ConfigStaticXML -ConfigStaticXMLURL $value1 - - .NOTES - Additional information about the function. - #> - - [CmdletBinding()] - PARAM - ( - [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][ValidatePattern('.xml$')]$ConfigStaticXMLURL, - [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][system.io.fileinfo]$Destination - ) - TRY { - $request = Invoke-WebRequest -Uri $ConfigStaticXMLURL -ErrorAction SilentlyContinue - $URIvalid = $true - } - CATCH { - $URIvalid = $false - } - - IF ($URIvalid) { - Start-BitsTransfer -Source $ConfigStaticXMLURL -Destination $destination.FullName - $Log.UpdateConfigStaticXMLURL = $ConfigStaticXMLURL - } - ELSE { - $Log.UpdateConfigStaticXMLURL = '[URI invalid or unreachable]' + $ConfigStaticXMLURL - } - } - + } -PROCESS { +Process { Write-Verbose "Starting precheck. Determing if script will run or not." # Veriy script is running with administrative priveleges. If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) @@ -3537,14 +3486,8 @@ End { $Date = Get-Date Set-RegistryValue -Path $RegistryKey -Name $LastRunRegistryValueName -Value $Date Write-Output "Setting last ran to $($Date)" - - # Update Config.xml from HTTP/S source - IF ($PSBoundParameters.ContainsKey('UpdateConfigStaticXMLURL')) { - Write-Output 'Updating local config.xml from supplied URL' - Update-ConfigStaticXML -ConfigStaticXMLURL $UpdateConfigStaticXMLURL -Destination "$(Join-Path ($global:ScriptPath) "Config.xml")" - } - - IF ($LocalLogging -like 'true') { + + if ($LocalLogging -like 'true') { Write-Output 'Updating local logfile with results' Update-LogFile -Log $log -Mode 'Local' } @@ -3562,7 +3505,6 @@ End { if ($PSBoundParameters.ContainsKey('Webservice')) { Write-Output 'Updating SQL database with results using webservice' Update-Webservice -URI $Webservice -Log $Log - } - - Write-Verbose "Client Health script finished" + } + Write-Verbose "Client Health script finished" } From fb6b406e40d9724ed3bb5ede8327f47d6821a98d Mon Sep 17 00:00:00 2001 From: hkystar35 <32749858+hkystar35@users.noreply.github.com> Date: Fri, 12 Jun 2020 14:17:45 -0600 Subject: [PATCH 3/3] Update ConfigMgrClientHealth.ps1 Added Function Update-ConfigStaticXML Added Update-ConfigStaticXML to Logging Added latest Windows OS version builds --- ConfigMgrClientHealth.ps1 | 83 ++++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 15 deletions(-) diff --git a/ConfigMgrClientHealth.ps1 b/ConfigMgrClientHealth.ps1 index dc0bafd..38134d9 100644 --- a/ConfigMgrClientHealth.ps1 +++ b/ConfigMgrClientHealth.ps1 @@ -46,7 +46,8 @@ param( [ValidatePattern('.xml$')] [string]$Config, [Parameter(HelpMessage='URI to ConfigMgr Client Health Webservice')] - [string]$Webservice + [string]$Webservice, + [ValidateNotNullOrEmpty()][ValidatePattern('.xml$')]$UpdateConfigStaticXMLURL ) Begin { @@ -422,6 +423,9 @@ Begin { 16299 {$OSName = $OSName + " 1709"} 17134 {$OSName = $OSName + " 1803"} 17763 {$OSName = $OSName + " 1809"} + 18362 {$OSName = $OSName + " 1903"} + 18363 {$OSName = $OSName + " 1909"} + 19041 {$OSName = $OSName + " 2004"} default {$OSName = $OSName + " Insider Preview"} } } @@ -509,14 +513,12 @@ Begin { finally { Write-Output $obj } } - Function Get-ClientMaxLogHistory { try { $obj = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\CCM\Logging\@Global').LogMaxHistory } catch { $obj = 0 } finally { Write-Output $obj } } - Function Get-Domain { try { if ($PowerShellVersion -ge 6) { $obj = (Get-CimInstance Win32_ComputerSystem).Domain } @@ -673,7 +675,6 @@ Begin { } } - Function Test-BITS { Param([Parameter(Mandatory=$true)]$Log) @@ -758,7 +759,6 @@ Begin { else { $log.ClientInstalledReason += " $Message" } } - function Get-PendingReboot { $result = @{ CBSRebootPending =$false @@ -1040,6 +1040,9 @@ Begin { 16299 {$OSName = $OSName + " 1709"} 17134 {$OSName = $OSName + " 1803"} 17763 {$OSName = $OSName + " 1809"} + 18362 {$OSName = $OSName + " 1903"} + 18363 {$OSName = $OSName + " 1909"} + 19041 {$OSName = $OSName + " 2004"} default {$OSName = $OSName + " Insider Preview"} } } @@ -1788,7 +1791,6 @@ Begin { else { Write-Host "SMSTSMgr: OK"} } - # Windows Service Functions Function Test-Services { Param([Parameter(Mandatory=$false)]$Xml, $log, $Webservice, $ProfileID) @@ -2047,7 +2049,6 @@ Begin { } } - Function Test-CCMSoftwareDistribution { # TODO Implement this function Get-WmiObject -Class CCM_SoftwareDistributionClientConfig @@ -2245,7 +2246,6 @@ Begin { catch { Write-Warning "PolicyPlatform: RecompilePolicyPlatform failed!" } } - # Get the clients SiteName in Active Directory Function Get-ClientSiteName { try { @@ -2479,7 +2479,6 @@ Begin { } } - # Gather info about the computer Function Get-Info { if ($PowerShellVersion -ge 6) { @@ -3059,6 +3058,7 @@ Begin { PatchLevel = $UBR ClientInstalledReason = $null RebootApp = $RebootApp + UpdateConfigStaticXMLURL = $null } Write-Output $obj # Write-Verbose "End New-LogObject" @@ -3169,7 +3169,7 @@ Begin { $logfile = $logfile = Get-LogFileName Test-LogFileHistory -Logfile $logfile $text = "<--- ConfigMgr Client Health Check starting --->" - $text += $log | Select-Object Hostname, Operatingsystem, Architecture, Build, Model, InstallDate, OSUpdates, LastLoggedOnUser, ClientVersion, PSVersion, PSBuild, SiteCode, Domain, MaxLogSize, MaxLogHistory, CacheSize, Certificate, ProvisioningMode, DNS, PendingReboot, LastBootTime, OSDiskFreeSpace, Services, AdminShare, StateMessages, WUAHandler, WMI, RefreshComplianceState, ClientInstalled, Version, Timestamp, HWInventory, SWMetering, BITS, ClientSettings, PatchLevel, ClientInstalledReason | Out-String + $text += $log | Select-Object Hostname, Operatingsystem, Architecture, Build, Model, InstallDate, OSUpdates, LastLoggedOnUser, ClientVersion, PSVersion, PSBuild, SiteCode, Domain, MaxLogSize, MaxLogHistory, CacheSize, Certificate, ProvisioningMode, DNS, PendingReboot, LastBootTime, OSDiskFreeSpace, Services, AdminShare, StateMessages, WUAHandler, WMI, RefreshComplianceState, ClientInstalled, Version, Timestamp, HWInventory, SWMetering, BITS, ClientSettings, PatchLevel, ClientInstalledReason, UpdateConfigStaticXMLURL | Out-String $text = $text.replace("`t","") $text = $text.replace(" ","") $text = $text.replace(" :",":") @@ -3215,10 +3215,56 @@ Begin { $SCCMLogJobs = New-Object System.Data.DataTable [Void]$SCCMLogJobs.Columns.Add("File") [Void]$SCCMLogJobs.Columns.Add("Text") - + + # Update local config.xml from URL + FUNCTION Update-ConfigStaticXML { + <# + .SYNOPSIS + Updates or creates local config.xml file using URL source to overwrite + + .DESCRIPTION + Updates or creates local config.xml file using URL source to overwrite + + .PARAMETER ConfigStaticXMLURL + URL for staticaly hosted XML file + + .PARAMETER Destination + Destination file + + .EXAMPLE + Update-ConfigStaticXML -ConfigStaticXMLURL 'https://server.local/bin/config.xml' -Destination "$(Join-Path ($global:ScriptPath) "Config.xml")" + + .NOTES + Additional information about the function. + #> + + [CmdletBinding()] + PARAM + ( + [Parameter(Mandatory = $true)][ValidatePattern('.xml$')][ValidateNotNullOrEmpty()]$ConfigStaticXMLURL, + [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][system.io.fileinfo]$Destination + ) + + TRY { + $request = Invoke-WebRequest -Uri $ConfigStaticXMLURL -ErrorAction SilentlyContinue + $URIvalid = $true + } + CATCH { + $URIvalid = $false + } + + IF ($URIvalid) { + Start-BitsTransfer -Source $ConfigStaticXMLURL -Destination $destination.FullName + $Log.UpdateConfigStaticXMLURL = $ConfigStaticXMLURL + } + ELSE { + $Log.UpdateConfigStaticXMLURL = '[URI invalid or unreachable]' + $ConfigStaticXMLURL + } + } + } -Process { +PROCESS { Write-Verbose "Starting precheck. Determing if script will run or not." # Veriy script is running with administrative priveleges. If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) @@ -3486,7 +3532,13 @@ End { $Date = Get-Date Set-RegistryValue -Path $RegistryKey -Name $LastRunRegistryValueName -Value $Date Write-Output "Setting last ran to $($Date)" - + + # Update Config.xml from HTTP/S source + IF ($PSBoundParameters.ContainsKey('UpdateConfigStaticXMLURL')) { + Write-Output 'Updating local config.xml from supplied URL' + Update-ConfigStaticXML -ConfigStaticXMLURL $UpdateConfigStaticXMLURL -Destination "$(Join-Path ($global:ScriptPath) "Config.xml")" + } + if ($LocalLogging -like 'true') { Write-Output 'Updating local logfile with results' Update-LogFile -Log $log -Mode 'Local' @@ -3505,6 +3557,7 @@ End { if ($PSBoundParameters.ContainsKey('Webservice')) { Write-Output 'Updating SQL database with results using webservice' Update-Webservice -URI $Webservice -Log $Log - } - Write-Verbose "Client Health script finished" + } + + Write-Verbose "Client Health script finished" }