aqquire localhost.json from azufunction (powershell commands install failed and I found no az-command for cmd.exe) Any Solutions? - powershell

I installed last year the powershell az core tools with big problems but got it working.
I used this 2 Commands to get the local.settings.json iwth actual values:
Connect-AzAccount -Tenant 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' -SubscriptionId 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
func azure functionapp fetch-app-settings '<function-name>' --output-file local.settings.json
On installing the powershell core tools we spend a few hours and failed , so i tried to find similar command für standard command line (CMD.exe) but I found no similar command that worked so.
I found only this:
az login --tenant "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx"
this sets the correct tenant and this worked.
I found additionally thsis commad to set the subscription but i got no response:
# change the active subscription using the subscription ID
az account set --subscription "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
And I could request the config setting on screen with that command:
az functionapp config appsettings list --name MyFunctionApp --resource-group MyResourceGroup
But i found no way to create with the az command the local.setings.json and the file is in wrong format so piping it in a file will not work too.
[
...
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"slotSetting": false,
"value": "dotnet"
},
...
]
Can anyone help me to get the file local.settings.json with actual config values with the az commands from standard windows shell.

Generally, local.settings.json file is ignored while publishing to Azure Function App as it is specified in the .gitignore file:
While publishing/deploying the function app, make sure to publish with the setting --publish-local-settings -i.
Syntax:
func azure functionapp publish <FunctionAppName> --publish-local-settings -i
Then, all the local.settings.json config values can be published and the values using the PowerShell cmdlet will be displayed:
Get-AzFunctionAppSetting -Name FunctionAppName -ResourceGroupName RGName | ConvertTo-Json | Out-File "local.settings.json"
OR use the same Az cmdlet to get the correct format of config settings defined in local.settings.json that are published to Azure function app.
to get the file local.settings.json with actual config values
Using az command for saving the published local.settings.json config values in a file:
az functionapp config appsettings list --name MyFunctionApp --resource-group MyResourceGroup --output json > local.settings.json

Related

Azure DevOps Pipeline - Create a Synapse managed-private-endpoints to a Azure Storage Account

I am trying to create a 'Synapse Managed private endpoint' to an Azure storage account via a 'Azure cli' task as a step in a pipeline. I want to create the MPE automatically.
The pipeline step calls a power-shell script with parameters. The script is located in source control. Calling the script and passing in parameter values is working fine.
Within the powershell script the following happens...
Get the json template (see below) from source control - this step works.
In the powershell script subsitute the json fields enclosed in <...> with a the parameter values passed in to the power-shell script - this works fine. The converted json is shown in the below screenshot.NB: sensitive values have been readacted here but look correct...
The line in the power-shell that's raising the error is...
az synapse managed-private-endpoints create --workspace-name "$pSynapseWorkspaceName" --pe-name "$pPrivateEndpointName" --file $mpeArmJson --debug --verbose
I think it's to do with the json-string parmater $mpeArmJson and double-quotes - this is what I need help solving ???
The value of $mpeArmJson which the value at this point is (note sensitive values have been readacted here but look correct)...
{
"name": "dds2-datalake-endpoint",
"properties": {
"privateLinkResourceId": "/subscriptions/<redacted subscription id>/resourceGroups/dds2-data-tst-rg/providers/Microsoft.Storage/storageAccounts/dds2datatstdlksa",
"groupId": "dfs",
"fqdns": [
"<redacted-storage-account>.dfs.core.windows.net"
]
}
}
In my Azure devOps pipeline I have created a 'Azure Powershell' task. The task calls a PowerShell script stored in source-control - taking in parameters.
Inside the powershell script I am calling...
New-AzSynapseManagedPrivateEndpoint -WorkspaceName "$pSynapseWorkspaceName" -Name "$pPrivateEndpointName" -DefinitionFile "$tmpDir"
NB: the devOps pipeline runs under a Az 'service principal' which creates the Synapse workspace and in doing so gets the 'owner' and also a 'synapse admin.' permissions automatically set in IAM.
The 'service principal' also needs 'blob storage data contributor' on the main storage account linked to Synapse.

Anyone know how to escape spaces in Azure Cli?

I am running
$nameLine= az boards iteration team list --team "DevOpsTesting Team" --timeframe current --project DevOpsTesting | findstr "name"
$nameOnly = (select-string ":(.*)" -inputobject $name).Matches.Groups[1].Value.Replace(",","")
az boards work-item create --title Test --type Task --project DevOpsTesting --iteration DevOpsTesting\\$nameOnly --assigned-to A.B#gmail.com --fields "Description=PR is open, please test the new exe version and approve Priority=2"
But because the value of nameOnly is "Sprint 7" I am getting an error
az : ERROR: unrecognized arguments: 7
At line:4 char:1
..?
thx.
If spaces are used within a iteration, then enclose in double-quotes, in your case you could add the doule-quotes like:
--iteration "DevOpsTesting\\$nameOnly"

Migrate(copy) ACR with tag using Import-AzContainerRegistry

I am trying to import Azure container registry with tags.
I know the Azure cli command:
az acr import --name $TARGET_REG --source $SOURCE_REG.azurecr.io/$repo":"$tag;
But Azure cli doesn't support in my work station and need to transform it into Power shell something like:
Import-AzContainerRegistryImage -RegistryName $TARGET_REG -ResourceGroupName $RG_NAME -SourceRegistryUri $SOURCE_REG_URI -SourceImage $tag
Any guidance over there?
After couple of trials and errors I am able to transform it with the below line of code that worked for me:
Import-AzContainerRegistryImage -RegistryName $TARGET_REG -ResourceGroupName $TARGET_RG_NAME -SourceRegistryResourceId $SOURCE_REG_RES_ID -SourceImage $repo:$tag

