syntax error

Glenn Maxwell 11,416 Reputation points
2022-02-15T14:44:52.307+00:00

Hi All

I have servers list in the text format. i want to fetch users list who are members of Remote Desktop Users group. i am able to fetch using the below syntax.

I want to create a script in sccm and attach it to the collection and export the information to a csv file. experts guide me

$Srv = Get-Content "C:\temp\servers.txt"
$Srv | Foreach-Object { Invoke-Command -ComputerName $_ { Net LocalGroupMember 'Remote Desktop Users' } } | Export-csv C:\temp\output.csv -NoTypeInformation

i have created a script and added the line Net LocalGroupMember 'Remote Desktop Users' script shows succeeded but i dont get the output. When i use the syntax
net localgroup 'Remote Desktop Users' i can see the output but how do i export to csv file.

Microsoft Configuration Manager
0 comments No comments
{count} votes

Accepted answer
  1. AllenLiu-MSFT 44,821 Reputation points Microsoft Vendor
    2022-02-16T08:38:35.42+00:00

    Hi, @Glenn Maxwell

    I can use this script to get the output, and you may add "-append" in the end to make sure add objects to the existing file.
    Import-Module Microsoft.PowerShell.LocalAccounts
    Get-LocalGroupMember -Group "Remote Desktop Users" | select Name | Export-csv -path "\server01\sharedfolder\output.csv" -NoTypeInformation -append

    Here is my result:
    174902-1.png

    174893-2.png


3 additional answers

Sort by: Most helpful
  1. AllenLiu-MSFT 44,821 Reputation points Microsoft Vendor
    2022-02-16T06:31:36.727+00:00

    Hi, @Glenn Maxwell

    Thank you for posting in Microsoft Q&A forum.

    I use the below script to export to csv file.

    Import-Module Microsoft.PowerShell.LocalAccounts  
    Get-LocalGroupMember -Group "Remote Desktop Users" | select Name | Export-csv -path "\\RemoteServer\C$\Temp\GroupMembers.csv" -NoTypeInformation  
    

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Glenn Maxwell 11,416 Reputation points
    2022-02-16T07:01:09.79+00:00

    i have used the below syntax but i did not get any output

    Import-Module Microsoft.PowerShell.LocalAccounts
    Get-LocalGroupMember -Group "Remote Desktop Users" | select Name | Export-csv -path "\server01\sharedfolder\output.csv" -NoTypeInformation

    0 comments No comments

  3. Glenn Maxwell 11,416 Reputation points
    2022-02-16T08:59:20.147+00:00

    below is the script result
    174768-soutput.jpg


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.