Get-CMClientVersion.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<#
.SYNOPSIS
This function gets the SCCM client version.
.DESCRIPTION
This function gets the SCCM client version.
.PARAMETER Computername
Enter a name of a computer or list of computers.
.EXAMPLE
Get-CMClientVersion -Computername 'SERVER01'
.EXAMPLE
Get-CMClienVersion -Computername 'SERVER01','WORKSTATION02'
.NOTES
Created by: Jason Wasser @wasserja
#>

function Get-CMClientVersion {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $false,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true)]
        [string[]]$ComputerName = $env:COMPUTERNAME
    )

    begin {}
    process {

        foreach ($Computer in $ComputerName) {
            Write-Verbose -Message "Checking SCCM Client version on $Computer"
            if ($Computer -eq $env:COMPUTERNAME) {
                $SccmClientVersion = Get-WmiObject -Namespace 'ROOT\ccm' -Class Ccm_InstalledComponent -Filter "Name = 'SmsClient'"
            }
            else {
                $SccmClientVersion = Get-WmiObject -Namespace 'ROOT\ccm' -Class Ccm_InstalledComponent -Filter "Name = 'SmsClient'" -ComputerName $Computer
            }
            $SccmClientVersion | Select-Object -Property PSComputerName, Version
        }
    }
    end {}
}