Last active
July 3, 2019 22:39
-
-
Save DexterPOSH/11081268 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-SCCMDeviceInfo | |
{ | |
[CmdletBinding(DefaultParameterSetName='Computer')] | |
[OutputType([PSObject])] | |
Param | |
( | |
# Specify the Package IDs which need to be removed from the DP | |
[Parameter(Mandatory, | |
ParameterSetName="Computer", | |
ValueFromPipelineByPropertyName, | |
ValueFromPipeline, | |
Position=0)] | |
[string[]]$ComputerName, | |
# Pass the DP name where cleanup is to be done | |
[Parameter(Mandatory,ParameterSetName='CollectionID')] | |
[string]$CollectionId, | |
#Supply the SCCM Site Server hosting SMS Namespace Provider | |
[Parameter(Mandatory, | |
HelpMessage="Specify your SCCCM Server hosting SMS Namespace provider")] | |
[String]$SCCMServer, | |
#Specify this switch to select the properties to get back, Default- gets all the properties | |
[Switch]$PropertySelect | |
) | |
Begin | |
{ | |
Write-Verbose -Message "[BEGIN]" | |
try | |
{ | |
$sccmProvider = Get-CimInstance -query "select * from SMS_ProviderLocation where ProviderForLocalSite = true" -Namespace "root\sms" -computername $SCCMServer -errorAction Stop | |
# Split up the namespace path | |
$Splits = $sccmProvider.NamespacePath -split "\\", 4 | |
Write-Verbose "Provider is located on $($sccmProvider.Machine) in namespace $($splits[3])" | |
# Create a new hash to be passed on later | |
$hash= @{"ComputerName"=$SCCMServer;"NameSpace"=$Splits[3];"ErrorAction"="Stop"} | |
$Properties = '*' #by default get all the properties back for the Device | |
if ($PropertySelect) #if the Switch specified give a out-grdiview to select the properties | |
{ | |
$Properties = Get-CIMClass -ClassName SMS_CombinedDeviceResources @hash | select -ExpandProperty CimClassProperties | | |
Out-GridView -PassThru -Title "Select the Properties to retrieve" | |
$Properties = $Properties | select -ExpandProperty Name | |
} | |
} | |
catch | |
{ | |
Write-Warning "Check if the Servername $SCCMServer has SMS Namespace provider on it" | |
$Error[0].Exception | |
} | |
} | |
Process | |
{ | |
Switch -Exact ($PSCmdlet.ParameterSetName) | |
{ | |
"Computer" | |
{ | |
#Code to get information when the ComputerNames are specified | |
foreach ($computer in $ComputerName) | |
{ | |
$query = "Select {0} from SMS_CombinedDeviceResources Where Name='{1}'" -f ($Properties -join ","),$computer | |
Get-CimInstance -Query $query @hash | Select-Object -Property $Properties | |
} #end foreach ($computer in $computername) | |
} | |
"CollectionID" | |
{ | |
#code to get members from COllectionID | |
$query = "Select {0} from {1}" -f ($Properties -join ","),(Get-CimInstance -ClassName SMS_Collection -filter "CollectionId='$CollectionId'" @hash).MemberClassName | |
Get-CimInstance -Query $query @hash| Select -Property $Properties | |
} | |
} #end Switch -Exact ($PSCmdlet.ParameterSetName) | |
} | |
End | |
{ | |
Write-Verbose -Message "[END]" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment