Script Repository


Start Azure virtual machine

February 24, 2021
1041

The script starts an Azure virtual machine.

Note: The script uses the $Context variable available on the server side only. This means that the script can be executed only by business rules, custom commands, and scheduled tasks. To add the script, use the Run a program or PowerShell script action.

Parameters:

  • $vmName - Specifies the virtual machine name.
  • $serviceName - Specifies the name of the Azure service that contains the virtual machine.
  • $publishSettingsFile - Specifies the full path to a *.publishsettings file with a certificate to connect to your Windows Azure account. You can obtain one using the Get-AzurePublishSettingsFile cmdlet.
Edit Remove
PowerShell
$scriptBlock = {
   Import-Module Azure

    $vmName = 'MYSERVER' # TODO: modify me
    $serviceName = 'MyService' # TODO: modify me
    $publishSettingsFile = 'C:\Azure\MyAzureSettings.publishsettings' # TODO: modify me

    Import-AzurePublishSettingsFile -PublishSettingsFile $publishSettingsFile
    Start-AzureVM -ServiceName $serviceName -Name $vmName
}

# Start Windows PowerShell as a separate process and run the script block
$waitTimeSeconds = 8 * 60 * 1000
$powershellPath = “C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe”
$process = Start-Process $powershellPath -NoNewWindow -ArgumentList ("-ExecutionPolicy Bypass -noninteractive -noprofile " + $scriptBlock) -PassThru
$process.WaitForExit($waitTimeMilliseconds)
See Also:

Comments ( 0 )
No results found.
Leave a comment