Skip to content

Instantly share code, notes, and snippets.

@XPlantefeve
Created March 31, 2015 14:03
Show Gist options
  • Select an option

  • Save XPlantefeve/f0c1ea8d72611b57fedc to your computer and use it in GitHub Desktop.

Select an option

Save XPlantefeve/f0c1ea8d72611b57fedc to your computer and use it in GitHub Desktop.
Gets computer information from SCCM.
<#
.Synopsis
Gets computer info from SCCM
.DESCRIPTION
Retrieves computers from SCCM, with optional targeting and filtering
.INPUTS
[System.String]
.OUTPUTS
[System.Management.ManagementObject#root\sms\site_SCM\SMS_R_System]
.EXAMPLE
C:\PS> Get-SCCMComputer -Name ITECBRUC1201234,ITECBRUC1243210
Retrieves information about two computers.
.EXAMPLE
C:\PS> Get-SCCMComputer -Filter 'ITECBRUC120%'
Retrieves information about all matching computers.
#>
function Get-SCCMComputer
{
[CmdletBinding()]
[OutputType([System.Management.ManagementObject])]
Param
(
# Computer Name
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
ParameterSetName='name',
Position=0)]
[Alias('ComputerName')]
[string[]]$Name,
# Filter, in the form '%StringToSearch%'
[Parameter(Mandatory=$true,
ParameterSetName='filter')]
[string]$Filter,
# SCCM Server, default to the current MP
[string]$Server,
# SCCM Site, default to the current one
[string]$Site
)
Begin
{
if ( $Filter ) {
$FilterString = 'Name like '
$Name = $Filter
} else {
$FilterString = 'Name = '
}
if ( !$Server ) {
$Server = (Get-WmiObject -Class 'SMS_Authority' -Namespace 'ROOT\ccm').CurrentManagementPoint
}
if ( !$Site ) {
$Site = (Get-WmiObject -Class 'SMS_Authority' -Namespace 'ROOT\ccm').Name -Replace '^SMS:',''
}
Update-TypeData -TypeName SCCM.ComputerInfo -MemberType ScriptProperty -MemberName LastLogonUser -Value { "$($This.LastLogonUserDomain)\$($This.LastLogonUserName)" } -Force
Update-TypeData -TypeName SCCM.ComputerInfo -DefaultDisplayPropertySet Name,LastLogonUser,IPAddresses,MACAddresses,ADSiteName -Force
}
Process
{
$Row = Get-WmiObject -ComputerName $Server -Namespace "root\sms\site_$Site" -Class SMS_R_SYSTEM -Filter "$FilterString '$Name'"
$Row.PSTypeNames.Insert(0,'SCCM.ComputerInfo')
$Row
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment