【问题标题】:How to find product guid in xml file using select-string?如何使用选择字符串在 xml 文件中查找产品 guid?
【发布时间】:2013-04-02 06:25:33
【问题描述】:

我们有一个 xml 文件,我们在其中存储了产品 guid 的几个属性。

我正在尝试使用 powershell select-string cmdlet 查找 guid,但它没有返回任何值。

GEt-content rules.xml | Select-String "5351BABA-40C2-477B-8111-DA54A48CD8EB"

guid 在文件中,我手动验证。

为什么 select-string 找不到产品 guid?有没有其他方法可以找到它是否可用?

xml 文件中的示例内容

<Component Id="M_PostConfig" Name="Post-Configuration" StsDisplayEntry="Database Server Post-Configuration" StsDisplayText="Please wait while Post-Configuration is installed" UninstallCommand="&quot;%pTxtFoldrSystem32%\msiexec.exe&quot;" Version="2.30.1.3" UninstallParameters="/i {85bb61a2-e0d8-4c3b-83a7-d978dcd4b3d2} REMOVE=DBSERVER /L*V+ &quot;%pFoldrInstallPath%\Foundation\Install\MSI_Uninstall.log&quot; /qn msifeatwise" SupportUninstall="Yes"> </Component>

【问题讨论】:

  • 需要更多信息。我无法重现。 Get-Content .\Desktop\test.xml | Select-String "85bb61a2-e0d8-4c3b-83a7-d978dcd4b3d2" 在包含您提供的示例的 xml 文件中返回应有的行。
  • 我会为输入文件使用完全限定的路径,以确保脚本在您进行手动验证时读取的文件与您相同。

标签: xml powershell powershell-2.0


【解决方案1】:

试试([String](Get-Content rules.xml)) | Select-String "5351BABA-40C2-477B-8111-DA54A48CD8EB"。

【讨论】:

    猜你喜欢
    • 2020-08-06
    • 2011-04-24
    • 1970-01-01
    • 2011-06-26
    • 2018-07-03
    • 1970-01-01
    • 1970-01-01
    • 2013-03-05
    • 1970-01-01
    相关资源
    最近更新 更多