# Powershell Regex MDT xml

**URL:** <https://forums.powershell.org/t/powershell-regex-mdt-xml/14514>\
**Category:** PowerShell Help\
**Created:** [June 10, 2020, 8:56am UTC](https://forums.powershell.org/t/powershell-regex-mdt-xml/14514 "2020-06-10T08:56:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [June 10, 2020, 8:56am UTC](https://forums.powershell.org/t/powershell-regex-mdt-xml/14514/1 "2020-06-10T08:56:32Z")

</div>

Hi,

I need to get the “name”, “description” and “disable” from a file by using regex.

file content extract :

\<step type=“BDD\_RunPowerShellAction” name=“1.0 ---------- DEBUG JRAM ----------” description=“” disable=“false” continueOnError=“false” successCodeList=“0 3010”\>

\<step type=“BDD\_Gather” name=“Gather local only” disable=“false” continueOnError=“false” successCodeList=“0 3010” description=“” startIn=“”\>

As you can see the order is different on the two lines (on the first one, there is “step type” then “name” then "description and finally “disable”, this is all I need, and on the second it is “step type” then “name” then “disable” and “description” is at the end).

I have done this but the regex is not good :

if ($\_ -match ““false””) { $StepNum++ $Step = $\_ $Step -match “name=(?.\*) disable=” $Name = $matches[‘content’] Write-Host " Step Name ($StepNum) : $Name" -ForegroundColor Yellow " Step Name ($StepNum) : $Name" | Out-File -FilePath “$FileDot” -Append } }

Thank you very much for your help.

Jo

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [June 10, 2020, 1:53pm UTC](https://forums.powershell.org/t/powershell-regex-mdt-xml/14514/2 "2020-06-10T13:53:12Z")

</div>

Jo, welcome to [Powershell.org](http://Powershell.org). Please take a moment and read the very first post on top of the list of this forum: [Read Me Before Posting! You’ll be Glad You Did!](https://powershell.org/forums/topic/read-me-before-posting-youll-be-glad-you-did).

When you post code, error messages, sample data or console output format it as code, please.  
In the “ **Text** ” view you can use the code tags “ **PRE** ”, in the “ **Visual** ” view you can use the format template “ **Preformatted** ”. You can go back edit your post and fix the formatting - you don’t have to create a new one.  
Thanks in advance.

If your file is a proper XML file you don’t have to use - actually you should not use - regex to get nodes, attributes, names, properties or information in general from an XML file.

Here you can find helpful information about working with XML and Powershell: [Mastering everyday XML tasks in PowerShell](https://www.powershellmagazine.com/2013/08/19/mastering-everyday-xml-tasks-in-powershell/).

If you like to post XML content you should use an external service like [Github Gist](https://gist.github.com) because the forum software here does not handle xml content gracefully.

---

<div class="post-metadata">

**Author:** ![js2010](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@js2010](https://forums.powershell.org/u/js2010)\
**Post date:** [June 10, 2020, 4:09pm UTC](https://forums.powershell.org/t/powershell-regex-mdt-xml/14514/3 "2020-06-10T16:09:25Z")

</div>

Treating it like xml seems easier.

```
[xml]$xml = @'
<top>
  <step type="BDD_RunPowerShellAction" name="1.0 ———- DEBUG JRAM ———-"
    description="" disable="false" continueOnError="false"
    successCodeList="0 3010" />
  <step type="BDD_Gather" name="Gather local only" disable="false"
    continueOnError="false" successCodeList="0 3010"
    description="" startIn="" />
</top>
'@

$xml.top.step | select name,description,disable

name description disable
---- ----------- -------
1.0 ———- DEBUG JRAM ———- false
Gather local only false
```

Nice unicode quotation marks (U+201C, LEFT DOUBLE QUOTATION MARK, and U+201D, RIGHT DOUBLE QUOTATION MARK).

```
'"name"' | format-hex -Encoding BigEndianUnicode

           00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00000000 20 1C 00 6E 00 61 00 6D 00 65 20 1D ..n.a.m.e .
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/powershell-regex-mdt-xml/14514/4 "2024-05-16T20:29:24Z")

</div>

Closed on May 16, 2024, 8:29pm UTC


