Created
May 30, 2024 12:55
-
-
Save r0ckbeard/60a89aafef1b90a58fb6d4ac4701dfb1 to your computer and use it in GitHub Desktop.
Imports devices from csv to SCCM/MECM device collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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