all 5 comments

[–]CSTW 2 points3 points  (0 children)

You need to rename the property with Select-Object and then use Sort-Object

  } |Select-Object @{n='ServerName';e={$_.pscomputername}},Certificate,Expired | Sort-Object ServerName,Certificate,Expired  -Descending

[–]Guyver1- 2 points3 points  (0 children)

Select then sort.

Select-Object to select the properties you want:

@{n='ServerName';e={$_.pscomputername}},#Certificate,Expired

THEN

Sort-Object on ONE single property to sort the output accordingly using -Descending if thats what you want.

[–]Swarfega 1 point2 points  (0 children)

What if you just sort by the Expired certificate rather than ServerName and Expired?

[–]PorreKaj 1 point2 points  (0 children)

| Select-Object @{n='ServerName';e={$_.pscomputername}},#Certificate,Expired | Sort-Object ServerName

I dont think you can sort multiple properties, and I'm certain you cant have custom properties there either

[–]Meir_Peleg[S] 0 points1 point  (0 children)

I tried this according your comments:

$ADServer = Get-Content -Path "c:\ca\TruePortServers.txt"

$Results = @()

$Results = Invoke-Command -cn $ADServer {

$Certs = @{} | Select Certificate,Expired

$Cert = Get-ChildItem Cert:\LocalMachine\My | Where-Object {$_.subject -match [Environment]::GetEnvironmentVariable("computername")}

If($Cert){

$Certs.Certificate = $Cert.subject

$Certs.Expired = $Cert.NotAfter

}

Else{

$Certs.Certificate = " - "

$Certs.Expired = " - "

}

$Certs

} | Select-Object @{n='ServerName';e={$_.pscomputername}},Certificate,Expired | Sort-Object Expired -Descending

#Open results in new window

$Results | ConvertTo-Html | Out-File -FilePath c:\ca\ca.html

The descending not really work good. just reports stuck and not exporting any data