gpt4 book ai didi

powershell - 如何剥离添加到 “adding trusted sites?”中所需的详细信息

转载 作者:行者123 更新时间:2023-12-02 23:13:29 26 4
gpt4 key购买 nike

我们的应用程序使用包含以下详细信息的url文件

[DEFAULT]
BASEURL=http://MachineName:1800/App/LandingPage.aspx
[InternetShortcut]
URL=http://MachineName:1800/App/LandingPage.aspx

我需要将此URL添加到受信任的站点。

所以首先我需要单独获取 http://MachineName
如果我运行followind命令,它具有BASEURL所在的完整行。
$URL = Get-content FileName.url | Select-string -pattern "BASEURL"

如何使用Powershell仅从 http://MachineName获取内容?

最佳答案

Select-String cmdlet返回 bool(boolean) 值或MatchInfo。根据documentation:

Outputs Microsoft.PowerShell.Commands.MatchInfo or System.Boolean By default, the output is a set of MatchInfo objects, one for each match found. If you use the Quiet parameter, the output is a Boolean value indicating whether the pattern was found.



如果在不使用 -quiet的情况下进行了多次匹配,则将获得 MatchInfo对象的数组。可以像这样通过 Matches[]数组的 Value属性访问结果,
PS C:\> $URL = Get-content \temp\FileName.url | Select-string -pattern "(http://[^:]+)"
PS C:\> $URL

BASEURL=http://MachineName:1800/App/LandingPage.aspx
URL=http://MachineName:1800/App/LandingPage.aspx

PS C:\> $URL[0].Matches[0].value
http://MachineName
PS C:\> $URL[1].Matches[0].value
http://MachineName

为了只捕获不带前缀的BASEURL字符串,请像这样使用非捕获组,
PS C:\> $URL = Get-content \temp\FileName.url | Select-string -pattern "(?:BASEURL=)(http://[^:]+)"
PS C:\> $url

BASEURL=http://MachineName:1800/App/LandingPage.aspx

PS C:\> $url.Matches[0].Groups[1].Value
http://MachineName

关于powershell - 如何剥离添加到 “adding trusted sites?”中所需的详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27561277/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com