Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New-LocalUser doesn't work in Power 7.3+ without importing Microsoft.Powershell.LocalAccounts #21645

Open
5 tasks done
NekoJonez opened this issue May 8, 2024 · 0 comments
Open
5 tasks done
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.

Comments

@NekoJonez
Copy link

Prerequisites

Steps to reproduce

try {
        $Secure_String_Pwd = ConvertTo-SecureString "GeheimWachtwoord" -AsPlainText -Force
        New-LocalUser -Name "Eigenaar" -Password $Secure_String_Pwd -FullName "Eigenaar" -Description "Lokale admingebruiker" -AccountNeverExpires | Out-Null

        try {
          Add-LocalGroupMember -Group "Administrators" -Member "Eigenaar"
        }
        catch {
          Write-Host "Er was een fout met het toevoegen van de 'Eigenaar' gebruikersaccount als beheerder. Stuur deze fout naar de ICT dienst als deze fout blijft aanhouden: $($_.Exception.Message)"
        }

        Write-Host "De eigenaar account is aangemaakt met wachtwoord: $($Global:Pwd_Shown). De gebruikernaam is .\Eigenaar."
      }
      catch {
        Write-Host "Er was een fout met het aanmaken van de 'Eigenaar' gebruikersaccount. Stuur deze fout naar de ICT dienst als deze fout blijft aanhouden: $($_.Exception.Message)"
      }

The above script fails to create the user account in PowerShell 7+, it works fine in PowerShell 5.3...

If I set this underneath the first try statement:

    if ($PSVersionTable.PSVersion.Major -ge 7) {
      # Deze module zo inladen. Niet via "ModuleIfNeeded", want anders werkt het niet in Powershell 7.
      Import-Module Microsoft.PowerShell.LocalAccounts -UseWindowsPowerShell -SkipEditionCheck | Out-Null
    }

It works perfectly. So, I think something is going wrong.

Expected behavior

The user account is created.

Actual behavior

The useraccount isn't created.

Error details

Could not load type 'Microsoft.PowerShell.Telemetry.Internal.TelemetryAPI' from assembly 'System.Management.Automation, Version=7.4.2.500, Culture=neutral, PublicKeyToken=*****'.

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.2
PSEdition                      Core
GitCommitId                    7.4.2
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

@NekoJonez NekoJonez added the Needs-Triage The issue is new and needs to be triaged by a work group. label May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.
Projects
None yet
Development

No branches or pull requests

1 participant