您必须明确选择您正在执行的属性,但它不能为空,因此您必须捕捉这种可能性。
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$path = "https://www.broadcom.com/support/security-center/definitions/download/detail?gid=sep14"
($definitionPath = (Invoke-WebRequest $path).Links)
<#
# Results
innerHTML : Cookie Policy.
innerText : Cookie Policy.
outerHTML : <a class="banner-policy-link" aria-label=" Cookie Policy." href="https://www.broadcom.com/company/legal/cookie-policy"> Cookie Policy.</a>
outerText : Cookie Policy.
tagName : A
class : banner-policy-link
aria-label : Cookie Policy.
href : https://www.broadcom.com/company/legal/cookie-policy
innerHTML : More Information
innerText : More Information
outerHTML : <a aria-label="More Information" onclick="Optanon.TriggerGoogleAnalyticsEvent('OneTrust Cookie Consent', 'Preferences Cookie Policy');"
href="https://cookiepedia.co.uk/giving-consent-to-cookies" target="_blank">More Information</a>
outerText : More Information
tagName : A
aria-label : More Information
onclick : Optanon.TriggerGoogleAnalyticsEvent('OneTrust Cookie Consent', 'Preferences Cookie Policy');
href : https://cookiepedia.co.uk/giving-consent-to-cookies
target : _blank
innerHTML : <div title="powered by OneTrust" id="optanon-popup-bottom-logo" style='background:
url("https://cdn.cookielaw.org/skins/5.9.0/default_flat_bottom_two_button_black/v2/images/cookie-collective-top-bottom.png"); width: 155px;
height: 35px;' alt="OneTrust Website"></div>
innerText :
outerHTML : <a href="https://onetrust.com/poweredbyonetrust" target="_blank" rel="noopener"><div title="powered by OneTrust" id="optanon-popup-bottom-logo"
style='background: url("https://cdn.cookielaw.org/skins/5.9.0/default_flat_bottom_two_button_black/v2/images/cookie-collective-top-bottom.png");
width: 155px; height: 35px;' alt="OneTrust Website"></div></a>
outerText :
tagName : A
href : https://onetrust.com/poweredbyonetrust
target : _blank
rel : noopener
#>
Try
{
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$path = "https://www.broadcom.com/support/security-center/definitions/download/detail?gid=sep14"
($definitionPath = (Invoke-WebRequest $path).Links) |
Where-Object{$_.InnerText -like "*core15sdsv5i64.exe" -and $_.InnerText -notlike "*.jdb"} |
Select-Object -ExpandProperty href
}
Catch {Write-Warning -Message 'The target resource is not found or is blank'}
Finally {Write-Warning -Message 'Some other issue occurred'}
<#
# Results
Some other issue occurred
#>
就个人而言,我会对此进行重构以获得更直接的参考
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$path = "https://www.broadcom.com/support/security-center/definitions/download/detail?gid=sep14"
($definitionPath = (Invoke-WebRequest $path).Links).href
<#
https://www.broadcom.com/company/legal/cookie-policy
https://cookiepedia.co.uk/giving-consent-to-cookies
https://onetrust.com/poweredbyonetrust
#>
($definitionPath = (Invoke-WebRequest $path).Links).href |
Select-String -Pattern 'cookie'
<#
https://www.broadcom.com/company/legal/cookie-policy
https://cookiepedia.co.uk/giving-consent-to-cookies
#>