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 用Firefox截图_Powershell_Firefox_Start Process - Fatal编程技术网

Powershell 用Firefox截图

Powershell 用Firefox截图,powershell,firefox,start-process,Powershell,Firefox,Start Process,我花了很长时间才弄明白为什么这个简单的命令不起作用 我正试图根据[本文][1]截取使用PowerShell和Firefox的域名列表 目前,我有以下代码,但它不产生截图,我不确定是什么错误的代码明智。非常感谢在正确方向上的任何帮助和/或要点 $screenshotdir = "$PSScriptRoot\FF_Screenshots" If(!(Test-Path -Path $screenshotdir)) {New-Item -Path $PSScriptRoot -Name "FF_Scr

我花了很长时间才弄明白为什么这个简单的命令不起作用

我正试图根据[本文][1]截取使用PowerShell和Firefox的域名列表

目前,我有以下代码,但它不产生截图,我不确定是什么错误的代码明智。非常感谢在正确方向上的任何帮助和/或要点

$screenshotdir = "$PSScriptRoot\FF_Screenshots"
If(!(Test-Path -Path $screenshotdir)) {New-Item -Path $PSScriptRoot -Name "FF_Screenshots" -ItemType Directory}

    function getFireFoxScreenShot() {
        $importedCSV = Import-Csv .\Domains.csv

        foreach ($url in $importedCSV) {
            $domainName = $url.Name #example google.com
            $domain = $url.Domain #example google (no tld)
            if (-not ([string]::IsNullOrEmpty($domainName))){       
                Echo "Getting Screen Shot for: $domainName"
                Start-Process -FilePath "C:\Program Files\Mozilla Firefox\firefox.exe " -ArgumentList " --screenshot $screenshotdir\$domain.png ", "$domainName" -Wait            
            }
       }
    }
    getFireFoxScreenShot

[1]: https://www.bleepingcomputer.com/news/software/chrome-and-firefox-can-take-screenshots-of-sites-from-the-command-line/

确保指定协议(
https://
http://
)与您链接到的文章中的协议相同:

# Tested with Developer Edition of Firefox
$domain = "example"
$domainName = example.com"
$screenshotdir = "C:\SO\56572800"


# This works
Start-Process -FilePath "C:\Program Files\Firefox Developer Edition\firefox.exe" -ArgumentList "--screenshot $screenshotdir\$domain-with-https.png", "https://$domainName" -Wait

# But doesn't work
Start-Process -FilePath "C:\Program Files\Firefox Developer Edition\firefox.exe " -ArgumentList " --screenshot $screenshotdir\$domain-no-https.png ", "$domainName" -Wait
根据我的检查,如果您不指定
https://
前缀(或
http://
如果适用),它将挂起很长时间,因此您可能会觉得它正在工作


如注释中所述,您必须确保
$screenshotdir
的值已正确分配并可用于函数

此外,从命令中修剪前导/尾随空格也是一种很好的做法,即使在您的示例中,它仍然适用于空格。我指的是这些:

                                                                HERE |          HERE |                                    HERE |
Start-Process -FilePath "C:\Program Files\Mozilla Firefox\firefox.exe " -ArgumentList " --screenshot $screenshotdir\$domain.png ", "$domainName" -Wait     

$screenshotdir
设置为什么?控制台是否有任何输出?您好,目前我无法测试有关firefox的任何解决方案。但是试着使用文章中的cmd代码。然后将其构建为一个字符串并执行以下操作:调用表达式$CmdLine希望它有所帮助!BRI编辑了这篇文章以反映$screenshotdirNo控制台输出。CLI只是停留在那里/挂起。我可以在我的任务列表中看到firefox,所以它正在被调用和运行。