Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save r0ckbeard/526f530d87373594f6f042b3b320fad8 to your computer and use it in GitHub Desktop.

Select an option

Save r0ckbeard/526f530d87373594f6f042b3b320fad8 to your computer and use it in GitHub Desktop.
Imports users from csv to SCCM/MECM user 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 users will be added
$collectionID = ""
# Import the CSV
$users = Import-Csv -Path $csvPath
foreach ($user in $users) {
# Extract the actual username value
$userName = $user.UserName.Trim()
# Get the user resource ID
$userResourceID = Get-CMUser -Name $userName | Select-Object -ExpandProperty ResourceID
if ($userResourceID) {
# Add each user to the collection
Add-CMUserCollectionDirectMembershipRule -CollectionId $collectionID -ResourceID $userResourceID
} else {
Write-Host "User $userName not found in SCCM."
}
}
Write-Host "Users have been added to the collection."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment