Get-ChildItem, help to get right result that I expeded.

Hello. I am a beginner of the powershell.

I need to check the expiry date by powershell, So I googled it!

Here’s the script that I copied from somewhere.

$daysremain=30
$certs = Get-ADComputer -Filter {Enabled -eq $True -and OperatingSystem -like “*Server*” -and Name -like “test*”} -SearchBase “OU=testgroup, OU=Server, OU=inhous, DC=test, DC=com” |% {Invoke-Command -ComputerName $_.name -ScriptBlock {Get-ChildItem cert:\LocalMachine\my -Recurse | Where-Object {$_ -is [System.Security.Cryptography.X509Certificates.X509Certificate2] -and $_.NotAfter -gt (Get-Date) -and $_.NotAfter -lt (Get-Date).AddDays($daysremain)| Select-Object PSComputerName, FriendlyName, NotAfter, Subject, Issuer}}}
Write-Output $certs

And then, I could not get the right result that I expected. Only I could see these objects

“Thumbprint, Subject, PSComputerName”.

I have no Idea what I have to do to figure it out.

Can you help me??

I’m sorry for not being fluent in English. If you don’t understand, please reply.

 

 

If I am reading correctly, you are looking for certificates that expire in 30 days, correct?

# Get list of servers
$certs = Get-ADComputer -Filter {
Enabled -eq $True -and OperatingSystem -like “*Server*” -and Name -like “test*”
} -SearchBase “OU=testgroup, OU=Server, OU=inhous, DC=test, DC=com”

# Get certs that expire in 30 days
$result =
Invoke-Command -ComputerName $certs.Name -ScriptBlock {
    Get-ChildItem cert:\LocalMachine\my -Recurse | 
    Where-Object {$_.NotAfter -eq (Get-Date).AddDays(30)} |
    Select-Object FriendlyName, NotAfter, Subject, Issuer
}

$result | Select-Object PSComputerName,FriendlyName,
NotAfter,Subject,Issuer