Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell添加内容创建两个文件_Powershell - Fatal编程技术网

Powershell添加内容创建两个文件

Powershell添加内容创建两个文件,powershell,Powershell,当我注释掉“真实”代码并使用写主机进行调试时,我得到了预期的结果。否则我会得到两个文件。一个按计划命名,即,andrew.aboutme.html,第二个命名为W3Creports.andrew.aboutme.html(注意W3Creports的不需要的前缀) 两个文件的内容相同 这就是我现在的位置 $HtmlCheck += "https://validator.w3.org/nu/?doc=" $doc = "http://www.example.com/www1/" $WebRoot =

当我注释掉“真实”代码并使用写主机进行调试时,我得到了预期的结果。否则我会得到两个文件。一个按计划命名,即,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
    }
}
$HtmlCheck+=”https://validator.w3.org/nu/?doc="
$doc=”http://www.example.com/www1/"
$WebRoot=“C:/inetpub/wwwroot/myname/wwww1/”
$ReportFolder=$WebRoot+“W3Creports”
新项目$Reports-ItemType目录-Force
Get-ChildItem-Path$Reports-Include*.-File-Recurse | foreach{$\.Delete()}
#获取文件夹列表,即网站文件夹。。。忽略名称中包含数字的任何文件夹
$Sites=(Get ChildItem-Path$WebRoot-Directory | Where Object{$\名称-match“^[^\d]”).Name
foreach($站点中的站点)
{
$SitePath=$WebRoot+$site
$Pages=Get ChildItem-Path$SitePath-File |其中对象{$\.Name-match.*\.htm.$”}
foreach($页中的页)
{
$url=$HtmlCheck+$doc+$site+“/”+$page.Name
#$WebResponse=调用WebRequest$url
$results=“?”#$WebResponse.allegements |其中id-eq“results”|选择-ExpandProperty innerHTML
$detail1=“boo”#“$($site)。$($page)”
$detail2=“W3C Nu HTML验证程序”+(获取日期).ToString()
#写入主机“$($ReportFolder)/$($site)。$($page.Name)”hi
添加内容“$($ReportFolder)/$($site)。$($page.Name)”hi
#添加内容$reportfile$detail2
#添加内容$reportfile$结果
}
}

您在
$WebRoot
内部创建了
$ReportFolder
,因此它被视为
$Sites
之一。所以它也验证和报告了,啊哈!!当然谢谢我盯着它看了太久了。你在
$WebRoot
中创建了
$ReportFolder
,所以它被认为是
$Sites
之一。所以它也验证和报告了,啊哈!!当然谢谢我盯着它看太久了。