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...' $SCCMServer = $STTSettings.SCCMSettings.SCCMServerHostname $DeviceCollection = $STTSettings.SCCMSettings.SCCMDefaultCollection $ErrorOccurred = $false } process { if ((!$SCCMDevices) -or $ForceLookup ) { # Get all Computers from SCCM collection Write-Verbose "Getting list of devices from SCCM collection: $DeviceCollection" # TODO can this be done using the API? $Command = { Import-Module ConfigurationManager Set-Location SC3: Get-CMDevice -CollectionName $Using:DeviceCollection } try { $Global:SCCMDevices = Invoke-Command -ComputerName $SCCMServer -ScriptBlock $Command } 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") } } } |