I have the following code which correctly fetches the AD Property links from the MSDN documentation:
$uri = 'https://msdn.microsoft.com/en-us/library/ms675090(v=vs.85).aspx' #lists all AD attributes
$results = [xml](Invoke-RestMethod -Method Get -Uri $uri -UseBasicParsing -UseDefaultCredentials)
[System.Xml.XmlNamespaceManager] $nsMgr = New-Object -TypeName System.Xml.XmlNamespaceManager($results.NameTable)
$nsMgr.AddNamespace('ns','http://www.w3.org/1999/xhtml')
$results.SelectNodes("/ns:html/ns:body/ns:div[@id = 'page']/ns:div[@id = 'body']/ns:div[@id = 'content']/ns:div[@class = 'topic']/ns:div[@id = 'mainSection']/ns:dl/ns:dd/ns:a/@href",$nsMgr)
Originally I'd hoped to avoid adding the namespace prefix (ns:), which the documentation implies can be done by adding a namespace with the prefix string.Empty. This seems to work in terms of setting the default namespace; but SelectNodes does not make use of this default.
$uri = 'https://msdn.microsoft.com/en-us/library/ms675090(v=vs.85).aspx' #lists all AD attributes
$results = [xml](Invoke-RestMethod -Method Get -Uri $uri -UseBasicParsing -UseDefaultCredentials)
[System.Xml.XmlNamespaceManager] $nsMgr = New-Object -TypeName System.Xml.XmlNamespaceManager($results.NameTable)
#$nsMgr.AddNamespace('ns','http://www.w3.org/1999/xhtml') #tried with and without this line
$nsMgr.AddNamespace([string]::Empty,'http://www.w3.org/1999/xhtml')
$nsMgr.DefaultNamespace #returns http://www.w3.org/1999/xhtml as hoped
$results.SelectNodes("/html",$nsMgr).Name #should return `html` but doesn't (though works if we register the prefix and use /ns:html)
Question:
Is there any way to have PowerShell use SelectNodes without requiring a namespace prefix / via setting a default namespace?