title: How to add a user to Windows 10 using python and powershell
body: <p>I am trying to add a user to windows 10 using a python script that uses powershell to add the user.</p>
  
  <p>Here is what I have so far:</p>
  
  <p>main.py</p>
  
  <pre><code>import subprocess as sub
  import os
  
  
  username = testUser
  passwds = passwordTest
  
  command = """
  $nusnm = """ + '"{}"'.format(username) + """
  $nuspss = ConvertTo-SecureString """ + '"{}"'.format(passwds) + """ -AsPlainText -Force
  New-LocalUser -Name $nusnm -Password $nuspss
  Add-LocalGroupMember -Group "Administrators" -Member $nusnm
  Get-LocalUser
  """
  print(command)
  exec = sub.Popen(["powershell","&amp; {" + command + "}"])
  
  </code></pre>
  
  <p>Also if it helps, this is the Powershell code that I am basing it off of which does work:</p>
  
  <pre><code>$nusnm = Read-Host -Prompt 'What would you like the name of the user to be? '
  $nuspss = Read-Host -Prompt -AsSecureString 'Please input a new password for the user '
  New-LocalUser $nusnm -Password $nuspss -Confirm
  Add-LocalGroupMember -Group "Administrators" -Member $nusnm
  Get-LocalUser
  </code></pre>
  
  <p>When I execute this python code, I do not get any errors, but I also do not get an added user named testUser. What am I doing wrong? </p>
  
  <p>Any help is greatly appreciated</p>