Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When PowerShell 5 Is Obsolete We Can Make Things Better #115

Open
RichieBzzzt opened this issue Apr 15, 2020 · 0 comments
Open

When PowerShell 5 Is Obsolete We Can Make Things Better #115

RichieBzzzt opened this issue Apr 15, 2020 · 0 comments

Comments

@RichieBzzzt
Copy link
Contributor

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

Invoke-RestMethod -Method Get -Uri $uri -Headers $Headers -OutFile $tempLocalExportPath
$Response = Get-Content $tempLocalExportPath -Encoding UTF8
$Response = $response.Replace("# Databricks notebook source", " ")
Remove-Item $tempLocalExportPath
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 | out-null

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant