Private/ADLookups/_UpdateSCCMDevices.ps1
function _UpdateSCCMDevices { [CmdletBinding()] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '', Justification = 'Global to be used again in the same session.')] param ( [Parameter()] [switch]$ForceLookup ) begin { $ADLookups_FindTabInformationTextBox.Text = 'Loading SCCM Devices...' # This is set in the function being called $SCCMServer = $STTSettings.SCCMSettings.SCCMServerHostname # Tried the API $DeviceCollection = $STTSettings.SCCMSettings.SCCMDefaultCollection $ErrorOccurred = $false } process { if ((!$SCCMDevices) -or $ForceLookup ) { # Get all Computers from SCCM Write-Verbose "Getting list of devices from SCCM collection: $DeviceCollection" # using API should be possible # get the collection full membership sms_fullcollectionmembership # for each member of that, get the v1.0 device stats # filter on primaryuser, currentlogonuser, and lastlogonuser $Command = { Import-Module ConfigurationManager Set-Location 'SC3:' Get-CMDevice -CollectionName $Using:DeviceCollection } try { $Global:SCCMDevices = Invoke-Command -ComputerName $SCCMServer -ScriptBlock $Command } catch { $ErrorOccurred = $true $MessageSplat = @{ MessageText = 'Unable to get devices from SCCM.' MessageIcon = 'Hand' ButtonType = 'OK' MessageTitle = 'Error' } _ShowMessageBox @MessageSplat } } } end { if ($ErrorOccurred) { $ADLookups_FindTabInformationTextBox.Text = "Unable to get devices from SCCM.`nVerify that you have permissions to read SCCM." } else { $ADLookups_FindTabInformationTextBox.Text = 'Loading from SCCM Complete.' $ADLookups_FindTabObjectTypeComboBox.Items.Add("User's Computer") if ($HomeWindow_BannerButton) { $HomeWindow_BannerButton.Visibility = 'Hidden' } } } } |