Skip to main content

Simple True/False VM search??? RRS feed

  • Question

  • Good morning! I'm very much a newbie here... I am looking for a simple PS snippet to check, from a csv list, if a VM exists in my Azure subscription (I don't care about statuses, storage accounts, etc... simply "does the next VM in my list exists or not - return a true or false" - that's it!)

    I have my csv files and have run many scripts to do things like remove DNS entries and ping/connection tests, remove computer accounts from AD, etc, so I get the gist of pulling data from csv files using ForEach... I just need to add a quick look-up in Azure to also check for the existence of a VM before continuing on with the rest of my script... I will be needing to have any existing VM's removed from the list as well, or export all non-existing, returned "False" computer names to another csv...

    Clear as mud?!?  Thanks for any suggestions!


    Monday, June 3, 2019 3:28 PM

All replies

  • I verified the below cmdlet will return all virtual machines currently in the subscription, which you could then use to verify.

    Get-AzureRmResource -ResourceGroupName <name> -ResourceType Microsoft.Compute/virtualMachines

    Another opition would be the below cmdlet, which only looks for the name given, assuming you know what you're looking for. If it finds the resource, it dumps out details on the resource. If no resource is found, it returns no data.

    Get-AzureRmResource -Name <name>

    You can verify these yourself by quickly starting up a CloudShell PowerShell instance in the Azure Portal.


    Tuesday, June 4, 2019 1:58 AM