Private/_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 # API is so fast, no need to limit on collection, would also be more difficult # $DeviceCollection = $STTSettings.SCCMSettings.SCCMDefaultCollection $ErrorOccurred = $false } process { if ((!$SCCMDevices) -or $ForceLookup ) { # Get all Computers from SCCM using API Write-Verbose "Getting list of devices from SCCM collection: $DeviceCollection" try { $Global:SCCMDevices = _GetSCCMInformationQuery -Route 'v1.0' -Connector 'Device' } catch { $ErrorOccurred = $true Write-Error $_ } } } 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") } } } |