natalie.solero
Goto Top

Powershell GUI creating local users

Hi guys,

im trying to create a gui for creating local user accounts. the gui is just running fine but i have a problem creating the account. i need to convert the password to a securestring. whats the code for that and where i have to put it in?

Content-Key: 1770879202

Url: https://administrator.de/contentid/1770879202

Printed on: March 23, 2023 at 11:03 o'clock

Member: MrCount
MrCount Jan 28, 2022 at 09:07:16 (UTC)
Goto Top
Hi,

you can use ConvertTo-SecureString

Member: natalie.solero
natalie.solero Jan 28, 2022 updated at 09:43:44 (UTC)
Goto Top
@MrCount i know but i down't know where to add
doesn't work
Member: colinardo
colinardo Jan 28, 2022 updated at 10:22:40 (UTC)
Goto Top
Hi @natalie.solero,
there are multiple errors in your script, beginning from misspelled variables ($textbox2 does not exist) and other flaws, for example that you are not forcing the session to elevation, which is mandatory for creating local admin accounts.
This is a correction and should do what you expect from it.
I would strongly advise you to change your variable names to "speaking" one's instead, in the current form they do not show what they are intended for, this eliminates such dumb errors, and additionally saves our time face-wink.

Best regards
Uwe
Member: natalie.solero
natalie.solero Jan 28, 2022 at 10:22:21 (UTC)
Goto Top
Hi @colinardo
thank you very much for your reply and for your suggestions. i will definitive will look into it. at the moment i just copy and paste your script but unfortunately the script immediately ends up with an error i can't see because the windows closes
Member: colinardo
colinardo Jan 28, 2022 updated at 10:34:42 (UTC)
Goto Top
I tested it, and runs without problems.
but unfortunately the script immediately ends up with an error i can't see because the windows closes
To see the error, start an empty powershell console and start the script from there, then you can read the error. Alternatively start it like that from a batch cmd
This also forces the console to stay open. This command also suppresses the executionpolicy which is assigned to the machine. So if you haven't tweaked the executionpolicy it is time to do so now in an elevated console with:

Please note, the account wich runs the script needs to have admin rights on the machine, otherwise this will not work!

screenshot

at the moment i just copy and paste
Better learn the basics from the link library you can finde here
Powershell Leitfaden für Anfänger
Member: natalie.solero
natalie.solero Jan 28, 2022 updated at 11:36:16 (UTC)
Goto Top
Now it works . Thank you so much for that @colinardo
is it possible you can help me with another wish? i just modified your script for creating normal and admin accounts. that works fine.
i want to add a further checkbox with "no password" for creating normal user accounts without password.

why are your corners in the gui and messages round? is it win11 already?

this is what i have
Member: natalie.solero
natalie.solero Jan 28, 2022 updated at 12:31:51 (UTC)
Goto Top
@colinardo maybe I didn't express it correctly. i just have added a checkbox like in the picture. if i mark the checkbox "noPassword" i want to create a local user without a password. i don't want to enter a password in the password textbox
1
Member: colinardo
colinardo Jan 28, 2022, updated at Jan 29, 2022 at 13:42:23 (UTC)
Goto Top
i just have added a checkbox like in the picture.
Your posted code above did not have such a checkbox so i did not implement it :-P, thats your homework for today.

Member: MrCount
MrCount Jan 28, 2022 at 15:26:04 (UTC)
Goto Top
However, it would make sense if the "AdminAccount" and "noPassword" checkboxes were mutually exclusive....
Member: natalie.solero
natalie.solero Feb 15, 2022 at 06:18:27 (UTC)
Goto Top
Hey guys, sorry for the late reply. i wasn't good the last days.
@colinardo
i have changed line 92 to
and added
because i want that the user isn't able to change the password after login and the account never expires like in the picture below
what do i need to add?
1
2