Skip to content

Instantly share code, notes, and snippets.

@pacodelacruz
Last active January 22, 2019 09:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pacodelacruz/537cca5666f9ebd81ce36d4b7b6264da to your computer and use it in GitHub Desktop.
Save pacodelacruz/537cca5666f9ebd81ce36d4b7b6264da to your computer and use it in GitHub Desktop.
function Upload-FileToWebApp($resourceGroupName, $webAppName, $slotName = "", $localPath, $kuduPath){
$kuduApiAuthorisationToken = Get-KuduApiAuthorisationHeaderValue $resourceGroupName $webAppName $slotName
if ($slotName -eq ""){
$kuduApiUrl = "https://$webAppName.scm.azurewebsites.net/api/vfs/site/wwwroot/$kuduPath"
}
else{
$kuduApiUrl = "https://$webAppName`-$slotName.scm.azurewebsites.net/api/vfs/site/wwwroot/$kuduPath"
}
$virtualPath = $kuduApiUrl.Replace(".scm.azurewebsites.", ".azurewebsites.").Replace("/api/vfs/site/wwwroot", "")
Write-Host " Uploading File to WebApp. Source: '$localPath'. Target: '$virtualPath'..." -ForegroundColor DarkGray
Invoke-RestMethod -Uri $kuduApiUrl `
-Headers @{"Authorization"=$kuduApiAuthorisationToken;"If-Match"="*"} `
-Method PUT `
-InFile $localPath `
-ContentType "multipart/form-data"
}
@redbull05689
Copy link

Hi! I try to use it in my script and I get following errors:
resolves to a directory. Specify a path including a file name, and then retry the command.. The program will terminate in 3 sec.
Add-Content : Cannot bind argument to parameter 'Path' because it is null.
At line:26 char:17

  • Add-content $LogsFullPath -value "[$(Get-Date)]ERROR: $($_.Except ...
    
  •             ~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:) [Add-Content], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddContentCommand

Uploading File to WebApp completed
Add-Content : Cannot bind argument to parameter 'Path' because it is null.
At line:31 char:17

  • Add-content $LogsFullPath -value "[$(Get-Date)]Uploading File to  ...
    
  •             ~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:) [Add-Content], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddContentCommand

PS C:\WebScrape> Get-KuduApiAuthorisationHeaderValue
Get-KuduApiAuthorisationHeaderValue : The term 'Get-KuduApiAuthorisationHeaderValue' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • Get-KuduApiAuthorisationHeaderValue
  •   + CategoryInfo          : ObjectNotFound: (Get-KuduApiAuthorisationHeaderValue:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    
    
    

Could you kindly to give me an advise, please?

@redbull05689
Copy link

resolves to a directory. Specify a path including a file name, and then retry the command.. The program will terminate in 3 sec.
Add-Content : Cannot bind argument to parameter 'Path' because it is null.
At line:26 char:17

  • Add-content $LogsFullPath -value "[$(Get-Date)]ERROR: $($_.Except ...
    
  •             ~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:) [Add-Content], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddContentCommand

Uploading File to WebApp completed
Add-Content : Cannot bind argument to parameter 'Path' because it is null.
At line:31 char:17

  • Add-content $LogsFullPath -value "[$(Get-Date)]Uploading File to  ...
    
  •             ~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:) [Add-Content], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddContentCommand

PS C:\WebScrape> Get-KuduApiAuthorisationHeaderValue
Get-KuduApiAuthorisationHeaderValue : The term 'Get-KuduApiAuthorisationHeaderValue' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • Get-KuduApiAuthorisationHeaderValue
  •   + CategoryInfo          : ObjectNotFound: (Get-KuduApiAuthorisationHeaderValue:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    
    

Could you give an advise. What should I do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment