0

I have a PowerShell script that creates a local user and adds to the Admin group it's working when I'm running it but I've made an exe file from it. after execution, nothing happens

$UserName = Read-Host "UserName"
$UserPassword = Read-Host "Password" -AsSecureString
New-LocalUser -Name $UserName -Password $UserPassword -description 'NewUser'
Add-LocalGroupMember -Group "Administrators" -Member ("$UserName") -Verbose 

I've made exe file using the "PS2exe" module and "iexpress" can somebody help to fix it or create Log files for this exe

  • 1
    "*after execution, nothing happens*", not even a prompt for a "username"? What happens if you minimize the script to just `Read-Host "UserName"`? Note that programs generated with PS2EXE are sometimes identified as malware. Check the windows/virus eventlogs. Note that PS2EXE doesn't add any security, just obscures the script which could quiet easily be revealed. Saying that, if you need it to execute by double cliking you might also consider a `.bat` file with invokes a `PowerShell -EndodedCommand`, see e.g.: https://stackoverflow.com/a/73331681/1701026 – iRon Aug 24 '22 at 07:30
  • 1
    It seems mandatory to ask if this is being run with elevated privileges? – notjustme Aug 24 '22 at 07:31
  • Its opening window that requires Username and Password after adding credentials for the new user window was closed but the user don't add. The procedure requires Admin permission but I'm also run as admin. – Albert Ashkhatoyan Aug 24 '22 at 11:02
  • I have used start-transcript and it shows 'New-localUser : Object reference not set to an instance of an object' – Albert Ashkhatoyan Aug 24 '22 at 14:05

0 Answers0