【问题标题】:Generating a list of all self-signed certs?生成所有自签名证书的列表?
【发布时间】:2019-09-25 18:44:32
【问题描述】:

我正在尝试使用 Powershell 在环境中生成所有自签名证书的列表。

我需要将脚本的这一部分定向到多台机器(IP 地址),但我不知道该怎么做:

dir cert: -Recurse |
where {$_.subject -ne $null} |
where {$_.subject -eq $_.issuer} |
Export-Csv -NoTypeInformation -Encoding UTF8 -delimiter ';' -path .\ssc_export

Powershell 不是我的强项,但它是我在这种环境中可用的全部。任何见解将不胜感激!

【问题讨论】:

    标签: encryption certificate


    【解决方案1】:

    假设 WinRM is configured 并且您拥有所需的权限,这将起作用:

    $computers = Get-Content -Path "R:\computers.txt"
    
    $Results = @()
    
    ForEach ($Computer in $Computers) {
      $Results += Invoke-Command -ComputerName $Computer -ScriptBlock { 
    
        $storeNames = @();
        foreach($store in Get-ChildItem -Path "cert:CurrentUser" `
          | Where-Object { $_.Name -ne 'UserDS' } ` # filter UserDS: https://stackoverflow.com/questions/57116536/powershell-fails-when-trying-to-read-certificate-store-with-the-specified-netwo/57278095#57278095
        ){
          $storeNames += "cert:CurrentUser\$($store.Name)";
        }
        foreach($store in Get-ChildItem -Path "cert:LocalMachine"){
          $storeNames += "cert:LocalMachine\$($store.Name)";
        }
    
        $storeNames | % { Get-ChildItem -Path $_ } `
        | where {$_.subject -ne $null} `
        | where {$_.subject -eq $_.issuer} `
        | select-object -property `
            @{ Name="Computer"; Expression={$env:COMPUTERNAME} }, `
            @{ Name="Path"; Expression={$_.PSParentPath} }, `
            @{ Name="Subject"; Expression={$_.Subject} }, `
            @{ Name="Issuer"; Expression={$_.Issuer} } `
        | Format-Table
      };       
    }
    
    $Results
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-18
      • 1970-01-01
      • 2014-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-08
      相关资源
      最近更新 更多