I know that I'm fundamentally missing something here but I am taking what I have constructed so far (in 1 day's time) and asking for assistance in figuring out how to take variables from a query and inserting them into a event log. Here's what I have so far - but I suspect that I need to handle the variables in a more robust way in the event that there's
#Run a query to get a collection
$colItems=some query
foreach ($objItem in $colItems) {
#declare $objItem variables for each item in collection
$Id=$objItem.RequestID
$SerialNumber= $objItem.SerialNumber
}
#Write an entry in the Application log of the local system
write-eventlog -logname Application -source CertWatch -eventID 1001 -entrytype Warning -message "This cert $id with serial number $SerialNumber is within 30 days of expring."