Error building ARM Config during "terraform init" command from azure Azure CLI

I am trying to run "terraform init" command using AZ CLI. Firstly it initialize the backend tfstorage container with tfstate files after that it is raising the error which is mentioned bellow.My az cli version is "2.38.0"
Error: Error building ARM Config: please ensure you have installed Azure CLI version 2.0.79 or newer. Error parsing json result from the Azure CLI: launching Azure CLI: exec: "az": executable file not found in %PATH%.**
Thanks in advance if somebody can rescue me
Navigate to the project directory path using power shell and run the command on the power shell.
C:\Users\abc\IdeaProjects\test_devopspipeline\terraform-manifest>
$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; rm .\AzureCLI.msi
Reference: https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest&tabs=azure-powershell
I was getting this error too, in my case it was a simply that when I ran this
Provider "azurerm" {
subscription_id = "${var.subscription_id}"
tenant_id = "${var.tenant_id}"
client_id = "${var.client_Id}"
client_secret = "${var.client_secret}"
features {}
}
Terraform was not able to capture those values from the .tfvars file, In my particular case, it was a typo on client_Id => (Id) is meant to be id.
If you want to set these variables from outside of the .tf files you can check this link out

Azure Custom Script Extensions with a Windows VM and azure-cli: Publisher is Invalid

I'm trying to provision some VMs on Azure and immediately after customize them with a script. It seems the best way to accomplish this is with Custom Script Extensions.
When I try and execute az extension set on a VM that I have created, it bombs and complains that
The value of parameter publisher is invalid.
This is presumably because I have set myself as the publisher. Instead of Microsoft.OSTCExtensions or some other commonly accepted Extension publisher.
The name Custom Script Extension implies to me that CUSTOM scripts can be chainloaded via this method. Is that not possible without first becoming an extension publisher?
The commands I'm executing:
Set an Extension:
az vm extension set --resource-group dev-eu2 --vm-name dev-eu2-dc --name deploy_ad_to_eu2.ps1 --publisher "zimmertr" --settings /home/tj/git/Dev.Builder/azure-cli/script_extensions/domain_controller/dc_eu2.json --version v0.1
The JSON being called by said extension:
{
"fileUris": ["http://localhost:8000/powershell/domain_controllers/deploy_ad_to_eu2.ps1"],
"commandToExecute": "./deploy_ad_to_eu2.ps1"
}
This JSON then calls deploy_ad_to_eu2.ps1, which is a Powershell script running on a fileserver on my computer. I know this PowerShell script is 100% working because I can copypaste it into a PowerShell prompt without any issues. I'm just tired of RDPing into servers and looking for a little automation.
Am I doing something wrong here?
As Johan said, we should use Microsoft.compute as the publisher and use CustomscriptExtension as the name of the extension.
By the way, we should use --version to 1.9, the json should like this:
{
"fileUris": ["https://jasonvmdiag956.blob.core.windows.net/jasonvmtest/jason.ps1"],
"commandToExecute": "powershell.exe ./jason.ps1"
}
We can run this script in Azure CLI 2.0 like this:
az vm extension set --resource-group jasonvm --vm-name jasonvm --name CustomScriptExtension --publisher Microsoft.Compute --settings D:\cert\qq.json --version 1.9
The output like this:
C:\Users>az vm extension set --resource-group jasonvm --vm-name jasonvm --name CustomScriptExtension --publisher Microsoft.Compute --settings D:\cert\qq.json --version 1.9
{| Finished ..
"autoUpgradeMinorVersion": true,
"forceUpdateTag": null,
"id": "/subscriptions/5384xxxx-xxxx-xxxx-xxxx-xxxxe29axxxx/resourceGroups/jasonvm/providers/Microsoft.Compute/virtualMachines/jasonvm/extensions/CustomScriptExtension",
"instanceView": null,
"location": "eastus",
"name": "CustomScriptExtension",
"protectedSettings": null,
"provisioningState": "Succeeded",
"publisher": "Microsoft.Compute",
"resourceGroup": "jasonvm",
"settings": {
"commandToExecute": "powershell.exe ./jason.ps1",
"fileUris": [
"https://jasonvmdiag956.blob.core.windows.net/jasonvmtest/jason.ps1"
]
},
"tags": null,
"type": "Microsoft.Compute/virtualMachines/extensions",
"typeHandlerVersion": "1.9",
"virtualMachineExtensionType": "CustomScriptExtension"
}
Update:
I had test this PowerShell in my lab, it works fine, here are my steps:
1.upload that powershell script to Azure storage account container(type:container):
2.create json file in your local PC:
{
"fileUris": ["https://jasonvmsdiag665.blob.core.windows.net/ps1/installad.ps1"],
"commandToExecute": "powershell.exe ./installad.ps1"
}
3.run that script in CLI 2.0:
The publisher refers to the publisher of the extension itself, not the publisher of the script to execute. The combination of publisher and name uniquely identifies which extension to apply to the Virtual Machine.
The Microsoft.Compute CustomScriptExtension extension (where Microsoft.Compute is the publisher and CustomScriptExtension is the name of the extension) is general purpose in that the script for the extension to execute is fed through the configuration. Thus there is no need to publish one extension per script.
In other words, you should not specify yourself as the publisher, you should specify the actual publisher of the extension and use the configuration to specify which script(s) you want to execute.