I have a strange issue using remoting with Powershell.
I have a script called dothis.ps1 which does the following:
$s = New-PSSession -ComputerName $someServer -Authentication CredSSP -Credential $credential
$result = Invoke-Command -Session $s { param($dropLocation) C:\somScript.ps1 @PSBoundParameters } -ArgumentList $DropLocation
This script is executed by the InvokeProcess
of Microsoft.TeamFoundation.Build.Workflows.Activities
The issue I have is that if I print out the version of Powershell from the dothis.ps1, I have 2.0.
But if I print out the version of the Powershell from the remote script (somSecript.ps1), it gives me 1.0.
I wanted to know the version of the powershell I was running because the following command does not work: $Host.Runspace.ThreadOptions
Can somebody explain me what is going on? Thanks.
The version value you're reading comes out of the registry apparently, even though you're on a newer version of PS (since PS v1 doesn't support sessions). Reading this other StackOverflow article pointed me to $psversiontable
, which should get you exactly what you're after.