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 # 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" $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") $HomeWindow_BannerButton.Visibility = 'Hidden' } } } |