PowerShell - CommandNotFoundException

Eddie Eagle 1 Reputation point
2021-12-06T12:59:01.577+00:00

I have a strange error with the PowerShell and a simple command:

New-LocalGroup -Description "Test Usergroup" -Name Testsusers

When I open the Powershell from CMD-box or from Start menu and run the command everything works fine (if I start with elevated rights). If I start the Shell without elevated rights I get the correct message "access denied...".

I want to run this command from an installation script (Inno Setup). The setup runs with elevated privileges, the powershell starts, but the script will not be executed. I have added to the command line the parameter "-NoExit" so that I can see what is happening. So I see that the command "New-LocalGroup" is unknown (CommandNotFoundException).
How can it be that on the same Windows 10 X64, with the same user the command is once known and once not?

Windows for business Windows Server User experience PowerShell
Windows for business Windows Client for IT Pros User experience Other
0 comments No comments
{count} votes

10 answers

Sort by: Most helpful
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2021-12-06T14:45:38.07+00:00

    This is the PowerShell Module: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/?view=powershell-5.1
    It's Microsoft.PowerShell.LocalAccounts

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

  2. Eddie Eagle 1 Reputation point
    2021-12-06T15:06:09.2+00:00

    I think I found the reason: It is a 32 Bit setup and starts the x86 powershell, where the command is not defined.
    Do you have any idea how to set user permissions for 32-bit systems as well (without net.exe)?
    Thanks a lot.
    Thomas


  3. Eddie Eagle 1 Reputation point
    2021-12-06T15:56:48.863+00:00

    It's a pity, but Set-Acl is probably not suitable for creating user accounts.
    wmic is discontinued.
    I have to go back to the good old net.exe and find a way to use SID's, because I also have to use other standard user groups.
    Thomas


  4. Eddie Eagle 1 Reputation point
    2021-12-09T15:24:39.693+00:00

    How can I add on this way a user to a user group on a 32 Bit system?

    0 comments No comments

  5. Eddie Eagle 1 Reputation point
    2021-12-09T17:13:05.283+00:00

    An interesting suggestion, but again, I am language dependent when selecting a predefined user group.
    Thanks anyway!

    0 comments No comments

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.