Skip to content

Instantly share code, notes, and snippets.

@tiny-dancer
Last active October 18, 2019 18:38
Show Gist options
  • Select an option

  • Save tiny-dancer/2d2bcbd103220dee2a09c0d213195682 to your computer and use it in GitHub Desktop.

Select an option

Save tiny-dancer/2d2bcbd103220dee2a09c0d213195682 to your computer and use it in GitHub Desktop.

Revisions

  1. tiny-dancer revised this gist Oct 18, 2019. 1 changed file with 1 addition and 33 deletions.
    34 changes: 1 addition & 33 deletions lp-cl.ps1
    Original file line number Diff line number Diff line change
    @@ -1,39 +1,7 @@
    <#
    .DESCRIPTION
    An example runbook which prints out the first 10 Azure VMs in your subscription (ordered alphabetically).
    For more information about how this runbook authenticates to your Azure subscription, see our documentation here: http://aka.ms/fxu3mn
    .NOTES
    AUTHOR: Azure Automation Team
    LASTEDIT: Mar 27, 2015
    #>
    workflow Get-AzureVMTutorial
    workflow lp-cl
    {
    #The name of the Automation Credential Asset this runbook will use to authenticate to Azure.
    $CredentialAssetName = 'DefaultAzureCredential'

    #Get the credential with the above name from the Automation Asset store
    $Cred = Get-AutomationPSCredential -Name $CredentialAssetName
    if(!$Cred) {
    Throw "Could not find an Automation Credential Asset named '${CredentialAssetName}'. Make sure you have created one in this Automation Account."
    }

    #Connect to your Azure Account
    $Account = Add-AzureAccount -Credential $Cred
    if(!$Account) {
    Throw "Could not authenticate to Azure using the credential asset '${CredentialAssetName}'. Make sure the user name and password are correct."
    }

    #TODO (optional): pick the right subscription to use. Without this line, the default subscription for your Azure Account will be used.
    #Select-AzureSubscription -SubscriptionName "TODO: your Azure subscription name here"

    #Get all the VMs you have in your Azure subscription
    $VMs = Get-AzureVM

    #Print out up to 10 of those VMs
    if(!$VMs) {
    Write-Output "No VMs were found in your subscription."
    } else {
    Write-Output $VMs[0..9]
    }
    }
  2. tiny-dancer created this gist Oct 18, 2019.
    39 changes: 39 additions & 0 deletions lp-cl.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    <#
    .DESCRIPTION
    An example runbook which prints out the first 10 Azure VMs in your subscription (ordered alphabetically).
    For more information about how this runbook authenticates to your Azure subscription, see our documentation here: http://aka.ms/fxu3mn
    .NOTES
    AUTHOR: Azure Automation Team
    LASTEDIT: Mar 27, 2015
    #>
    workflow Get-AzureVMTutorial
    {
    #The name of the Automation Credential Asset this runbook will use to authenticate to Azure.
    $CredentialAssetName = 'DefaultAzureCredential'

    #Get the credential with the above name from the Automation Asset store
    $Cred = Get-AutomationPSCredential -Name $CredentialAssetName
    if(!$Cred) {
    Throw "Could not find an Automation Credential Asset named '${CredentialAssetName}'. Make sure you have created one in this Automation Account."
    }

    #Connect to your Azure Account
    $Account = Add-AzureAccount -Credential $Cred
    if(!$Account) {
    Throw "Could not authenticate to Azure using the credential asset '${CredentialAssetName}'. Make sure the user name and password are correct."
    }

    #TODO (optional): pick the right subscription to use. Without this line, the default subscription for your Azure Account will be used.
    #Select-AzureSubscription -SubscriptionName "TODO: your Azure subscription name here"

    #Get all the VMs you have in your Azure subscription
    $VMs = Get-AzureVM

    #Print out up to 10 of those VMs
    if(!$VMs) {
    Write-Output "No VMs were found in your subscription."
    } else {
    Write-Output $VMs[0..9]
    }
    }