GItHub has a easy way to get raw contents of a file by clicking on Raw button for any code file in GitHub, where it will redirect to url starting with ‘https://raw.githubusercontent.com/’. For example the PowerShell script here can be viewed as raw content or retrieved programmatically using PowerShell using Invoke-WebRequest with url https://raw.githubusercontent.com/chamindac/VSTS_PS_Utils/master/CreateAzureWebApp/CreateAzureWebApp.ps1. Let’s look at possibility of retrieving raw content of a file in VSTS Git repo via VSTS REST API.
You can use the ‘Git Items Get’ REST API call to retrieve the content of a file with VSTS Git. Let’s try this with an example. Below is a simple PowerShell script that retrieves the content of a given file in VSTS. For the Personal Access Token (PAT) you need code read access scope for this script to work.
The URI parameter includeContent as true is required to enable get the content. If you do not specify the URI parameter $format with value json, you can get file content to $File variable directly in the PowerShell script. In that case you do not need to use $File.content to get the file contents. However, when you specify the $format=json you get file content with additional information such as commitId.
The versionDescriptor.versionType is set to branch and versionDescriptor.version is used to define the branch of the Git repo where the file contains in above script.