Function to display username once and devices of user from Device Afinity

Welcome Forums General PowerShell Q&A Function to display username once and devices of user from Device Afinity

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
2 years, 6 months ago.

  • Author
    Posts
  • #38194

    Participant
    Points: 0
    Rank: Member

    I'm working on a powershell script that gets the device affinity of the user to the device. i could have, for example, one user attached to 4 devices. I want to create a small function to display the users and the device. But here's thing, i want to display the username once and the devices associated with the user.
    Currently all i get back is the same username, for example, 4 times for each device. This is what i have :

    
    $devices = Get-CMDevice -CollectionName 'Visio 2010 Multiple Devices'
    $Return = $devices | foreach { @( Get-CMUserDeviceAffinity -UserName $_.UserName) }
    $Return | % { Write-Output "$($_.UniqueUserName | select -Unique ) : $($_.ResourceName)" }
    
    

    How can i achieve this ?

    Thanks

  • #38300

    Keymaster
    Points: 1,638
    Helping HandTeam Member
    Rank: Community Hero

    So, not being familiar with the CM commands, I guess I'm not sure what output you ARE getting and what output you WANT to get. Can you provide examples?

The topic ‘Function to display username once and devices of user from Device Afinity’ is closed to new replies.