Taking configuration backups from Azure webapp wwwroot folder - azure

I'm trying to take specific configuration backup in Azure webapp wwwroot folder with below powershell script which was working fine in public App service plan(Standard and Premium) but the same powershell script is not working fine in Private App service plan(Isolated(App service Environment) - I1,I2,I3). Please find the code below.
Code:
Import-Module Kudu-api
$userNm="`$Testapp"
$password="*******"
$token = New-KuduAuthorizationToken $userNm $password
$sitename="Testapp"
Set-Location "C:\Users\admin\Desktop\Backups"
sleep -Seconds 2
Receive-KuduFile $sitename $token '/site/wwwroot/appsettings.json' ./appsettings.json`
Getting the below error when trying the above script in Isolated(I1) appservice plan:
Error : Invoke-RestMethod : The remote name could not be resolved: 'Testapp.scm.azurewebsites.net'
Please suggest how we can resolve this.

Related

Azure DevOps - Set-Azcontext - The term 'Set-Azcontext' is not recognized

I have created one Azure DevOps pipeline.
99% of this pipeline calls PowerShell scripts (PowerShell Core script type).
Within the Power Shell scripts are calls to the AZ module - this all works fine.
I now have to add a new step within the DevOps pipeline to set the 'VulnerabilityAssessment' on an SQL server - however this time I need to call module 'Set-Azcontext' as part of the PowerShell script which is shown below...
[CmdletBinding()]
param(
$prgname,
$psqlservername,
$psaname,
$pnotificationmmail = 'john.doe#hotmail.com',
$psubscriptionname = 'ABC'
)
#debug
#Get-Module -Name AZ -ListAvailable
# working in powershell and need to set the correct subscription in powershell (ABC)
Set-Azcontext -Subscription "ABC"
#Enable-AzSqlServerAdvancedDataSecurity -ResourceGroupName $prgname -ServerName $pservername -DoNotConfigureVulnerabilityAssessment
# https://learn.microsoft.com/en-us/powershell/module/az.sql/update-
azsqlservervulnerabilityassessmentsetting?view=azps-7.5.0
#Update-AzSqlServerVulnerabilityAssessmentSetting -ResourceGroupName $prgname -ServerName $pservername -StorageAccountName $psaname -ScanResultsContainerName "vulnerability-assessment" -RecurringScansInterval Weekly -EmailAdmins $true -NotificationEmail #pnotificationmmail
When the Azure devOps pipeline runs it fails on step...Set-Azcontext -Subscription "ABC"
update-vulnerability-assessment.ps1 : The term 'Set-Azcontext' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
The devOps process is running on a Azure agent. It looks like a module is not available or loaded.
Maybe I need to install/load the module containing 'Set-Azcontext' as part of the powershell script ? (if so how do I do this)
OR
Install a new capibility of the agent to have the module containing 'Set-Azcontext' installed?(if so how do I do this)
Going to instead via an ARM template in the Azure pipeline for setting the vulneratibilty of Azure SQL server

How to deploy Logic App from Visual Studio Community using powershell command?

I tried different ways to deploy my local logic app from VS Community using powershell but none of them are working.
Any solutions for this?
Logic App deployment successful from Visual Studio (local) through PowerShell Command
The following command worked for me
New-AzResourceGroupDeployment -ResourceGroupName <Azure-resource-group-name> -TemplateUri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.logic/logic-app-create/azuredeploy.json
and here is the output:
Here is the process that I followed before running the above command.
Process Flow:
I have found that there are 2 ways of deploying logic app through PowerShell i.e., Azure RM Template Commands and AZ Modules Commands
To work with any of the following commands, we are required to install related package files:
To deploy using Azure RM Template Commands - Run this code on PowerShell:
Install-Module -Name AzureRM -AllowClobber
To deploy using AZ module commands - Run this code on PowerShell:
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
Checkout the following links to play with versions (uninstalling old and installing new), setting up the policies, connecting of Azure Accounts, etc in these:
Azure RM PowerShell Commands and Azure Az Module PowerShell Commands
Following is the process of which I have tried deploying the Local Visual Studio Logic App to Azure in PowerShell using Azure RM PowerShell Script commands:
Before deploying:
Create a Logic App in Visual Studio (File > New Project > Select 'Azure Resource Group' > Logic App)
Your solution will be ready in a few seconds, you will be able to see two json files. As you select prameters.json file you will be able to see json schema for logic app deployment.
To Connect your logic with your Azure Account, right click on LogicApp.json and select 'Open with logic app designer'. If you don't find this option, then install this extension in your project:
Right click on project and click on validate
Select your resource group, subscription and click on edit parameters - give custom name to your logic app. Otherwise, it will throw you error of null in logicAppName and shows template is invalid.
After validation, it shows the template is valid. It can be automatically validate during deployment process also, but it's good way to validate to get rid out of errors.
PowerShell Commands to deploy your logic App from visual studio (local):
Install this Power Shell provided by Microsoft Cloud.
Run in Administrator Mode > Login with Connect-AzureRmAccount command (it takes you to browser and connect with Azure account) > after that it imports your subscription and resource group details in the shell like below:
Use the following command to deploy your logic app
New-AzResourceGroupDeployment -ResourceGroupName "AzureAccountMail" -Templatefile "C:\LogicAppTemplats\template.json" -TemplateParameterFile "C:\LogicAppTemplats\parameters.json"
Check this following documentation for this command overview.
Done! Deployment Succeeded.
Now Check out in the azure portal:
Note:
Here you can find the template file and parameters.json file under your project:
Make Sure you given your logic app name value here in the parameters.json file:
And Provide the logic app name, deployment location values in the template.json file (LogicApp.json)

azure active directory login failed while deploying blockchain workbench

Some one please help after opening the url of app services i am adding my institutional AD tenant to cloud shell for authentication but it gives error of login failed.orkbench
There were some recent changes to Azure Cloud Shell. While we are working on a solution, here is some workaround:
Before running cd; Invoke-WebRequest -Uri https://aka.ms/workbenchAADSetupScript -OutFile workbenchAADSetupScript.ps1; ./workbenchAADSetupScript.ps1 -SubscriptionID * -ResourceGroupName * -DeploymentId ***
Run Remove-Item -Path Function:\Connect-AzureAD in your Azure Cloud Shell session
Reference: https://social.msdn.microsoft.com/Forums/en-US/a6101462-ccc1-4922-a5ea-2d28890cb9a4/azure-blockchain-workbench-cloud-shell-active-directory-tenant-login-failed-error?forum=azureblockchain

Error while applying configuration using PowerShell DSC VM extension : "Compilation errors occurred while processing configuration"

I have a simple configuration that I am trying to apply to an Azure VM using PowerShell DSC extension
Configuration DSCTest
{
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Import-DscResource -ModuleName xPSDesiredStateConfiguration
Node "localhost"
{
File ESETInstaller
{
Type = 'Directory'
DestinationPath = 'C:\ESETInstaller'
Ensure = "Present"
}
}
}
DSCTest
I've published this using
Publish-AzVMDscConfiguration "D:\Test\DSCTest.ps1" -OutputArchivePath "D:\Test\DSCTest.ps1.zip"
and then I uploaded this zip file in Azure BLOB storage.
After that, I tried to apply this configuration to a VM using the following command:
Set-AzVMDscExtension -ResourceGroupName 'TestDSC' -VMName 'TestDSCVM' -ArchiveStorageAccountName 'test***********' -ArchiveResourceGroupName '******' -ConfigurationName $configurationName -ArchiveBlobName "DSCTest.ps1.zip" -ArchiveContainerName 'dsc' -Name "DSCTest" -Version 2.76
In the target machine, I can see that the DSC folder appears
But on the console I get the error:
Although, I am able to successfully apply the configuration in the target machine by manually executing the command from inside that VM.
Please let me know if anyone has ever faced this issue before. Thanks.
The logs inside the target machine showed that the issue is with the execution policy.
In my script I changed "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned" to "Set-ExecutionPolicy -ExecutionPolicy ByPass -Scope CurrentUser -Force" and it worked fine.

VSO/VSTS: Azure Powershell - The specified credentials cannot be used with the authentication scheme 'Basic'

I have the following build step which runs a script in Azure Powershell. The script basically publishes files to the web app (see further down for details).
This works just fine with all of my web apps EXCEPT FOR ONE. I get the following error:
scriptCommand= & "C:\a\8b0700333\MyProj\Scripts\Publish.ps1"
-websiteName mywebapp -packOutput "C:\a\8b0700333\MyProj\Api"
Stopping web app...
Publishing web app...
Publishing with publish method [MSDeploy]
[error]Error: The specified credentials cannot be used with the
authentication scheme 'Basic'.
[error]Error: Default credentials
cannot be supplied for the Basic authentication scheme.
[error]Parameter name: authType
[error]Error count: 1.
The Publish.ps1 script:
param($websiteName, $packOutput)
$website = Get-AzureWebsite -Name $websiteName
# get the scm url to use with MSDeploy. By default this will be the second in the array
$msdeployurl = $website.EnabledHostNames[1]
$publishProperties = #{'WebPublishMethod'='MSDeploy';
'MSDeployServiceUrl'=$msdeployurl;
'DeployIisAppPath'=$website.Name;
'Username'=$website.PublishingUsername;
'Password'=$website.PublishingPassword
'SkipExtraFilesOnServer'='False'}
Write-Output "Stopping web app..."
Stop-AzureWebsite -Name $websiteName
Write-Output "Publishing web app..."
$publishScript = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\default-publish.ps1"
. $publishScript -publishProperties $publishProperties -packOutput $packOutput
Write-Output "Starting web app..."
Start-AzureWebsite -Name $websiteName
Had the same issue, the problem was coming from the fact that apparently the script Microsoft provides doesn't support slots.
Made a fixed version here https://gist.github.com/baywet/f7ed425c48ccde4399c7
Helping myself from this post How can I get the PublishUrl via Azure PowerShell?
This error usually occurs when using MS deploy HTTP Basic Authentication without any credentials specified. So you can add following code in the PowerShell script to check if the publish username and password for the web app is get correctly.
Write-Output $website.PublishingUsername
Write-Output $website.PublishingPassword
And also, check the value of msdeployurl to see if it is the correct URL (Usually like: youwebappname.scm.azurewebsites.net) for deployment.
Write-Output $msdeployurl

Resources