How do I pass an array or list as a parameter to a PowerShell function?
Try this:
function CheckCert([string[]]$ComputerNames)
{
$deadline = (Get-Date).AddDays($global:threshold) # Set deadline date
foreach ($computer in $ComputerNames)
{
Invoke-Command -ComputerName $Computer { Dir Cert:\LocalMachine\My } |
foreach {
If ($_.NotAfter -le $deadline)
{
$_ | Select Issuer, Subject, NotAfter, @{N="Expires In (Days)";E={($_.NotAfter - (Get-Date)).Days}}
}
}
}
}
Working with PS 4.0 or later, it´s possible to define as CheckCert([array]$ComputerNames)
as well.