Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 49146

invoke operation failing even with admin user

$
0
0

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

 


Viewing all articles
Browse latest Browse all 49146

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>