How do I pass an array or list as a parameter to a PowerShell function?

前端 未结 2 1297
感情败类
感情败类 2021-02-19 00:13

I am writing a PowerShell script to get a list of certificates which are getting expired within 30 days. The script is working, but the problem is there are too many app and pre

2条回答
  •  盖世英雄少女心
    2021-02-19 00:40

    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}}
                }
            }
        }
    }
    

提交回复
热议问题