The following function helps you retrieve all the deployment that a user is supposed to received.
We use this during the Operating System Deployment (OSD). Using the UDI we get the user account that will receive the workstation currently being deployed. This script allow us to retrieve in SCCM all the Application advertised on the user that needed to be deployed on the computer during the task sequence.
I know this could probably be done with the Configuration Manager module, but I'm pretty new with it and I was not sure it could be loaded in a task sequence, if you have the answer let me know in the comment section.
Here is the step by step how I found my solution. You can also go straight to the function at the end of this article.
Define Default Parameters
First I define a splatting to avoid repeating the same parameters in each command.
# Define default parameters (Splatting)
$Splatting = @{
ComputerName = "Sccm01.lazywinadmin.com"
NameSpace = "root\SMS\Site_FX1"
}
Retrieve a user in SCCM CMDB
Then I need to find a user in the SCCM Database to retrieve its
ResourceID.
# Find the User in SCCM CMDB
$User = Get-WMIObject @Splatting -Query "Select * From SMS_R_User WHERE UserName='FxTest'"
Retrieve the collections the user is member of
# Find the collections where the user is member of
$Collections = Get-WmiObject -Class sms_fullcollectionmembership @splatting -Filter "ResourceID = '$($user.resourceid)'"