Powershell export Certificates

Is all about powershell

Have created following ps1 :

```powershell

Import-Module ActiveDirectory

Vnos Lokacije

[string]$lokacija = Read-Host “Vnesi Lokacijo …”

Današnji Datum

$datum = Get-Date

$lokacija = $lokacija.ToUpper()

Od danes do 10 dni starih računalnikov / aktivnih 10 dni

$danes = $datum.AddDays(-10)

$podatek = Get-ADComputer -SearchBase “OU=$lokacija,DC=dc,DC=dc,DC=com” -Properties * -Filter {LastLogonDate -gt $danes} | Select Name
Foreach ($podatk in $podatek) {
Get-Childitem cert:LocalMachine\Root -Recurse
where-object { $_.Subject -like “$hostname” }
}

Export-Csv -Path “C:\Users\kkdruadmin\Desktop\Test.csv”

```

And this I would like to export to csv with data of HOSTNAMES in start of every cert (foreach)
Curently script is exporting all certificates but I can not split it by hostnames (Get-ADComputer|select name)

Please … How can I fix this.

It looks like you’re using the wrong variable in your Where-Object filter.

where-object { $_.Subject -like “$hostname” }

instead of

where-object { $_.Subject -like “$podatk” }

What do you think?