Wie lege ich einen lokalen Benuterz mithilfe eines Powersehll Skript an?
Hierzu möchte ich ein Formular vwerdenden.
Folgendes habe ich erstellt:
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = 'lokaler Benutzer'
$form.Size = New-Object System.Drawing.Size(300,200)
$form.StartPosition = 'CenterScreen'
$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75,120)
$okButton.Size = New-Object System.Drawing.Size(75,23)
$okButton.Text = 'OK'
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)
$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(150,120)
$cancelButton.Size = New-Object System.Drawing.Size(75,23)
$cancelButton.Text = 'Cancel'
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = 'Benutzername:'
$form.Controls.Add($label)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,70)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = 'vollständiger Name:'
$form.Controls.Add($label)
$Benutzername = New-Object System.Windows.Forms.TextBox
$Benutzername.Location = New-Object System.Drawing.Point(10,40)
$Benutzername.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($Benutzername)
$Name = New-Object System.Windows.Forms.TextBox
$Name.Location = New-Object System.Drawing.Point(10,90)
$Name.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($Name)
$form.Topmost = $true
$form.Add_Shown({$textBox.Select()})
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
$x = $textBox.Text
$x
}
New-LocalUser $Benutzername -FullName $Name
Before you deal with the whole GUI-Schnickscnack, at least the basics should be sitting around creating a user profile
so the theory…
… creates a new local use without a password… he also does. but it does not appear in the start menu. Unlike the Cmd bug: net user “TestUser001” /add Powershell does not automatically assign the user to a group, and since our new user does not belong to any group, our Start Menu/LoginScreen does not know how to handle it.
You can use the groups Get-LocalGroup view. Relevant are only administrators and users for you.
..and the new user appears in the Start menu/Register screen. Attention the groupsNames only work with a German Windows!!!! (how to make international is not important here first)
Now comes the next fall knit:
If you add the FullName, the parameter -nopasswort will be ignored and the new user must enter a password at the first login! You can handle this by simply creating the new user with an empty password.
Töräääähäh….
Now we want to get rid of the two birds…
Do not forget the folders of users under C:\users\ to delete if you have logged in. otherwise Windows rebuilds its own folder names when the same username reappears
…to the core business.
Your GUI:
the whole New-Object System.Drawing…. Qatsch is Idiodie of people who have been writing/paste for 15 years… Powershell automatically recognizes the data type .Size/.Point … just assign the values as string
I also donate an elevator stick to work with Localuser you need admin rights
…works and because I’m testing everything I’m posting here… I’m gonna have to clean my computer with the Kärcher 😅😅😅
Error message would have been useful.
You will need to enter a password or use the “nopassword” parameter
No, it’s not…
$textBox.Text is not defined… we also don’t get over.
In addition, New-LocalUser does not automatically assign a group binding, so the new user does exist, but only users of visible groups can be displayed in the login (administrator, user, guest). So a new user will not be displayed….
see above