I have a rather strange issue, when I use the following code to retrieve the PS version from a list of servers, the PS version is truncated. However this doesn’t happen all the time, as when I query a short list of servers the output is ok.
$pcs = Get-ADComputer -Filter "OperatingSystem -like 'Windows 2012 R2 Standard'" -Properties OperatingSystem
foreach ($computer in $pcs)
Try {
$psver=invoke-command -computername ($Computer.name) -ScriptBlock {$PSVersionTable.PSVersion.ToString();}
$ResultObject = New-Object PSObject -Property @{PSVer = $psver; ComputerName = ($Computer.name)}
$Resultobject
}
Catch
{
Write-Host "Error: $($_.Exception.Message)
}
}
Output:
ComputerName PSVer TEST01 4.0 TEST02 4.0 TEST03 5....
I did also add $FormatEnumerationLimit = -1, didn;t seem to make any difference.
Any help much appreciated.
Thanks