Powershell Add-Content创建两个文件

时间:2016-01-06 13:58:13

标签: powershell

当我注释掉“真实”代码并使用Write-Host进行调试时,我得到了预期的结果。否则我最终得到两个文件。一个按计划命名,即 andrew.aboutme.html ,第二个命名为 W3Creports.andrew.aboutme.html (请注意W3Creports的不良前缀)。

两个文件的内容相同。

这是我在哪里......

$HtmlCheck += "https://validator.w3.org/nu/?doc="
$doc = "http://www.example.com/www1/"
$WebRoot = "C:/inetpub/wwwroot/myname/www1/"

$ReportFolder = $WebRoot + "W3Creports"
New-Item $Reports -ItemType Directory -Force 
Get-ChildItem -Path $Reports -Include *.* -File -Recurse | foreach { $_.Delete()}

# get a list of folders, i.e., the web site folders...  ignore any folders that have numbers in name
$Sites = (Get-ChildItem -Path $WebRoot -Directory | Where-Object {$_.Name -match "^[^\d]"}).Name

foreach ($site in $Sites)
{
    $SitePath = $WebRoot + $site
    $Pages = Get-ChildItem -Path $SitePath -File | Where-Object {$_.Name -match ".*\.htm.$"}

    foreach ($page in $Pages)
    {
        $url = $HtmlCheck + $doc + $site + "/" + $page.Name
        #$WebResponse = Invoke-WebRequest $url
        $results = "?" #$WebResponse.AllElements | Where id -eq "results"| Select -ExpandProperty innerHTML 


        $detail1 = "boo"  #"<h3>$($site).$($page) </h3>"  
        $detail2 = "W3C Nu HTML Validator " + (Get-Date).ToString()

       # Write-Host "$($ReportFolder)/$($site).$($page.Name)" "hi"
        Add-Content "$($ReportFolder)/$($site).$($page.Name)" "hi"
        #Add-Content $reportfile $detail2
        #Add-Content $reportfile $results
    }
}

0 个答案:

没有答案