Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Jan 22, 2019

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

This comment has been minimized.

Copy link

commented Jan 22, 2019

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
You can’t perform that action at this time.