Get Virtual Machines Across Subscriptions
This Script will search all Virtual Machines across your subscriptions that has the state Enable
.
How to use it:
Command to return a specific Virtual Machine
Get-MyVM -Name <VMName>
Command to return all Virtual Machines
Get-MyVM
function Get-MyVm {
param (
[Parameter(Mandatory = $false, ValueFromPipeline = $true)]
[string]$Name
)
If ($name){
Get-AzSubscription | Where-Object { $_.State -eq 'Enabled' } | ForEach-Object {
Select-AzSubscription $_ | Out-Null;
Get-AzVM -name $Name
} }
else {
Get-AzSubscription | Where-Object { $_.State -eq 'Enabled' } | ForEach-Object {
Select-AzSubscription $_ | Out-Null;
Get-AzVM
}
}
}