I want to compare local text file with online file via PowerShell, the content of two files are the same.
I know I have to use Compare-Object
cmdlet to compare two files, and I found I could get the content of online file by Invoke-WebRequest
cmdlet (https://www.quora.com/How-do-I-download-URL-content-using-Get-Content-in-PowerShell-Script). But it's not working as expected. It just output the file content of the online version.
$item1 = cat $path
$item2 = Invoke-WebRequest -Uri $URL | select -ExpandProperty Content
# No working as expected
Compare-Object -ReferenceObject $item1 -DifferenceObject $item2
Updates
After debugging, I found out that the type of return value is System.Array
when using Get-Content
(cat
), but when using Invoke-WebRequest
it's String
.
PS C:\> $item1.GetType() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Object[] System.Array PS C:\> $item2.GetType() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True String System.Object