why unix | RBL service | netrs | please | ripcalc | linescroll
hosted services

hosted services

    Here's a snippet for adding custom scripts to an Azure Linux VM. I'm not personally too fond of these extensions as they're limited and can almost randomly repeat. Ensure you remove it using the -uninstall flag once you've got confirmation that the script finished cleanly.

    $module_list = @( "azurerm", "azure" )
    
    foreach( $module in $module_list ) {
        if( !( Get-InstalledModule -name $module ) ) {
            write-host "Installing $module"
            install-module -Name $module -Scope CurrentUser -Force -allowclobber
        }
        Import-Module $module
    }
    
    write-host "Finished module checks"
    
    $subscription = "yoursubscription"
    $machine      = "vmname"
    $servicename  = "vmservice"
    
    $cred = get-credential -username $user
    
    Add-AzureAccount     -Credential $cred | out-null
    Login-AzureRmAccount -credential $cred | out-null
    
    Select-AzureSubscription -subscriptionname   $subscription -current -ErrorAction Stop | out-null
    
    $public_configuration = @'
        {
            "fileUris" : [],
            "commandToExecute": "/sbin/usermod -p 'yourpasswordcrypt' root"
        }
    '@
    
    $vm = get-azurevm -name $machine -ServiceName $servicename
    Set-AzureVMExtension -VM $vm -ExtensionName "CustomScriptForLinux" -Publisher "Microsoft.OSTCExtensions" -Version "1.*"  -PublicConfiguration $public_configuration
    
    # don't forget to add the flag -uninstall once your work is finished as a vm can have
    # only one CustomScriptForLinux extension
    
    $vm | update-azurevm