I currently have a bash script that uses dotnet to compile a Function App and the Azure CLI to push deploy a .zip file. The script is essentially:
dotnet clean --configuration Release
dotnet build --configuration Release
cd bin/Release/netstandard2.0
zip -r ${functionappName}.zip *
az functionapp deployment source config-zip -g group -n functionapp --src ${functionappName}.zip
Before this, an az login is done using a Service Principal that has permissions to deploy to the Function App.
I'd like to translate this into PowerShell. I can do the dotnet compilation and the creation of the zip file, but I haven't been able to figure out the deployment yet. I've tried using:
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password )))
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method POST -InFile $filePath -ContentType "multipart/form-data"
...with username and password being the Service Principal ID and secret, but that gives a 401 - Unauthorized: Access is denied due to invalid credentials error.
Is there some way to use PowerShell to zipdeploy to a Function App using a Service Principal?