azure.databricks.cicd.tools icon indicating copy to clipboard operation
azure.databricks.cicd.tools copied to clipboard

When PowerShell 5 Is Obsolete We Can Make Things Better

Open RichieBzzzt opened this issue 4 years ago • 0 comments

We can combine -SkipHeaderValidation -ContentType "charset=utf-8" to avoid having to use a temp file to save a file. So all this

https://github.com/DataThirstLtd/azure.databricks.cicd.tools/blob/7869448c81081c07cc39dd366889cc403059ac8f/Private/Set-LocalNotebook.ps1#L31-L40

can be condensed into

 $Response = (Invoke-RestMethod -Method Get -Uri $uri -Headers $Headers -SkipHeaderValidation -ContentType "charset=utf-8") -split '\n' | Select-Object -Skip 1
            if ($Format -eq "SOURCE") {
                $Response = ($Response.replace("[^`r]`n", "`r`n") -Join "`r`n")
            }

            Write-Verbose "Creating file $LocalExportPath"
            New-Item -force -path $LocalExportPath -value $Response -type file

Which is what it used to look like.

Sadly SkipHeaderValidation is not availablein PowerShell 5. Ho hum.

RichieBzzzt avatar Apr 15 '20 11:04 RichieBzzzt