Avatar of Kelly Garcia
Kelly GarciaFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

powershell script doesnt work in Azure

Hi All,

The powershell script below doesn't work in Microsoft Azure - The VM's do not start:

$jobs = @()
Foreach ( $VM in Get-AzureRmVM )
{
  if ( $_.Tags.Values -and $_.Tags.Keys -eq 'Start VM' )
  {
    $ResourceGroupName = $vm | select -expandproperty resourcegroupname
    Write-Output "$($VM.Name) is starting"
    $jobs += Start-Job -ScriptBlock { param($VMName, $RscGrp) Start-Azurermvm -Name $VMName -ResourceGroupName $RscGrp -ErrorAction Continue } -ArgumentList $VM.Name, $ResourceGroupName
  }
  Else
  {
    Write-output "Not starting the VM $VM.Name"
  }
} 
$jobs | Wait-Job | Remove-Job -Force

Open in new window


Please help!
PowershellAzure

Avatar of undefined
Last Comment
Jose Gabriel Ortega Castro
ASKER CERTIFIED SOLUTION
Avatar of Jose Gabriel Ortega Castro
Jose Gabriel Ortega Castro
Flag of Venezuela, Bolivarian Republic of image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Answered
Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo