Powershell XPATH seems to be not working

I am using Wifi profile xml files as an example.

In the below code if i use xpath as $XPath = "//*" I get the list of all nodes in the xml.

But if I specify specific node and all nodes under it with $XPath = "//WLANProfile//*", I get nothing.

Is there something wrong I am doing or does Powershell xpath work differently.

$path = "c:\something\wifi.xml"

$XPath = "//WLANProfile//*"

$xmlContent = [xml](Get-Content $path)

#This does not work unless $XPath is changed to "//*"
Select-Xml -Xml $xmlContent -XPath $XPath | Select-Object -ExpandProperty Node

#Just testing another way and same here only works when $XPath is equal to "//*"


<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
	<MacRandomization xmlns="http://www.microsoft.com/networking/WLAN/profile/v3">

Never really used xPath in the many times I’ve done XML parsing, I’ve always used dot notation:

[xml]$xml = Get-Content -Path C:\Scripts\wifi.xml

This XML looks straight forward, so is there a reason that you are attempting to leverage XPath?

@rob-simmers no special reason. I don’t work a lot with xml files and google pointed me to xpath. I was thinking this will result in spiting out all the nodes in xml and can be a template for any other similar xml file.

I have come this close

This seems to be caused by namespace as removing the line ‘xmlns=“http://www.microsoft.com/networking/WLAN/profile/v1”’ does make it work.

And I tried using the -Namespace as below and it doesn’t work

Select-Xml '//WLANProfile//*' -Namespace @{'xml'='http://www.microsoft.com/networking/WLAN/profile/v1'} -xml $xmlContent

when namespace is manually removed from file
Node Path Pattern
---- ---- -------
name InputStream //WLANProfile//*
SSIDConfig InputStream //WLANProfile//*
SSID InputStream //WLANProfile//*
hex InputStream //WLANProfile//*
name InputStream //WLANProfile//*
connectionType InputStream //WLANProfile//*
connectionMode InputStream //WLANProfile//*
MSM InputStream //WLANProfile//*
security InputStream //WLANProfile//*
authEncryption InputStream //WLANProfile//*
authentication InputStream //WLANProfile//*
encryption InputStream //WLANProfile//*
useOneX InputStream //WLANProfile//*
sharedKey InputStream //WLANProfile//*
keyType InputStream //WLANProfile//*
protected InputStream //WLANProfile//*
keyMaterial InputStream //WLANProfile//*
MacRandomization InputStream //WLANProfile//*
enableRandomization InputStream //WLANProfile//*