Powershell export Certificates

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Daniel Krebs Daniel Krebs 3 weeks, 5 days ago.

  • Author
  • #54644
    Profile photo of Dušan RUPNIK
    Dušan RUPNIK

    Is all about powershell

    Have created following ps1 :


    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.

  • #54646
    Profile photo of Daniel Krebs
    Daniel Krebs

    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?

You must be logged in to reply to this topic.