I want to set the windows service to run as a particular user(admin). This is my first attempt.
$myArgs = 'config "service22" start= demand obj= "'+$machineName+'\'+$userName+'" password= "'+$userPassword+'"'
Start-Process -FilePath sc.exe -ArgumentList $myArgs
I also tried this by changing the position of the variable many times(all places tried)
$svc = Get-WmiObject win32_service -filter "name='service22'"
$svc.change($null,$null,$null,$null,$null,$null,$null,$null,$null,$userName,$userPassword)
Nothing works with scripts but manually I could set it.