none
New guy needs help with script RRS feed

  • Question

  • Hi,

    I am trying to do the following:

    using find-AzureRmResources find all VM not located in westeurope. If all my resources are in weseurope then display "There is nothing outside westeurope"

    $getvms=Find-AzureRmResource|where{$_.ResourceType -like"Microsoft.Compute/virtualMachines"-and$_.Location -notlike"Westeurope"}
    
    Foreach ($eachvmin$getvms)
    { 
    If (!$eachvm) {write-host'There is nothing outside westeurope'}
    
    else {Write-Host"You have the following not in westeurope"$eachvm.Name}
    
    }
    

    however even when all my vm's are in westeurope, the script just end and goes back to the cursor without displaying anything.



    • Edited by LeeMoodley Thursday, September 21, 2017 6:53 AM
    • Moved by Bill_Stewart Tuesday, November 7, 2017 9:53 PM This is not "fix/debug/rewrite my script for me" forum
    Wednesday, September 20, 2017 11:52 AM

All replies

  • Please post your code correctly using the code posting tool on the edit bar.  Colorized code is unreadable in most browsers.


    \_(ツ)_/

    Wednesday, September 20, 2017 12:02 PM
  • Using help and learning the basics of PowerShell will help. You code is pretty much impossible.

    This will demonstrate how the properties and commands work.  Use help to learn why.

    $vms = Find-AzureRmResource -ResourceType 'Microsoft.Compute/virtualMachines'
    foreach($vm in $vms){
    	If($vm.Location -eq 'westeurope'){
    		write-host "$($vm.Name) is in WestEurope"
    	} else {
    		Write-Host "$($vm.Name) is in $($vm.location)"
    	}
    }
    


    \_(ツ)_/

    Wednesday, September 20, 2017 12:11 PM