So I have a Git repo in Azure DevOps, with a URL like
https://[$server]/tfs/[$company]/[$project]/_git/[$repoName]
And I can get to individual files in that repo by appending to that something like this:
?path=/[$folder]/[$fileName]
I am trying to use Powershell to download a specific file from this repo to the corresponding location and filename on my computer, like this:
$sourcePath = "https://[$server]/tfs/[$company]/[$project]/_git/[$repoName]?path=/[$folder]/[$fileName]&download=true"
$filePath = "C:\Documents\[$folder]\[$fileName]"
Invoke-RestMethod -Uri $sourcePath -Method Get -Headers @{Authorization=("Basic {0}" -f [$AuthInfo])} -OutFile $filePath
What this is doing is instead of replacing the local file with the file from the repo, it is replacing the contents of the local file with the contents of the response body. I find it odd that all the googling I've been doing says to do it this way, even though the Microsoft article on Invoke-RestMethod actually explains that this is what -OutFile
does.
Note I've also tried Invoke-WebRequest
....same thing.
So how do I download the actual file from the repo to the local destination I want (or replace the contents of the local destination file with the contents of the repo file)?
In addition, is there a way to specify which branch to get the file from? Maybe I should be using Git powershell commands with this as well somehow? All the other googling I've done about downloading from a git repo comes up with results about GitHub.
Thank you!