Can some kind person check if what follows is my poor coding or a bug, oddity, or whatever.
Code:
$URL = 'https://onegetcdn.azureedge.net/providers/providers.masterList.feed.swidtag'
$Online = Invoke-WebRequest -UseBasicParsing -Uri $URL
That, unless I've missed something, should be an xml document however powershell doesn't seem to treating as such..
Code:
$Online.Content | Get-Member
Doesn't return any objects from the xml document and..
Code:
[xml]$Online.Content
Says it "Cannot convert value "<?xml version="1.0" encoding="utf-8"?>" and "The specified node cannot be inserted as the valid child of this node, because the specified node is the wrong type."
I think it's something to do with either the formatting of the xml document or how Invoke-WebRequest/Invoke-RestMethod are decoding it because if i use "-outfile" and read it back in with "get-content" it works as you'd expect an xml file to work.
I've read some stuff about Invoke-WebRequest/Invoke-RestMethod screwing up BOM but I'm not entirely sure what, or how to spot, a BOM so can't tell if the above xml at the url is the problem or if it's my lack of powershell experience.
If it matters I'm currently parsing the xml document using this and while it works being able to use powershell's built in xml parsing would be a lot cleaner.
Code:
$URL = 'https://onegetcdn.azureedge.net/providers/providers.masterList.feed.swidtag'
$Online = Invoke-WebRequest -UseBasicParsing -Uri $URL
$Local = Get-ChildItem "$PathToScript\Files\Installers\Powershell\nuget" -Recurse -File
$OnlineVersion = $Online.Content | Select-String -Pattern 'https.*swidtag' | ForEach-Object { $_.Matches.Value }
if (($OnlineVersion -replace '\D') -gt ($Local.VersionInfo.FileVersion -replace '\D')) {
$Download = (Invoke-WebRequest -UseBasicParsing -Uri "$OnlineVersion").Content | Select-String -Pattern 'https.*\d.dll' | ForEach-Object { $_.Matches.Value }
$NewVersion = $Download | Select-String -Pattern '\d.+([\d]{1,3})' | ForEach-Object { $_.Matches.Value }
New-Item "$PathToScript\Files\Installers\Powershell\nuget\$NewVersion" -ItemType 'Directory' -Force | Out-Null
Invoke-WebRequest "$Download" -OutFile "$PathToScript\Files\Installers\Powershell\nuget\$NewVersion\Microsoft.PackageManagement.NuGetProvider.dll"
Remove-Item $Local.DirectoryName -Recurse -Force -EA 'SilentlyContinue'
}