0

I am able to import .csv file and its working for me without any error, but not able to add the users in Remote Desktop Users list. Can any one know the solution.

Import-csv -Path "C:\Users\Intune.Autopilot.Poc\Downloads\employees.csv" | ForEach-Object {
    Add-LocalGroupMember -Group "Remote Desktop Users" -Member $_.'userPrincipalName'
}

my csv file contains only userPrinicipalName user@domain.com advance thanks for helping.

please help me to get the issue resolved.

mklement0
  • 382,024
  • 64
  • 607
  • 775
sure
  • 1
  • 1
    What does it mean "*not able to add the users in Remote Desktop Users list*"? And BTW: Since `Add-LocalGroupMember` takes an array of members you don't need a loop at all. – Olaf Aug 13 '23 at 15:26
  • 2
    Why did you add the tags `[azure-active-directory]`, `[sccm]`,`[intune]` and `[microsoft-graph-intune]`? – Olaf Aug 13 '23 at 15:27
  • 1
    Have you checked the official documentation for the `Add-LocalGroupMember` cmdlet (https://learn.microsoft.com/powershell/module/microsoft.powershell.localaccounts/add-localgroupmember)? According to examples provided in the article, use `-Member "CONTOSO\Administrator"` format instead of UserPrincipalName – MikeSh Aug 14 '23 at 00:02

1 Answers1

1

I am able to import .csv file and its working for me without any error, but not able to add the users in Remote Desktop Users list. Can any one know the solution.

If you are trying to add users to the Remote Desktop Users group using PowerShell and a CSV file.

Make sure that CSV file is properly formatted and that the column header for userPrincipalName is spelled correctly and also there are no extra spaces or special characters in the values.

Here is the updated code to add users to the Remote Desktop Users

Excel Format:

enter image description here

    Import-Csv -Path "C:\Users\v-vallepuv\Desktop\RDP Users.csv" | ForEach-Object {
        $userPrincipalName = $_.'userPrincipalName'
        Write-Host "Adding $userPrincipalName to Remote Desktop Users group"
        Add-LocalGroupMember -Group "Remote Desktop Users" -Member $userPrincipalName
    }

By adding Write-Host statements, you can see the progress of the script and identify any issues.

Output:

enter image description here

Reference: Add-LocalGroupMember

Venkat V
  • 2,197
  • 1
  • 1
  • 10
  • There's no loop needed. `Add-LocalGroupMember` takes an array of members!!! ;-) – Olaf Aug 14 '23 at 06:46
  • Hi @Olaf, yes, we can run the command from an Array as well. I just provided a user query by adding the 'Write-Host' command to monitor the script's progress. However, if I add the 'Write-Host' command without a loop to track the script's progress, the output will have a different format, like [this](https://i.imgur.com/97jEadQ.png). – Venkat V Aug 14 '23 at 07:42