Unable to list out the user

Peter_1985 2,736 Reputation points
2022-12-21T13:24:14.393+00:00

Hi,
Please help and share the way to list out the relevant users within Windows server, in addition to the thread below.
https://learn.microsoft.com/en-us/answers/questions/1087739/issue-of-user-account.html?childToView=1137340#comment-1137340

Windows for business | Windows Server | User experience | Other
Developer technologies | Visual Studio | Other
Developer technologies | ASP.NET | Other
{count} votes

9 answers

Sort by: Most helpful
  1. Ali AlEnezi 1,081 Reputation points
    2022-12-23T10:05:45.16+00:00

    Hello,

    To list the relevant users within Windows Server, you can use the following steps:

    1. Open the Server Manager console on your Windows Server.
    2. In the left-hand menu, click on "Local Users and Groups."
    3. In the main window, click on the "Users" folder to view a list of all the users on the server.

    You can also use the command prompt or PowerShell to list the users on your Windows Server. To do this, you can use the following command:

    net user

    This command will list all the users on the server, along with their account status (e.g. active, disabled, etc.). You can also use the following command to list specific users:

    net user username

    Replace "username" with the name of the user you want to list.

    Alternatively, you can use the following PowerShell command to list all the users on the server:

    Get-LocalUser

    This will display a list of all the local user accounts on the server, along with their account status and other details.

    I hope this helps!


  2. MotoX80 36,291 Reputation points
    2022-12-23T13:54:08.34+00:00

    I have read through both of your threads and this question is just going in circles. @Jack J Jun has provided the correct answer as to how to list local user accounts. If you don't see your account there, then you did not create a "normal" local user account. Or you created the account on some other machine. Or you created a domain account.

    On C# project, I used Powershell command to create new user and furthermore,

    Please share the code that you used to create this user.

    I can make use of such user account to send out message with a success.

    What does that mean? Did you send an email? How did you authenticate the account that you created? Did you shell out a program or issue some COM call? How did you send this message?


  3. MotoX80 36,291 Reputation points
    2022-12-29T13:37:04.99+00:00

    What is the reason?

    Your code did not create the user. You are using commas as the command separator. You need to use semicolons.

    Open a command prompt and paste in this statement.

    powershell.exe $a = 1, $a++, $a  
    

    When you run it, nothing appears to happen because you assigned an array to the $a variable. When you run the line below, it returns the expected "2" when it displays the contents of the $a variable.

    powershell.exe $a = 1; $a++; $a  
    

    Why do you have -noexit? Is the rest of your code redirecting stdout/stderr or are you able to Alt+Tab and view the Powershell window?

    What output does Powershell produce?


  4. MotoX80 36,291 Reputation points
    2022-12-30T13:23:19.57+00:00

    The user account was created well

    That is simply not possible. In addition to the comma/semicolon problem, your code has "new-user". There is no such cmdlet.

    275123-image.png

    275075-image.png

    You would need to use New-LocalUser to create a local account or New-ADUser to create an Active Directory account.

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/new-localuser?view=powershell-5.1

    https://learn.microsoft.com/en-us/powershell/module/activedirectory/new-aduser?view=windowsserver2016-ps

    If you have written your own new-user script, then forum users will have no idea what it does.

    Modify the process.startinfo code to capture and then display both stdout and stderr. Remove the -noexit switch. Rerun the program and post the output.

    https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.redirectstandardoutput?view=netframework-4.7


  5. MotoX80 36,291 Reputation points
    2023-01-04T14:01:40.047+00:00

    I used the way to create LocalUser and the line below is not showing that LocalUser account. Why?

    Well, given no facts or evidence, the obvious assumption would be that you never created the account.

    If you read through your post, all along you insist that you created some user account and you used it to send email. But I pointed out that you used "New-User" in your Powershell code. That cmdlet does not exist, and it was simply not possible to create an account with that code.

    Muliple forum users have explained to you how to view local accounts. If you don't see the account listed, then you didn't create it. I have no idea why you think that this account exists.

    So now we go back to the Powershell code. Since you are launching a separate process, the primary method of determining success or failure is to capture stdout and stderr and display the contents to the user who is running the program. I told you to do that and post the output. You have not done that.

    276114-image.png

    I also pointed out that you used commas as cmdlet delimeters. That will not work. Did you fix that?

    Please rerun the Powershell code, capture stdout and stderr and display the output. You have another bug in that PS code, but I am not going to tell you what it is. It is more important that you learn how to troubleshoot your own code.


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.