{"id":456540,"date":"2025-04-24T08:02:40","date_gmt":"2025-04-24T08:02:40","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=456540"},"modified":"2025-04-24T08:10:35","modified_gmt":"2025-04-24T08:10:35","slug":"lokales-benutzerkonto-mit-powershell-erstellen","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/de\/script-hub\/lokales-benutzerkonto-mit-powershell-erstellen\/","title":{"rendered":"Wie Sie ein neues lokales Benutzerkonto mit PowerShell erstellen k\u00f6nnen"},"content":{"rendered":"<h2>Wichtigste Erkenntnisse<\/h2>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"1\" data-aria-level=\"1\"><strong>PowerShell-Effizienz<\/strong>: PowerShell wird verwendet, um lokale Benutzerkonten effizient zu erstellen und zu verwalten.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"2\" data-aria-level=\"1\"><strong>Erweiterte Funktionen<\/strong>: Umfasst die Planung f\u00fcr die Aktivierung\/Deaktivierung von Konten und das Hinzuf\u00fcgen von Benutzer:innen zu Verwaltungsgruppen.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"3\" data-aria-level=\"1\"><strong>Automatisierte Sicherheit<\/strong>: Generiert automatisch sichere Passw\u00f6rter und erh\u00f6ht so die Sicherheit der Konten.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"4\" data-aria-level=\"1\"><strong>Zeitmanagement<\/strong>: Spart Zeit bei der Verwaltung von Benutzerkonten, was besonders n\u00fctzlich f\u00fcr MSPs ist.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"5\" data-aria-level=\"1\"><strong>Anpassbares Skript<\/strong>: Erm\u00f6glicht die Anpassung durch benutzerdefinierte Parameter.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"6\" data-aria-level=\"1\"><strong>Aufgabenplanung<\/strong>: Bietet die M\u00f6glichkeit, Aufgaben zu planen, um Konten zu bestimmten Zeiten zu aktivieren oder zu deaktivieren.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"7\" data-aria-level=\"1\"><strong>Gruppenverwaltung<\/strong>: Erm\u00f6glicht das Hinzuf\u00fcgen von Benutzer:innen zu bestimmten Gruppen, einschlie\u00dflich Administrator:innen.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"8\" data-aria-level=\"1\"><strong>Anpassungsf\u00e4hig f\u00fcr Massenerstellung<\/strong>: Es wurde zwar f\u00fcr einzelne Konten entwickelt, kann aber auch f\u00fcr die Massen-Benutzererstellung angepasst werden.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"9\" data-aria-level=\"1\"><strong>Auswirkungen auf die Sicherheit<\/strong>: Betont die Notwendigkeit strenger Zugangskontrollen und regelm\u00e4\u00dfiger \u00dcberpr\u00fcfungen.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"10\" data-aria-level=\"1\"><strong>Kompatibilit\u00e4t mit NinjaOne<\/strong>: Kann f\u00fcr ein zentrales IT-Management in NinjaOne integriert werden.<\/li>\n<\/ul>\n<p>In der heutigen digitalen Welt ist die effiziente Verwaltung von Benutzerkonten f\u00fcr IT-Expert:innen von entscheidender Bedeutung. PowerShell, eine leistungsstarke Skriptsprache und Befehlszeilen-Shell, bietet eine dynamische M\u00f6glichkeit, diese Aufgaben zu erledigen. In diesem Blogbeitrag wird ein PowerShell-Skript untersucht, das nicht nur lokale Benutzerkonten erstellt, sondern auch Optionen f\u00fcr die Zeitplanung und Gruppenverwaltung bietet. Das Skript stellt seinen Nutzen in verschiedenen IT-Umgebungen unter Beweis.<\/p>\n<h2>Kontext<\/h2>\n<p>Dieses PowerShell-Skript zeichnet sich durch seine F\u00e4higkeit aus, lokale Benutzerkonten mit erweiterten Funktionen wie der Planung von Aktivierungs-\/Deaktivierungsdaten und dem Hinzuf\u00fcgen von Benutzer:innen zur lokalen Administratorgruppe zu erstellen. Diese Funktionen sind vor allem f\u00fcr IT-Expert:innen und <a href=\"https:\/\/www.ninjaone.com\/de\/was-ist-ein-msp\/\">Managed Service Provider (MSPs)<\/a> wichtig, die eine gro\u00dfe Anzahl von Benutzerkonten verwalten und den rechtzeitigen und sicheren Zugriff auf Systeme gew\u00e4hrleisten m\u00fcssen.<\/p>\n<h2>Das Skript<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">#Requires -Version 5.1\r\n\r\n&lt;#\r\n.SYNOPSIS\r\n    Create a local user account with options to enable and disable at specific dates, and add to local admin group. Saves randomly generated password to a custom field.\r\n.DESCRIPTION\r\n    You can specify when the account will be enabled and\/or disabled.\r\n    You can have the account be added as a member of the local Administrators group.\r\n\r\nPARAMETER: -UserNameToAdd \"JohnTSmith\" -Name \"John T Smith\"\r\n    Create use with the name JohnTSmith and display name of John T Smith.\r\n.EXAMPLE\r\n    -UserNameToAdd \"JohnTSmith\" -Name \"John T Smith\"\r\n    ## EXAMPLE OUTPUT ##\r\n    User JohnTSmith has been created successfully.\r\n    User JohnTSmith was added to the local Users group.\r\n\r\nPARAMETER: -UserNameToAdd \"JohnTSmith\" -Name \"John T Smith\" -DateAndTimeToEnable \"Monday, January 1, 2020 1:00:00 PM\"\r\n    Create use with the name JohnTSmith and display name of John T Smith.\r\n    The user will start out disabled.\r\n    A scheduled task will be create to enable the user after \"Monday, January 1, 2020 1:00:00 PM\"\r\n.EXAMPLE\r\n    -UserNameToAdd \"JohnTSmith\" -Name \"John T Smith\" -DateAndTimeToEnable \"Monday, January 1, 2020 1:00:00 PM\"\r\n    ## EXAMPLE OUTPUT ##\r\n    User JohnTSmith has been created successfully.\r\n    User JohnTSmith was added to the local Users group.\r\n    Created Scheduled Task: Enable User JohnTSmith\r\n    User JohnTSmith will be able to login after Monday, January 1, 2020 1:00:00 PM.\r\n\r\nPARAMETER: -UserNameToAdd \"JohnTSmith\" -Name \"John T Smith\" -DisableAfterDays 10\r\n    Create use with the name JohnTSmith and display name of John T Smith.\r\n    The user will be disabled after 10 days after the user's creation.\r\n.EXAMPLE\r\n    -UserNameToAdd \"JohnTSmith\" -Name \"John T Smith\" -DisableAfterDays 10\r\n    ## EXAMPLE OUTPUT ##\r\n    User JohnTSmith has been created successfully.\r\n    User JohnTSmith was added to the local Users group.\r\n\r\nPARAMETER: -UserNameToAdd \"JohnTSmith\" -Name \"John T Smith\" -AddToLocalAdminGroup\r\n    Create use with the name JohnTSmith and display name of John T Smith.\r\n    User will be added as a member of the local Administrators group.\r\n.EXAMPLE\r\n    -UserNameToAdd \"JohnTSmith\" -Name \"John T Smith\" -AddToLocalAdminGroup\r\n    ## EXAMPLE OUTPUT ##\r\n    User JohnTSmith has been created successfully.\r\n    User JohnTSmith was added to the local Users group.\r\n    User JohnTSmith was added to the local Administrators group.\r\n.OUTPUTS\r\n    None\r\n.NOTES\r\n    Minimum OS Architecture Supported: Windows 10, Windows Server 2016\r\n    Release Notes: Initial Release\r\nBy using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https:\/\/www.ninjaone.com\/terms-of-use.\r\n    Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. \r\n    Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. \r\n    Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. \r\n    Warranty Disclaimer: The script is provided \u201cas is\u201d and \u201cas available\u201d, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. \r\n    Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. \r\n    Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. \r\n    EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).\r\n#&gt;\r\n\r\n[CmdletBinding()]\r\nparam (\r\n    [Parameter()]\r\n    [String]$UserNameToAdd,\r\n    [Parameter()]\r\n    [String]$Name,\r\n    [Parameter()]\r\n    [String]$PasswordCustomField,\r\n    [Parameter()]\r\n    [int]$PasswordLength,\r\n    [Parameter()]\r\n    [DateTime]$DateAndTimeToEnable,\r\n    [Parameter()]\r\n    [int]$DisableAfterDays,\r\n    [Parameter()]\r\n    [Switch]$AddToLocalAdminGroup,\r\n    [Parameter()]\r\n    $PasswordOptions\r\n)\r\n\r\nbegin {\r\n    function Test-IsElevated {\r\n        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()\r\n        $p = New-Object System.Security.Principal.WindowsPrincipal($id)\r\n        $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)\r\n    }\r\n    function New-SecurePassword {\r\n        [CmdletBinding()]\r\n        param (\r\n            [Parameter(Mandatory = $false)]\r\n            [int]$Length = 16,\r\n            [Parameter(Mandatory = $false)]\r\n            [bool]$IncludeSpecialCharacters = $true\r\n        )\r\n        # .NET class for generating cryptographically secure random numbers\r\n        $cryptoProvider = New-Object System.Security.Cryptography.RNGCryptoServiceProvider\r\n        $SpecialCharacters = if ($IncludeSpecialCharacters) { '!@#$%&amp;-' }\r\n        $passwordChars = \"abcdefghjknpqrstuvwxyzABCDEFGHIJKMNPQRSTUVWXYZ0123456789$SpecialCharacters\"\r\n        $password = for ($i = 0; $i -lt $Length; $i++) {\r\n            $byte = [byte[]]::new(1)\r\n            $cryptoProvider.GetBytes($byte)\r\n            $charIndex = $byte[0] % $passwordChars.Length\r\n            $passwordChars[$charIndex]\r\n        }\r\n        return $password -join ''\r\n    }\r\n    function New-LocalUserFromNinja {\r\n        param(\r\n            [string]$Username,\r\n            [string]$Name,\r\n            [string]$PasswordCustomField,\r\n            [DateTime]$EnableDate,\r\n            [int]$DisableAfterDays,\r\n            [switch]$AddToLocalAdminGroup\r\n        )\r\n        # Generate a secure localUserPassword\r\n        $Password = New-SecurePassword -Length $PasswordLength -IncludeSpecialCharacters $true\r\n        if ($Username -and $Name) {\r\n            # Check if the user already exists\r\n            if (-not (Get-LocalUser -Name $Username -ErrorAction SilentlyContinue)) {\r\n                # Create new local user\r\n                $UserSplat = @{\r\n                    Name                 = \"$Username\"\r\n                    FullName             = \"$Name\"\r\n                    Password             = ConvertTo-SecureString -String $($Password -join '') -AsPlainText -Force\r\n                    Description          = \"User account created on $(Get-Date)\"\r\n                    PasswordNeverExpires = $false\r\n                }\r\n\r\n                if ($EnableDate -and $EnableDate -gt (Get-Date)) {\r\n                    $UserSplat['Disabled'] = $true\r\n                }\r\n\r\n                if (-not $EnableDate -and $DisableAfterDays) {\r\n                    $UserSplat['AccountExpires'] = $(Get-Date).AddDays($DisableAfterDays)\r\n                }\r\n                elseif ($DisableAfterDays) {\r\n                    $UserSplat['AccountExpires'] = $(Get-Date $EnableDate).AddDays($DisableAfterDays)\r\n                }\r\n\r\n                if ($env:passwordOptions -like 'Password Never Expires' -or $PasswordOptions -like 'Password Never Expires') {\r\n                    $UserSplat['PasswordNeverExpires'] = $true\r\n                }\r\n\r\n                New-LocalUser @UserSplat\r\n                if ($env:passwordOptions -like 'User Must Change Password' -or $PasswordOptions -like 'User Must Change Password') {\r\n                    net.exe user $Username \/logonpasswordchg:yes\r\n                }\r\n                # Write it to a secure custom field\r\n                if ((Get-LocalUser -Name $Username -ErrorAction SilentlyContinue)) {\r\n                    Write-Host \"User $Username has been created successfully.\"\r\n                    if ($PasswordCustomField -like \"null\") {\r\n                        Write-Host \"CustomField not specified.\"\r\n                        Write-Host \"Password set to: $Password\"\r\n                    }\r\n                    else {\r\n                        Ninja-Property-Set -Name \"$PasswordCustomField\" -Value \"$Password\"\r\n                        Write-Host \"Password saved to $PasswordCustomField Custom Field.\"\r\n                    }\r\n                }\r\n                else {\r\n                    throw \"Failed to create User $Username.\"\r\n                }\r\n\r\n                Add-LocalGroupMember -Group $(Get-LocalGroup -Name \"Users\") -Member $Username\r\n\r\n                Write-Host \"User $UserName was added to the local Users group.\"\r\n\r\n                # If date to enable account is specified, disable account until then\r\n                if ($EnableDate) {\r\n                    if ($EnableDate -gt (Get-Date)) {\r\n                        # Schedule a job to enable the user at the specified date\r\n                        $TaskSplat = @{\r\n                            Description = \"Ninja Automation Enable User $Username\"\r\n                            Action      = New-ScheduledTaskAction -Execute \"powershell.exe\" -Argument \"-NoProfile -WindowStyle Hidden -Command &amp; {Enable-LocalUser -Name `\"$Username`\"}\"\r\n                            Trigger     = New-ScheduledTaskTrigger -Once -At $EnableDate\r\n                            Principal   = New-ScheduledTaskPrincipal -UserId \"SYSTEM\" -LogonType ServiceAccount\r\n                        }\r\n\r\n                        try {\r\n                            New-ScheduledTask @TaskSplat | Register-ScheduledTask -User \"System\" -TaskName \"Enable User $Username\" | Out-Null\r\n                            if ($(Get-ScheduledTask -TaskName \"Enable User $Username\")) {\r\n                                Write-Host \"Created Scheduled Task: Enable User $Username\"\r\n                            }\r\n                            else {\r\n                                throw \"Failed to find scheduled task with the name 'Enable User $Username'\"\r\n                            }\r\n                        }\r\n                        catch {\r\n                            Write-Error $_\r\n                            throw \"Failed to create Enable User scheduled task.\"\r\n                        }\r\n\r\n                        Write-Host \"User $Username will be able to login after $EnableDate.\"\r\n                    }\r\n                }\r\n                else {\r\n                    Write-Host \"No Enable Date is Set, $UserName is able to login now.\"\r\n                }\r\n\r\n                # Add to local admin group if specified\r\n                if ($AddToLocalAdminGroup) {\r\n                    Add-LocalGroupMember -Group $(Get-LocalGroup -Name \"Administrators\") -Member $Username\r\n                    if (-not (Get-LocalGroupMember -Group $(Get-LocalGroup -Name \"Administrators\") -Member $Username)) {\r\n                        throw \"Failed to add user to local Administrators group.\"\r\n                    }\r\n                    Write-Host \"User $UserName was added to the local Administrators group.\"\r\n                }\r\n            }\r\n            else {\r\n                Write-Host \"User $Username already exists.\"\r\n            }\r\n        }\r\n        else {\r\n            throw \"Username and Name are required to create a local account.\"\r\n        }\r\n    }\r\n}\r\nprocess {\r\n    if ($env:usernameToAdd -and $env:usernameToAdd -like \"null\") {\r\n        Write-Error \"usernameToAdd($env:usernameToAdd) parameter is invalid.\"\r\n        exit 1\r\n    }\r\n    if ($env:name -and $env:name -like \"null\") {\r\n        Write-Error \"name($env:name) parameter is invalid.\"\r\n        exit 1\r\n    }\r\n    if ($env:passwordCustomField -and $env:passwordCustomField -like \"null\") {\r\n        Write-Error \"passwordCustomField($env:passwordCustomField) parameter is invalid.\"\r\n        exit 1\r\n    }\r\n    if (-not (Test-IsElevated)) {\r\n        Write-Error -Message \"Access Denied. Please run with Administrator privileges.\"\r\n        exit 1\r\n    }\r\n    $params = @{\r\n        Username = if ($PSBoundParameters.ContainsKey(\"UserNameToAdd\")) { $UserNameToAdd }else { $env:usernameToAdd }\r\n        Name     = if ($PSBoundParameters.ContainsKey(\"Name\")) { $Name }else { $env:name }\r\n    }\r\n    # Conditionally add EnableDate\r\n    if ($env:dateAndTimeToEnable -and $env:dateAndTimeToEnable -notlike \"null\") {\r\n        $params[\"EnableDate\"] = Get-Date \"$env:dateAndTimeToEnable\"\r\n    }\r\n    elseif ($PSBoundParameters.ContainsKey(\"DateAndTimeToEnable\") -and $DateAndTimeToEnable) {\r\n        $params[\"EnableDate\"] = $DateAndTimeToEnable\r\n    }\r\n    # Conditionally add DisableAfterDays\r\n    if ($env:disableAfterDays -notlike \"null\") {\r\n        $params[\"DisableAfterDays\"] = $env:disableAfterDays\r\n    }\r\n    elseif ($PSBoundParameters.ContainsKey(\"DisableAfterDays\")) {\r\n        $params[\"DisableAfterDays\"] = $DisableAfterDays\r\n    }\r\n\r\n    # Conditionally add AddToLocalAdminGroup\r\n    if ([Convert]::ToBoolean($env:addToLocalAdminGroup)) {\r\n        $params[\"AddToLocalAdminGroup\"] = $true\r\n    }\r\n    elseif ($PSBoundParameters.ContainsKey(\"AddToLocalAdminGroup\")) {\r\n        $params[\"AddToLocalAdminGroup\"] = $AddToLocalAdminGroup\r\n    }\r\n    # Conditionally add AddToLocalAdminGroup\r\n    if ($env:passwordCustomField -notlike \"null\") {\r\n        $params[\"PasswordCustomField\"] = $env:passwordCustomField\r\n    }\r\n    elseif ($env:passwordCustomField -like \"null\") {\r\n        Write-Error \"passwordCustomField: is Required\"\r\n        exit 1\r\n    }\r\n    elseif ($PSBoundParameters.ContainsKey(\"PasswordCustomField\")) {\r\n        $params[\"PasswordCustomField\"] = $PasswordCustomField\r\n    }\r\n\r\n    if ($env:passwordLength -notlike \"null\") {\r\n        $PasswordLength = $env:passwordLength\r\n    }\r\n    elseif (-not $passwordLength) {\r\n        $PasswordLength = 20\r\n    }\r\n\r\n    try {\r\n        New-LocalUserFromNinja @params\r\n    }\r\n    catch {\r\n        Write-Error $_\r\n        exit 1\r\n    }\r\n}\r\nend {\r\n    \r\n    \r\n    \r\n}<\/pre>\n<p>&nbsp;<\/p>\n\n<div class=\"in-context-cta\"><p>Greifen Sie auf \u00fcber 300 Skripte im NinjaOne Dojo zu.<\/p>\n<p><a href=\"https:\/\/www.ninjaone.com\/de\/kostenlosetestversionformular\/\">Zugang erhalten<\/a><\/p>\n<\/div>\n<h2>Detailansicht<\/h2>\n<p>Das Skript ist in mehrere Schl\u00fcsselabschnitte unterteilt, in denen eine bestimmte Aufgabe erf\u00fcllt wird:<\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"1\" data-aria-level=\"1\"><strong>Definition der Parameter<\/strong>: Parameter wie <strong>UserNameToAdd<\/strong>, <strong>Name<\/strong> und <strong>DateAndTimeToEnable<\/strong> werden deklariert und erm\u00f6glichen die Anpassung der Benutzereingabe.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"2\" data-aria-level=\"1\"><strong>Funktionen<\/strong>: Kritische Funktionen wie <strong>Test-IsElevated<\/strong>, <strong>New-SecurePassword<\/strong> und <strong>New-LocalUserFromNinja<\/strong> werden definiert. <strong>Test-IsElevated<\/strong> pr\u00fcft auf Administratorrechte, <strong>New-SecurePassword<\/strong> generiert ein sicheres Passwort, und <strong>New-LocalUserFromNinja<\/strong> stellt die Kernfunktionalit\u00e4t der Benutzererstellung und -verwaltung dar.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"3\" data-aria-level=\"1\"><strong>Erstellung und Verwaltung von Benutzer:innen<\/strong>: Das Skript pr\u00fcft, ob der angegebene Benutzer existiert, erstellt einen neuen, wenn dies nicht der Fall ist, und legt Eigenschaften wie Passwort, Beschreibung und Ablauf des Kontos fest. Es verwaltet auch das Hinzuf\u00fcgen von Benutzer:innen zu Gruppen und plant Aufgaben f\u00fcr die Aktivierung\/Deaktivierung von Konten.<\/li>\n<\/ul>\n<h2>Potenzielle Anwendungsf\u00e4lle<\/h2>\n<p>Stellen Sie sich vor, ein MSP verwaltet die IT f\u00fcr ein Unternehmen mit tempor\u00e4rem Personal. Er kann dieses Skript verwenden, um die Kontoerstellung f\u00fcr neue Mitarbeiter:innen zu automatisieren, indem er bestimmte Aktivierungs- und Deaktivierungsdaten festlegt und so Zeit spart und manuelle Fehler vermeidet.<\/p>\n<h2>Vergleiche<\/h2>\n<p>Die Verwaltung von Benutzerkonten erfolgt traditionell mit manuellen Prozessen oder einfachen Skripten, denen fortgeschrittene Funktionen wie die Generierung sicherer Passw\u00f6rter oder die geplante Aktivierung\/Deaktivierung fehlen. Dieses Skript bietet einen ausgefeilteren, sichereren und zeitsparenderen Ansatz.<\/p>\n<h2>FAQs<\/h2>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"4\" data-aria-level=\"1\"><strong>Kann dieses Skript die Massen-Benutzererstellung verarbeiten?<\/strong><br \/>\nEs ist zwar f\u00fcr einzelne Konten konzipiert, kann aber mit \u00c4nderungen auch f\u00fcr die Massenerstellung angepasst werden.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"5\" data-aria-level=\"1\"><strong>Ist der Einsatz in sensiblen Umgebungen sicher?<\/strong><br \/>\nJa, es enth\u00e4lt Funktionen wie die sichere Passwortgenerierung.<\/li>\n<\/ul>\n<h2>Folgen<\/h2>\n<p>Die Verwendung eines solchen Skripts erh\u00f6ht die Sicherheit und Effizienz, unterstreicht aber auch die Notwendigkeit strenger Zugangskontrollen und \u00dcberwachungen, da die automatische Erstellung von Konten ein potenzieller Vektor f\u00fcr unbefugten Zugang sein kann, wenn sie nicht ordnungsgem\u00e4\u00df verwaltet wird.<\/p>\n<h2>Empfehlungen<\/h2>\n<p>Zu den Best Practices geh\u00f6ren die regelm\u00e4\u00dfige \u00dcberpr\u00fcfung von Skripten, die Verwendung in Verbindung mit robusten Pr\u00fcfungsrichtlinien und die Sicherstellung, dass nur befugtes Personal Zugriff auf das Skript und seine Funktionen hat.<\/p>\n<h2>Abschlie\u00dfende \u00dcberlegungen<\/h2>\n<p>Sie wissen nun, wie Sie ein neues lokales Benutzerkonto mit PowerShell erstellen k\u00f6nnen. Falls Sie Ihr System noch weiter optimieren wollen, ziehen Sie die Integration des Skripts in eine Endpunkt-Management-Plattform in Betracht, wie etwa NinjaOne. Diese Plattform, die f\u00fcr die <a href=\"https:\/\/www.ninjaone.com\/de\/\">Rationalisierung von IT-Managementaufgaben<\/a> bekannt ist, kann solche Skripte erg\u00e4nzen, indem sie eine zentrale und benutzerfreundliche Schnittstelle f\u00fcr die Verwaltung dieser automatisierten Prozesse bietet. Die Integration von PowerShell-Skripten in eine NinjaOne-Umgebung kann die <a href=\"https:\/\/www.ninjaone.com\/de\/effizienz\/\">betriebliche Effizienz<\/a> und Sicherheit der IT-Verwaltung erheblich verbessern.<\/p>\n","protected":false},"author":35,"featured_media":193896,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_relevanssi_hide_post":"","_relevanssi_hide_content":"","_relevanssi_pin_for_all":"","_relevanssi_pin_keywords":"","_relevanssi_unpin_keywords":"","_relevanssi_related_keywords":"","_relevanssi_related_include_ids":"","_relevanssi_related_exclude_ids":"","_relevanssi_related_no_append":"","_relevanssi_related_not_related":"","_relevanssi_related_posts":"","_relevanssi_noindex_reason":"","_lmt_disableupdate":"no","_lmt_disable":""},"operating_system":[4212],"use_cases":[4309],"class_list":["post-456540","script_hub","type-script_hub","status-publish","has-post-thumbnail","hentry","script_hub_category-windows"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/script_hub\/456540","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/comments?post=456540"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/media\/193896"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/media?parent=456540"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/operating_system?post=456540"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/use_cases?post=456540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}