title: How to enable / disable function apps in a resource group in azure
body: <p>I an writing a <strong>powershell</strong> script which will run in <strong>runbook</strong>.
  This script will first <strong>disable the function apps</strong> in the resource group, then another similar script will <strong>enable the functions apps</strong> in the resource group.</p>
  
  <p>I already tried below script but it does not enable function apps</p>
  
  <pre><code>$connectionName = "AzureRunAsConnection"
  try {
      # Get the connection "AzureRunAsConnection "
      $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         
  
      "Logging in to Azure..."
      Add-AzureRmAccount `
          -ServicePrincipal `
          -TenantId $servicePrincipalConnection.TenantId `
          -ApplicationId $servicePrincipalConnection.ApplicationId `
          -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint  } catch {
      if (!$servicePrincipalConnection)
      {
          $ErrorMessage = "Connection $connectionName not found."
          throw $ErrorMessage
      } else{
          Write-Error -Message $_.Exception
          throw $_.Exception
      }
  }
  
  $RGName = Get-AutomationVariable -Name 'DRPrimaryResourceGroupName'
  $FAppResources = Get-AzureRmResource -ResourceType "Microsoft.Web/sites" -ResourceGroupName $RGName -ExpandProperties  
  $LAppResources = Get-AzureRmResource -ResourceType "Microsoft.Logic/workflows" -ResourceGroupName $RGName -ExpandProperties 
  
  ForEach ($FAResource in $FAppResources) {
          Write-Output ("*****************************************************************************************")
          Write-Output ("Starting FunctionApp "+ $FAResource.ResourceName+ " in Resource Group " +$RGName)
          Write-Output ("*****************************************************************************************")
          Start-AzureRmWebApp -ResourceGroupName $RGName -Name $FAResource.ResourceName
          Write-Output ($FAResource.ResourceName + " and its status is " +  $FAResource.Properties.State)
  }
  ForEach ($LAResource in $LAppResources) {  
          Write-Output ("*****************************************************************************************")
          Write-Output ("Enabling Logic App "+ $LAResource.ResourceName +" in Resource Group"+ $RGName)  
          Write-Output ("***************************************************************************************")
          Set-AzureRmLogicApp -ResourceGroupName $RGName -Name $LAResource.ResourceName -State Enabled -Force
          Write-Output ($LAResource.ResourceName + " and its status is " +  $LAResource.Properties.State)
  }
  </code></pre>