I am writing a script to import a list of computers from a CSV file, then reach out to each of these computers, pull all of their certificate information, and export it to a new CSV. The script that I have works perfectly, but I cannot get it to include the name of the computer in the final product. I have tried everything that I can possibly think of including creating a new PSObject, trying to pull the env:Computername, and trying to export the names from the original CSV but nothing is working!This will be run locally on a single PC.
Here is what the input looks like:
Server
Compname
Compname2
Compname3
Here is the export: This is dummy data ![1]: http://i.stack.imgur.com/lSHXK.png
Here is what I need the export to be: This is dummy data, the highlight is for example purposes only ![2]: http://i.stack.imgur.com/IPuSt.png
I will copy my code down below, but any assistance would be appreciated! I am relatively new at powershell and have been teaching myself exclusively, so please excuse any errors or redundancies in the code. The code already works perfectly except for not including the computername in it's export.
#Import File
$Serverlist = Import-Csv "C:\Servers.csv"
#Find Cert info
Foreach ($Server in $ServerList)
{
Write-Host "$Server"
$Servername = $Server
$Certlist = Get-ChildItem -Recurse Cert: | Select-Object Subject, Issuer, Thumbprint, FriendlyName, NotBefore, NotAfter, Extensions
}
#Export CSV
$Certlist | Export-CSV C:\ServerResults.csv