Azure VMs provide an administrative tool called Azure VM Extension. It implements some of the important features needed to manage virtual machines, such as resetting passwords, setting RDP parameters, and many other key features, and Azure VMs are adding new extension. By default, the Windows VM that you create installs the following basic VM Extension, including Iaasdiagnostics,vmaccess and BGInfo. Linux VMS, if the diagnostics feature is turned on, the linuxdiagnostic extension is installed by default.
Azure CLI gives you access to extension and related information that Azure provides in a region. You can use the following command:
Azure VM Extension-image List
This article describes the Customerscriptforlinux extension added to Azure Linux VMS through PowerShell commands.
1 Preparing Azure VMS
Azure VMS must be running when they add extension, and their Windows Azure Agent must already be installed. You can see if a waagent program is running with the following command:
[Email protected] waagent]# Ps-ef | grep "Waagent-daemon" | Grep-v grep
Root 935 1 0 08:29? 00:00:01 Python/usr/sbin/waagent-daemon
?
2 Preparing the PowerShell environment
Sign in to Azure China
$mycred = get-credential -username [email protected] -message Hello
Login-azurermaccount -environmentname Azurechinacloud -credential $mycred
?
Define resource Group, VM, and location variables
$RGName = ' Hwiscsi '
$VmName = ' hwiscsi02 '
$Location = ' China East '
?
Define extension related information
$ExtensionName = ' Customscriptforlinux '
$Publisher = ' Microsoft.ostcextensions '
$Version = ' 1.5 '
?
?
$PublicConf = ' {' Fileuris ': ' [] ', ' commandtoexecute ': ' ls '} '
$PrivateConf = ' {
"Storageaccountname": "hwiscsi984",
"Storageaccountkey": "sn4qtyoufybk+skwfplwbj0vpat64nf7wssiqmbo9hpfmtrss5iihsixkjr8s9x5pu1zblwirg3x3h7kbbq+iw=="
}‘
?
To execute the set-azurermvmextension command, install extension:
set-azurermvmextension -resourcegroupname $RGName -vmname $VmName -location $Location '
-name $ExtensionName -publisher $Publisher '
-extensiontype $ExtensionName -typehandlerversion $Version '
-settingstring $PublicConf -protectedsettingstring $PrivateConf
?
After execution, the screen output is as follows:
PS c:\users\hengz> set-azurermvmextension-resourcegroupname $RGName-vmname $VmName-location $Location '
-name $ExtensionName-publisher $Publisher '
-extensiontype $ExtensionName-typehandlerversion $Version '
-settingstring $PublicConf-protectedsettingstring $PrivateConf
?
RequestID Issuccessstatuscode StatusCode Reasonphrase
--------- ------------------- ---------- ------------
True OK okay
Successful execution.
3 Checking the information inside the VM
In the VM, you can view the related logs in/var/log/azure/microsoft.ostcextensions.customscriptforlinux/1.5.2.0.
?
Add customscriptextension to Azure VMs with PowerShell commands