I tried to create 2 virtual machines with the same parameters but with 2 different ways:
The Powershell cmdlet:
New-AzVm -ResourceGroupName $rg -Name "Testing1img" -Credential $credential -Image UbuntuLTS
Azure CLI from Powershell:
az vm create `
--name "Testing2img" `
--resource-group $rg `
--admin-username $credential.UserName `
--admin-password $credential.Password `
--image "UbuntuLTS"
Both create an Ubuntu LTS VM on the same resource group (different name). The problem I have is that they create VMs with slightly different settings.
In the first case it creates:
an Ubuntu 16.04 Linux
DNS name is being assigned
In the second case we have:
an Ubuntu 18.04 Linux
No Dns name is being configured
Why these (even small) differences? Shouldn't they both create the same exact VMs? Someone asking for an UbuntuLTS would expect the latest available image and not 16.04.
For New-AzVM you can specify the Ubuntu version with...
-Image Canonical:UbuntuServer:18.04-LTS:latest
My experience shows that functionalities are often delivered in different time frames for individual tools. I often came across commands that used methods other than those recommended in the documentation.
I'm not sure how this looks like for the PowerShell module but the azure CLI code is available on GitHub. So it's possible to verify which endpoints are used and i think the same is possible for debug mode in PowerShell.
https://github.com/Azure/azure-cli/blob/e4a2e19855b2ff0964d084239de9f3f230e67be4/src/azure-cli/azure/cli/command_modules/vm/custom.py#L682
Related
I am newbie with microsoft azure and trying to study and follow the tutorial.
But my problem is, here is my tutorial :
# generate a unique name and store as a shell variable
webappname=mywebapp$RANDOM
# create a resource group
az group create --location westeurope --name myResourceGroup
# create an App Service plan
az appservice plan create --name $webappname --resource-group myResourceGroup --sku FREE
# create a Web App
az webapp create --name $webappname `
--resource-group myResourceGroup `
--plan $webappname
And my problem is, when I coded the code az group create --location westeurope --name myResourceGroup, it always said to me that I must login to azure but I login to azure before that.
And when I searched how to create a web app with azure CLI online, it show me a very different version command like this
https://www.youtube.com/watch?v=qILUM6DyruM
Could you please give me some advise for this problem ? Thank you in advance.
I'm looking for powershell command to get an Azure Windows VM plan info. I looked up Get-AzVM, but unable to find the required info.
Here's the property on azure portal, that I'm looking for
Please find the below screenshot to get the vm plan information
CLI
az vm show --name myvm --resource-group test --query storageProfile.imageReference.sku
Powershell
Get-AzVM -ResourceGroupName test -Name myvm -Status | select OsName
To get the status of all vms in the resource group :
Get-AzVM -ResourceGroupName test -Status
If this solve your problem then mark this your answer 👍
Use the below query:
az vm show --name myvm --resource-group test --query storageProfile.imageReference.sku
I am trying to setup Azure VM's using Powershell but i wish to do it all remotely with no logging into the machine. I have been able to spin up the VM using commands like New-AzVM but now i need to run specific powershell commands e.g. Enable-WindowsOptionalFeature -Online -FeatureName IIS-ManagementConsole
I can see you can run remote scripts using the following but as this is a brand new server there are no scripts on that box to execute.
Invoke-AzVMRunCommand -ResourceGroupName $ResourceGroupName -Name $VmName -CommandId 'RunPowerShellScript' -ScriptPath '<pathToScript>' -Parameter #{"arg1" = "var1";"arg2" = "var2"}
How can i copy scripts to the server remotely so i can use the above command, or run commands without the need for a script file.
You don't need to copy the scripts remotely to the Azure VM. You can run it locally.
Save the PowerShell scripts to a format .ps1 file, then run it on local PowerShell with referencing the path of the script via parameter -ScriptPath.
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ManagementConsole
You also could copy that scripts on the Virtual machine---Run command---RunPowerShellScript on the Azure portal, refer to this.
What you need is to look into the direction of PowerShell Desired State Configuration (DSC)
Here you can find general explanation for this technology
Get started manual for DSC
I am trying to download and install an exe during the provisioning of a Windows VM in Azure cloud. I do not want to use Custom Script Extension but instead I want to use "Custom Data". I cannot find any solid examples on Azure documentation.
In AWS, I found enough resources and I could develop the below PowerShell script and add it to the User Data but that doesn't work on Azure, I tried different variations but with no luck. Has anyone done that before? Is there any clear documentation on that? I read Azure uses Cloud-init but again, no clear examples on how to do that with Cloud-init for a Windows machine, all examples are for Linux.
<powershell>
start-transcript
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest 'https://www.domain-name.com/filename.exe' -OutFile C:\filename.exe
C:\filename.exe --quiet
</powershell>
Any help would be appreciated.
You can inject data into a Windows virtual machine on Azure, but you can't execute it using custom data or cloud init unfrotunately. Execution of the custom data using cloud init is only supported in Ubuntu images.
Source: https://azure.microsoft.com/es-es/blog/custom-data-and-cloud-init-on-windows-azure/
To achieve an execution of a script post provisioning, it depends on how you're provisioning the VM.
In ARM templates you can use custom script extensions: https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-windows
Using Azure CLI you can execute a script using az vm run-command like this:
az vm run-command invoke --command-id RunPowerShellScript --name win-vm -g my-resource-group \
--scripts 'param([string]$arg1)' \
'Write-Host Hello' \
--parameters 'arg1=kemety'
Sourced from here: https://learn.microsoft.com/en-us/cli/azure/vm/run-command?view=azure-cli-latest
I have a few Windows Server 2019 Core VMs in Azure all running the same windows service.
I would like to run a powershell script from my computer that loops through all the VMs and restarts the service on each.
I have a PS script on each VM which does this so how do I invoke them remotely? Is this possible without using Cloud Shell or Automation, with just a few lines of code? I have Azure powershell tools installed on my computer too.
Please provide answers with a working example.
Thank you
For your requirement, I think the simplest way is to use the Azure PowerShell command to execute the PowerShell script inside the VM, the example command here:
Invoke-AzVMRunCommand -ResourceGroupName 'rgname' -VMName 'vmname' -CommandId 'RunPowerShellScript' -ScriptPath 'sample.ps1' -Parameter #{param1 = "var1"; param2 = "var2"}
To execute the script in each VM, you need to make a loop with PowerShell yourself. By the way, you can also use the Custom Extension for Windows.