Skip to content

Instantly share code, notes, and snippets.

@NathanTheGr8
Created May 15, 2023 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NathanTheGr8/0e49048403d95418eec2e59403625b31 to your computer and use it in GitHub Desktop.
Save NathanTheGr8/0e49048403d95418eec2e59403625b31 to your computer and use it in GitHub Desktop.
# Site configuration
$SiteCode = "TES" # Site code
$ProviderMachineName = "Primary.domain.LOCAL" # SMS Provider machine name
# Customizations
$initParams = @{}
#$initParams.Add("Verbose", $true) # Uncomment this line to enable verbose logging
#$initParams.Add("ErrorAction", "Stop") # Uncomment this line to stop the script on any errors
# Import the ConfigurationManager.psd1 module
if((Get-Module ConfigurationManager) -eq $null) {
Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" @initParams
}
# Connect to the site's drive if it is not already present
if((Get-PSDrive -Name $SiteCode -PSProvider CMSite -ErrorAction SilentlyContinue) -eq $null) {
New-PSDrive -Name $SiteCode -PSProvider CMSite -Root $ProviderMachineName @initParams
}
# Set the current location to be the site code.
Set-Location "$($SiteCode):\" @initParams
$count = 0
$Array = Get-Content "C:\Temp\Collection.txt"
$array | foreach {
$percent = ($count/($Array.Length))*100
Write-Progress -Activity "adding pcs $count of $($Array.Length)" -PercentComplete $percent
Add-CMDeviceCollectionDirectMembershipRule -CollectionName "ProvWave2-Devices" -ResourceID (Get-CMDevice -Name $_).ResourceID
$count++
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment