Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save r0ckbeard/60a89aafef1b90a58fb6d4ac4701dfb1 to your computer and use it in GitHub Desktop.

Select an option

Save r0ckbeard/60a89aafef1b90a58fb6d4ac4701dfb1 to your computer and use it in GitHub Desktop.
Imports devices from csv to SCCM/MECM device collection
# Import SCCM module
Import-Module 'C:\Program Files (x86)\Microsoft Endpoint Manager\AdminConsole\bin\ConfigurationManager.psd1'
# Define the Site Code
$SiteCode = ""
# Define the path to the CSV file
$csvPath = ""
# Define the collection ID to which devices will be added
$collectionID = ""
# Import the CSV
$devices = Import-Csv -Path $csvPath
foreach ($device in $devices) {
# Extract the actual computer name
$computerName = $device.ComputerName.Trim()
# Get the device resource ID
$deviceResourceID = Get-CMDevice -Name $computerName | Select-Object -ExpandProperty ResourceID
if ($deviceResourceID) {
# Add each device to the collection
Add-CMDeviceCollectionDirectMembershipRule -CollectionId $collectionID -ResourceID $deviceResourceID
} else {
Write-Host "Device $computerName not found in SCCM."
}
}
Write-Host "Devices have been added to the collection."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment