格式阵列内部阵列以后用作电子邮件主体



我在脚本的早期创建一个空的$array,后来我循环浏览一些内容,并希望将这些内容添加到我的数组中。这是按预期工作的。

$AspxFiles = gci $path $filter -r | ? { $_.DirectoryName -notlike '*Werkstatt*' -and `
                                        $_.DirectoryName -notlike '*- Kopie*'   -and `
                                        $_.DirectoryName -notlike '*.1*'        -and `
                                        $_.DirectoryName -notlike '*.0*'        -and `
                                        $_.DirectoryName -notlike '*.2*'        -and `
                                        $_.Name -notlike '*- Kopie*'
                                        }
$array = @()
foreach ($file in $AspxFiles)
{
    $getURL = sls -Path $file.FullName -Pattern $regex -AllMatches | ? { $_ -notlike '*www.w3.org*' -and `
                                                                         $_ -notlike '*jquery.com*' -and `
                                                                         $_ -notlike '*www.mwe*' } | 
    % { $_.Matches } | % { $_.Value }
    foreach ($URL in $getURL)
    {
        $Request = [System.Net.WebRequest]::Create($URL)
        $Response = $Request.GetResponse()
        $Status = [int]$Response.StatusCode
        if ($Status -ne 200 -or $Response.ResponseUri -like '*PageNotFound*') 
        { 
            $x = [PSCustomObject] @{
                File = $file.Name
                URL  = $URL
            } ; $array += $x
        }
        $Response.Close()
    }
}

但是$array的输出是这样的:

@{File=B-1.56.aspx; URL=http://sdfsdfsdf/b-1.39.4_fr1_d.pdf}
@{File=B-1.56.aspx; URL=http://sdfsdfsdfssd/b-1.39.4_fr1_d.pdf}
@{File=B-1.58.aspx; URL=https://sdfffssd/b-1.39.6_de_d.pdf}
@{File=B-1.58.aspx; URL=https://fsdfsfb-1.39.6_de_d.pdf}

我如何像列表一样获得此格式,以便我可以抓住FileURL属性以将其作为电子邮件主体发送?:

$body = $array | sort File | ConvertTo-Html -Property File,URL -Head "<html><h2>Folgende Links wurden im Katalog nicht gefunden:</h2><br></html>" | Out-String

看起来这仍然只是脚本的一部分,但是:

  • 我会用OR'ED |条目将您的Anded通配符转换为-NotMatch Regex
  • 并设置$array = Foreach($file ...收集所有Ouput

$REDir = '.*Werkstatt.*|.*- Kopie.*|.*.[012].*'
$REURL = '.*www.w3.org.*|.*jquery.com.*|.*www.mwe.*'
$AspxFiles = Get-ChildItem $path $filter -r | 
    Where-Object { $_.DirectoryName -notmatch $REDir  -and `
                            $_.Name -notlike  '*- Kopie*'}
$array = @()
$array = foreach ($file in $AspxFiles) {
    $getURL = Select-String -Path $file.FullName -Pattern $regex -AllMatches | 
        Where-Object { $_ -notmatch $REURL } | 
           ForEach-Object { $_.Matches } | ForEach-Obkect { $_.Value }
    ForEach ($URL in $getURL) {
        $Request = [System.Net.WebRequest]::Create($URL)
        $Response = $Request.GetResponse()
        $Status = [int]$Response.StatusCode
        if ($Status -ne 200 -or $Response.ResponseUri -like '*PageNotFound*') { 
            [PSCustomObject] @{
                File = $file.Name
                URL  = $URL
            }
        }
        $Response.Close()
    }
}
$body = $array | Sort-Object File | 
    ConvertTo-Html -Property File,URL -Head `
      "<html><h2>Folgende Links wurden im Katalog nicht gefunden:</h2><br></html>" | 
        Out-String

最新更新