1 2 Previous Next 24 Replies Latest reply on Feb 13, 2019 5:27 AM by Vineeth

    invoke operation failing even with admin user

    Vineeth Hot Shot

      I am trying to create a user on windows machines but its failing  with this message "This operation requires an interactive window station" but if i login to the machine and open powershell as runasadmin and execute below script ($script)its working. Is there anyway to achieve this task over invoke-vm cmdlet.

      The guest user which i am using while invoke-vm has administrative rights on the machine.

      $script = @'
      function Elevate-Process  {
      param ([string]$exe = $(Throw "Pleave provide the name and path of an executable"),[string]$arguments)
      $startinfo = new-object System.Diagnostics.ProcessStartInfo 
      $startinfo.FileName = $exe
      $startinfo.Arguments = $arguments 
      $startinfo.verb = "RunAs" 
      $process = [System.Diagnostics.Process]::Start($startinfo)
      }
      Elevate-Process -Exe powershell.exe -Arguments "-noninteractive -command 
      $newUser = 'swops'
      $pswd = 'Ann0tat10n'
      $localusers=Get-LocalUser | Select Name
      if($localusers -notcontains $newUser){
      # Create user
      $securePswd = ConvertTo-SecureString -AsPlainText -String $pswd -Force
      New-LocalUser -Name $newUser -Password $securePswd -Confirm:$false
      }
      else{
      # Change Password for Existing user
      $localadministrator=[adsi]("WinNT://./swops, user")
      $localadministrator.psbase.invoke("SetPassword", "$pswd")
      Set-LocalUser -Name 'swops' -PasswordNeverExpires 1
      net localgroup Administrators swops /ADD
      }
      "
      '@
      Invoke-VMScript -VM 'WUSALP810003' -ScriptText $script -ScriptType Powershell -GuestUser '' -GuestPassword '' |Select -ExpandProperty ScriptOutput
      
      

       

      Regards
      Vineeth.K
        1 2 Previous Next