• About me…

ConfigMgr.nl

VMware, Automation and more

  • About me…

Powershell – Get SCCM Client info from WMI

06-06-2017 ConfigMgr Powershell SCCM Script No Comments

Last week I was busy with a deployment and this week the question came up “does every server have a SCCM client installed”. My first reaction was “yes” but after a close look at our SCCM sites I wasn’t sure. The problem I had was that there are multiple AD domains linked to multiple SCCM sites, so if one site showed ‘Client=No’ that didn’t mean the server didn’t have a client. It only meant that the server didn’t have a client in that particular site. So only looking at SCCM wouldn’t give me the answer.

What if I would use AD as a source for my search? Dump every computer object into a list and run through that list to obtain information about the client. The challenge with that approach was that AD contains computer objects that are not really computer objects… For instance, if you build a Failover Cluster the cluster itself creates a computer object and also the cluster resources use computer objects. So using AD as a starting point was of the table.

Another possible source was vCenter. As vCenter contains all the (virtual) servers I could use that as a source. A small problem was that in the DTA (Development, Test, and Acceptance) domains a lot of servers were turned off. So I had to use a filter to get the correct list of servers. And I had to filter on the OS of the VM…

The script I finally put together looked like this:

<#
.SYNOPSIS
    Get SCCM client information from WMI(based on vSphere VM's)
.DESCRIPTION
    Use this script if you need to retrieve SCCM client information
.PARAMETER vCenterServer
    Name of the vCenter Server
.EXAMPLE
    .\Get-CMClientInfo.ps1 -vCenterServer 'vcserver.domain.local'
    Retrieve SCCM client info from all VM's under the vCenter Server vcserver.domain.local
.NOTES
    Script name: Get-CMClientInfo.ps1
    Author:      Jeroen Buren
    DateCreated: 06-06-2017
#>

[CmdletBinding(SupportsShouldProcess=$true)]

param(
    [parameter(Mandatory=$true,HelpMessage="Name of the vCenter Server")]
    [ValidateScript({Test-Connection -ComputerName $_ -Count 1 -Quiet})]
    [string]$vCenterServer
)

#----------------------------------------------------------
# STATIC VARIABLES
#----------------------------------------------------------
$ProgressCount = 0
$Results = @()

#----------------------------------------------------------
# FUNCTIONS
#----------------------------------------------------------

function Get-VMFolderPath {
    Begin {}
    Process {
        foreach ($vm in $Input) {
            $DataCenter = $vm | Get-Datacenter
            $DataCenterName = $DataCenter.Name
            $VMname = $vm.Name
            $VMParentName = $vm.Folder
            if ($VMParentName.Name -eq "vm") {
                $FolderStructure = "{0}\{1}" -f $DataCenterName, $VMname
                $FolderStructure
                Continue
            }
            else {
                $FolderStructure = "{0}\{1}" -f $VMParentName.Name, $VMname
                $VMParentID = Get-Folder -Id $VMParentName.ParentId
                do {
                    $ParentFolderName = $VMParentID.Name
                    if ($ParentFolderName -eq "vm") {
                        $FolderStructure = "$DataCenterName\$FolderStructure"
                        $FolderStructure
                        break
                    }
                    $FolderStructure = "$ParentFolderName\$FolderStructure"
                    $VMParentID = Get-Folder -Id $VMParentID.ParentId
                }
                until ($VMParentName.ParentId -eq $DataCenter.Id)
            }
        }
   }
   End {}
}


#----------------------------------------------------------
# SCRIPTBODY
#----------------------------------------------------------

# Connect to vCenter Server
Connect-VIServer -Server $vCenterServer | Out-Null

# Select the VMs..
$VMs = Get-VM | Where {($_.PowerState -eq 'PoweredOn') -and ($_.Guest -match 'Microsoft Windows Server')} | Sort-Object -Property Name
# ..and count them
$ComputerCount = $VMs.Count

Foreach ($VM in $VMs) {
    $ProgressCount++
    $Computer = $VM.Name
    $Folder = $VM | Get-VMFolderPath
    Write-Progress -Activity "Getting SCCM client information..." -Id 1 -Status "$($ProgressCount) / $($ComputerCount)" -CurrentOperation "$Computer" -PercentComplete (($ProgressCount / $ComputerCount) * 100)
    #If (Test-Connection -ComputerName $Computer -Count 1 -Quiet) {
        Try {
            $ClientVersion = $(Get-WMIObject -Query "SELECT ClientVersion FROM SMS_Client" -Namespace "root/ccm" -Computername $Computer -ErrorAction Stop | Select ClientVersion).ClientVersion
            $SiteCode = $($([WMIClass]"\\$Computer\root\ccm:SMS_Client").GetAssignedSite() | Select sSiteCode).sSiteCode
            $Object = [pscustomobject]@{
                Computername = $Computer
                Folder = $Folder
                SiteCode = $SiteCode
                ClientVersion = $ClientVersion
            }
            $Results += $Object
        }
        Catch {
            $Object = [pscustomobject]@{
                Computername = $Computer
                Folder = $Folder
                SiteCode = "Unknown"
                ClientVersion = "Unknown"
            }
            $Results += $Object
        }
    #}
}

$Results #| Export-Csv -Path <path to CSV file> -NoTypeInformation

# Disconnect from the vCenter Server
Disconnect-VIServer -Server $vCenterServer -Confirm:$false
clientsccmwmi

SCCM - Windows Update settings and errors

SCCM - Duplicate Device Records

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Reporting on your Windows Server backup
  • Testing Script Runtime Service for vSphere – part 1
  • Using ADFS with vCenter 7
  • Network Port Diagram vSphere
  • Joining ESXi hosts to AD using Authentication Proxy in vCenter 7 (updated 04-12-2020)
  • Windows Server 2019 customization issue
  • Packer and WinRM – mystery resolved
  • Using LDAPS with vCenter and AD
  • Backup your homelab… for free!
  • Remediation did not succeed

Archives

Categories

AnyLinq (1) Azure (2) ConfigMgr (8) DIY (4) PowerCli (8) Powershell (9) SCCM (9) Script (12) Solutions (16) System Center (3) VMware (30) vRealize Automation (1) vRealize Orchestrator (1)

Jeroen BurenFollow

Jeroen Buren
Retweet on TwitterJeroen Buren Retweeted
Annemiek73Annemiek Meijer@Annemiek73·
16 Jan

Running man kan altijd! Ook tijdens #VVAL2021 @VriendvanAmstel #RunningMan #VVALS

Reply on Twitter 1350537030879608833Retweet on Twitter 13505370308796088332Like on Twitter 135053703087960883326Twitter 1350537030879608833
Retweet on TwitterJeroen Buren Retweeted
PowerCLIVMware PowerCLI@PowerCLI·
11 Jan

Do check out the SRS roadmap here. Feel free to influence the roadmap by submitting your requests. https://github.com/vmware/script-runtime-service-for-vsphere/projects/2 https://twitter.com/PowerCLI/status/1337370157551796225

VMware PowerCLI@PowerCLI

Introduction to Script Runtime Service (SRS) for vSphere https://blogs.vmware.com/PowerCLI/2020/12/introduction-to-script-runtime-service-srs-for-vsphere.html

Reply on Twitter 1348606798492618752Retweet on Twitter 13486067984926187524Like on Twitter 13486067984926187528Twitter 1348606798492618752
jeroen_burenJeroen Buren@jeroen_buren·
7 Jan

New blogpost about Script Runtime Service for vSphere.
https://configmgr.nl/2021/01/07/testing-script-runtime-service-for-vsphere-part-1/

#VMware #vSphere #SRS #PowerCLI

Reply on Twitter 1347191971002118144Retweet on Twitter 1347191971002118144Like on Twitter 1347191971002118144Twitter 1347191971002118144
jeroen_burenJeroen Buren@jeroen_buren·
18 Dec

Nice!! https://www.formula1.com/en/latest/article.breaking-perez-to-partner-verstappen-at-red-bull-in-2021-as-albon-becomes.21qHfmHAyfzAjVHT3PfVBd.html

Reply on Twitter 1339935240069001218Retweet on Twitter 1339935240069001218Like on Twitter 13399352400690012181Twitter 1339935240069001218
Retweet on TwitterJeroen Buren Retweeted
vRealizeAutovRealize Automation@vRealizeAuto·
16 Dec

#vRA x Terraform part 1 — #Cloud Automation Essentials☁️

Check out this blog to explore how you can use vRealize Automation and Terraform in effective ways.👍 https://bit.ly/3r2sLxE

Reply on Twitter 1339261564931727368Retweet on Twitter 13392615649317273686Like on Twitter 13392615649317273685Twitter 1339261564931727368
Load More...
Proudly powered by WordPress | Theme: Doo by ThemeVS.