Execute remote PowerShell script from VSOnline fails - Access Denied - powershell

I am facing a very strange issue trying to run a Remote PowerShell script from the new build system of Visual Studio Online.
Context:
I have a Build server that I host on my own VM. I have also created a second VM where I want the PowerShell script to be run on.
When I run a build from the Build server, I want to create a task that run a PowerShell script on a remote machine. Sounds easy.
Both machines have everything configured to run the Remote PowerShell. (I think)
Problem:
If I manually run the script from the build server, the script is properly executed on my remote machine.
But, if I run the script by starting a new build, it doesn't work, I always get an error message
New-PSSession : [xxx.cloudapp.net] Connecting to remote server xxx.cloudapp.net failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
Have you faced this issue before with VSOnline?

This can happen if there isn't a trust relationship between the remote machine and the build machine. E.g. you could look at the hosts.equiv file on the remote machine and make sure it trusts the build machine.
If that doesn't help then more info might be needed, like how you're trying to sign in, what build agent account you're running as.
Guy

Related

How do I get remote access with PowerShell?

I want to connect to a specific set of laptops on our domain remotely. I need to have it log to the C drive, and search out a specific folder, then report back on a specific file contained in the folder.
I have found scripts that have shown me how to locate and show if the path exists, along with a specific file name at the end of the path. I created a test file on my laptop and the script worked flawlessly.
However, I need it to reach out over our domain, log into the target laptop, locate the file and contents then create a report on the findings. This will need to be done over VPN to the devices on our network.
My main issue at this point is finding the commands to invoke PowerShell to log onto the remote computers.
A rough overview on how to remote execute commands with PowerShell.
Enable PSRemoting with Enable-PSRemoting MS docs
Establish a remote connection with Enter-PSSession -ComputerName testserver123.global.local
This opens a prompt of the remote server where you can run commands. Your PS prompt will get a prefix indicating the remote server.
A useful link is here from 4sysops

Is it possible to run Copy-VMFile powershell command as non-admin?

I have a host machine with Hyper-V enabled, and I have a Hyper-V guest running on this machine. Becauze I can't drag&drop files to the VM, I wrote a script to do this for me, which is integrated in TotalCommander, and which uses Copy-VMFile.
My problem is that the PS script works only if I run it as admin, otherwise I get the error "You do not have the required permission to complete this task."
Why do I need admin to copy from the host machine to the guest OS? And is there a way, some policy which would allow me to circumvent this? It is annoying to enter a password every time I want to copy some files.

Checking out code to a remote server via powershell

I am trying to run a batch file that checks out code from a repo. This file is on a different server and i am trying to run it using powershell from my local machine after enabling remoting. when I use Invoke command nothing is returned on my powershell. If i directly try to checkout the code using svn command to the remote server i get svn access forbidden error. Is there a way to resolve this

Can't execute MSTest through powershell remote session

I'm unable to execute MSTest on a remote machine from within a powershell remote session, but it works perfectly if I'm logged into that remote machine and run it locally. My guess is that this indicates a permissions issue of some sort, but I have been unable to determine the problem. Here's the 2-liner I use to execute the tests successfully (locally) on the target machine:
PS> $params = #("/testcontainer:MyTests.dll", "/nologo", "/detail:stdout")
PS> & "MSTest" $params
I'm getting the following error when I attempt this through a PSRemote session:
Run has the following issue(s):
Test host process exited unexpectedly.
Failed to queue test run 'username#machinename 2015-08-10 03:30:18': Unable to start the agent process.
Any ideas what might be going on here? I'm using the same credentials to create the PSSession as I use when logging into the target machine with Remote Desktop, but apparently that's no good. Is it possible that because the tests use Selenium ChromeDriver there's some issue with starting a GUI program remotely?

How to uninstall a service on remote machine using powershell?

I am a newbie in powershell script. I want to uninstall a service on remote machine and re-install it again. I am able to stop the service, change the files that service is using and again start it.
But, now I want to completely uninstall it.
One more thing, I will be executing these scripts via TeamCity.
I have tried following ways, but each one is giving trouble:
using wmi class
running installutil command on remote machine. But, cant execute this on remote machine since there is problem in accessing that service.
Using Get-WmiObject command and then calling delete() on retrieved service.
Is there any promising solution ??
Any help will be appreciable..
After playing a lot with TC and many commands, finally I got my answer to uninstall a service on remote computer, and its working properly.
I have made use of "wmic" command and provided the remote computer name, username and password for /node:, /username:, and /password: parameters. And, provided 'installutil.exe' command to be executed remotely. Here, the actual command is..
"wmic /NODE:$serverName /USER:$userName /PASSWORD:$password process call create '$path_to_installutil_exe\installutil /u $exe_location_path_of_service'"