我尝试使用PowerShell通过以下代码自动执行Bing搜索:
for ($a = 0; $a -lt 45; $a++) {
$RandomWord = Get-Random -InputObject (get-content C:\Users\ashq4\OneDrive\Documents\RandomwordList.txt)
$RandomQuestion = Get-Random -InputObject("what+is+","Definition+","Thesaurus+for+","Examples+of+","prefixes+for+","suffixes+for+")
Start-Process microsoft-edge:http://www.bing.com/search?q=$RandomQuestion$RandomWord -windowStyle Minimized
start-sleep -Milliseconds 1500
}
start-sleep -Milliseconds 2000
Start-Process microsoft-edge:https://www.bing.com/rewards/dashboard
write-Host Done
Break Script
这段代码在我的默认ms edge配置文件中打开了45个标签页。它使用来自文本文件的随机搜索词。
效果很好。我的问题是如何打开Edge浏览器中存在的所有配置文件,以便在单独的窗口中执行此自动化。例如,如果我有两个配置文件。我希望搜索发生在每个配置文件与单独的两个窗口进行搜索自动化在45个标签。即2个窗口中分别有45个选项卡。
我问了AI,它提供了这个:
function Execute-ProfileScript($profileArgument) {
# Execute the Bing.ps1 script 45 times
for ($j = 0; $j -lt 45; $j++) {
$RandomWord = Get-Random -InputObject (get-content C:\Users\ashq4\OneDrive\Documents\RandomwordList.txt)
$RandomQuestion = Get-Random -InputObject("what+is+","Definition+","Thesaurus+for+","Examples+of+","prefixes+for+","suffixes+for+")
Start-Process -FilePath "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" -ArgumentList "--profile-directory=$profileArgument http://www.bing.com/search?q=$RandomQuestion$RandomWord" -WindowStyle Minimized
Start-Sleep -Milliseconds 1500
}
Start-Sleep -Milliseconds 2000
Start-Process -FilePath "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" -ArgumentList "--profile-directory=$profileArgument https://www.bing.com/rewards/dashboard"
Write-Host "Done with $profileArgument"
}
# Get the list of existing profiles
$edgeUserDataPath = "$env:LOCALAPPDATA\Microsoft\Edge\User Data"
$profiles = Get-ChildItem -Path $edgeUserDataPath -Filter "Profile*" | ForEach-Object { $_.Name }
# Filter out the "Default" profile
$profiles = $profiles | Where-Object { $_ -ne "Default" }
foreach ($profileName in $profiles) {
# Open Edge with the specified profile
$profileArgument = "--profile-directory=$profileName"
Start-Process -FilePath "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" -ArgumentList "$profileArgument --no-first-run --no-default-browser-check --flag-switches-begin --flag-switches-end --site-per-process"
# Execute the script for the opened profile
Execute-ProfileScript -profileArgument $profileArgument
}
它创建自己的新配置文件。不像预期的那样工作,但不知何故,它正在打开配置文件,但创建新的。
1条答案
按热度按时间hc2pp10m1#
如果您想使用现有的配置文件,只需在代码中设置
$profileName
值即可。配置文件名称可以在配置文件路径下的 edge://version/ 中找到。例如,下图中的配置文件名称为Default:如果设置
$profileName = "Default"
,Edge将打开现有配置文件。