Teamcity powershell runner to remotely run commands on server

This was a mix of small issues, for 1 the user when queried via team city was not resolving the domain correctly so this needed to be added to the username some-user@some-domain. There was also an issue in that the there was some sort of connection limit which was being hit when doing the PSSESSION connection, however if I changed over to Invoke-Command with a script block it worked fine.

If it helps anyone here is the command I ended up with to unzip a remote file, using 7zip command line as the native solution never seemed to work.

$password = ConvertTo-SecureString "%TestServer.Password%" -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PsCredential("%TestServer.Username%",$password)

$scriptBlock1 = {`
`
    $sevenZip = "%TestServer.ReleasePath%\7za.exe"; `
    &$sevenZip x %TestServer.ReleasePath%\web-package.zip -o%TestServer.WebPath% * -aoa; `
}
Invoke-Command -computername %TestServer.Server% -Credential $credentials -scriptblock $scriptBlock1

One thing to remember is that the username contains the domain as listed above, also the magic quotes are needed to allow the script block to be spread over lines as well as the semi colon to indicate the tasks should be run together.