locked
Powershell xml script to extract value from <Property name=“xx” value=“yy”/> RRS feed

  • Question

  • Hello PowerShell Experts,

    Can y'all assist me looking through this to what I did wrong? I just need the result to show the Property Name and the Value - <Property Name="SharedComputerLicensing" Value="0" /> from my XML file.

    What I have done...

    Get-ChildItem C:\esd\dist\OFFICE_FRSTDEFERRED_WIN\V16.0.4.3\Install\*.xml | foreach {
        echo $_.FullName

        [xml]$doc = Get-Content $_
        $SharedComputerLicensing = $doc.SelectSingleNode("//Property[@name = 'SharedComputerLicensing']")

        # never forget to check if there even is a match
        if ($SharedComputerLicensing) {
            echo "SharedComputerLicensing: $($SharedComputerLicensing.value)"

            if ($SharedComputerLicensing.value -eq "1") {
                $_.Directory | Move-Item -Destination C:\LocalFiles\OPP\RES\VerifySharedComputerLicensing
            }
        } else {
            echo "SharedComputerLicensingID not found"
        }
    }


    TX


    • Edited by GenXit Tuesday, November 5, 2019 12:45 PM changing name
    Tuesday, November 5, 2019 12:45 PM

Answers

  • I answered your question before. You deleted the post and ignor4ed the answer.

    I also posted a requirement for posting in technical forums. Please read the following and fix your original post;.

    [xml]$xml = @'
    <Configuration>
          <Add SourcePath="http://MO3CDN-Prod.delta.rl.delta.com:3650/pr/b8f9b850-328d-4355-9145-c59439a0c4cf" OfficeClientEdition="32" Channel="Targeted">
             <Product ID="O365ProPlusRetail">
                 <Language ID="en-us" />
                 <ExcludeApp ID="OneDrive" />
                 <ExcludeApp ID="Groove" />
                 <ExcludeApp ID="Teams" />
             </Product>
          </Add>
          <Updates UpdatePath="http://MO3CDN-Prod.delta.rl.delta.com:3650/pr/b8f9b850-328d-4355-9145-c59439a0c4cf" Channel="Targeted" Enabled="TRUE" />
          <Display Level="None" AcceptEULA="TRUE" />
          <Logging Level="Standard" Path="C:\esd\logs" />
          <Property Name="FORCEAPPSHUTDOWN" Value="TRUE" />
          <Property Name="SharedComputerLicensing" Value="0" />
          <Property Name="PinIconsToTaskbar" Value="TRUE" />
     </Configuration>
    '@
    $xml.Configuration.Property[1].Value
    $xml.SelectSingleNode('//Property[@Name="SharedComputerLicensing"]').Value


    \_(ツ)_/


    • Edited by jrv Tuesday, November 5, 2019 1:32 PM
    • Marked as answer by GenXit Tuesday, November 5, 2019 1:39 PM
    Tuesday, November 5, 2019 1:32 PM

All replies

  • I answered your question before. You deleted the post and ignor4ed the answer.

    I also posted a requirement for posting in technical forums. Please read the following and fix your original post;.

    [xml]$xml = @'
    <Configuration>
          <Add SourcePath="http://MO3CDN-Prod.delta.rl.delta.com:3650/pr/b8f9b850-328d-4355-9145-c59439a0c4cf" OfficeClientEdition="32" Channel="Targeted">
             <Product ID="O365ProPlusRetail">
                 <Language ID="en-us" />
                 <ExcludeApp ID="OneDrive" />
                 <ExcludeApp ID="Groove" />
                 <ExcludeApp ID="Teams" />
             </Product>
          </Add>
          <Updates UpdatePath="http://MO3CDN-Prod.delta.rl.delta.com:3650/pr/b8f9b850-328d-4355-9145-c59439a0c4cf" Channel="Targeted" Enabled="TRUE" />
          <Display Level="None" AcceptEULA="TRUE" />
          <Logging Level="Standard" Path="C:\esd\logs" />
          <Property Name="FORCEAPPSHUTDOWN" Value="TRUE" />
          <Property Name="SharedComputerLicensing" Value="0" />
          <Property Name="PinIconsToTaskbar" Value="TRUE" />
     </Configuration>
    '@
    $xml.Configuration.Property[1].Value
    $xml.SelectSingleNode('//Property[@Name="SharedComputerLicensing"]').Value


    \_(ツ)_/


    • Edited by jrv Tuesday, November 5, 2019 1:32 PM
    • Marked as answer by GenXit Tuesday, November 5, 2019 1:39 PM
    Tuesday, November 5, 2019 1:32 PM
  • I answered your question before. You deleted the post and ignor4ed the answer.

    I also posted a requirement for posting in technical forums. Please read the following and fix your original post;.

    [xml]$xml = @'
    <Configuration>
          <Add SourcePath="http://MO3CDN-Prod.delta.rl.delta.com:3650/pr/b8f9b850-328d-4355-9145-c59439a0c4cf" OfficeClientEdition="32" Channel="Targeted">
             <Product ID="O365ProPlusRetail">
                 <Language ID="en-us" />
                 <ExcludeApp ID="OneDrive" />
                 <ExcludeApp ID="Groove" />
                 <ExcludeApp ID="Teams" />
             </Product>
          </Add>
          <Updates UpdatePath="http://MO3CDN-Prod.delta.rl.delta.com:3650/pr/b8f9b850-328d-4355-9145-c59439a0c4cf" Channel="Targeted" Enabled="TRUE" />
          <Display Level="None" AcceptEULA="TRUE" />
          <Logging Level="Standard" Path="C:\esd\logs" />
          <Property Name="FORCEAPPSHUTDOWN" Value="TRUE" />
          <Property Name="SharedComputerLicensing" Value="0" />
          <Property Name="PinIconsToTaskbar" Value="TRUE" />
     </Configuration>
    '@
    $xml.Configuration.Property[1].Value
    $xml.SelectSingleNode('//Property[@Name="SharedComputerLicensing"]').Value


    \_(ツ)_/


    Thanks for the help. Appreciate you! yes, I was too exhausted working over 48 hours straight. I deleted it without even glancing at it. Thank you.

    Toly Xiong

    Tuesday, November 5, 2019 1:39 PM
  • Also r4emember that XML is always case sensitive and matches must be exact.

    \_(ツ)_/

    Tuesday, November 5, 2019 1:39 PM