Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从Azure Powershell重新启动Azure appservice_Powershell_Azure_Azure Web App Service - Fatal编程技术网

如何从Azure Powershell重新启动Azure appservice

如何从Azure Powershell重新启动Azure appservice,powershell,azure,azure-web-app-service,Powershell,Azure,Azure Web App Service,如何从Azure中ARM订阅的自动化帐户中的Runbook中运行的Azure Powershell重新启动AppService 我认为方法是: Restart-AzureWebsite -Name "your-appservice-name" 但这会得到: Restart-AzureWebsite : No default subscription has been designated. Use select-AzureSubscription -Default #<subscript

如何从Azure中ARM订阅的自动化帐户中的Runbook中运行的Azure Powershell重新启动AppService

我认为方法是:

Restart-AzureWebsite -Name "your-appservice-name"
但这会得到:

Restart-AzureWebsite : No default subscription has been designated.
Use select-AzureSubscription -Default #<subscriptionName> to set the default subscription.

此Powershell脚本在Azure自动化运行手册中工作:

Invoke-AzureRmResourceAction -ResourceGroupName "<your-resource-group-name>" -ResourceName "<your-resource-name>" -ResourceType 'Microsoft.Web/sites' -Action 'Restart' -Force
调用AzureRmResourceAction-ResourceGroupName”“-ResourceName”“-ResourceType'Microsoft.Web/sites'-Action'Restart'-Force
编辑

然而,下一个脚本可能更好;它依赖于@Tom Sun的上述答案,即

  • 升级模块-转到自动化帐户/模块/更新Azure模块
  • 导入AzureRm.Websites模块-转到自动化帐户/模块/浏览库
  • 在自动化帐户/凭据下创建

    $Cred = Get-AutomationPSCredential -Name '<your-credentials>'
    Add-AzureRMAccount -Credential $Cred
    
    Get-AzureRmSubscription –SubscriptionName '<your-subscription-name>' | Select-AzureRmSubscription
    
    Restart-AzureRmWebApp -ResourceGroupName "office" -Name "<your-appservice-name>"
    
    $Cred=获取自动PSCredential-名称“”
    添加AzureRMAccount-凭证$Cred
    获取AzureRmSubscription–SubscriptionName“”;选择AzureRmSubscription
    重新启动AzureRmWebApp-ResourceGroupName“office”-名称“”
    
  • Azure PowerShell中没有可用的重新启动AzureRmWebApp

    正如Walter-MSFT提到的,我们可以导入AzureRM.Websites,在此之前,我们需要将
    AzureRM.Profile
    更新到4.0,更多详细信息请参考屏幕截图

    在此之前,我们可以在本地创建Azure广告服务主体。 如何创建服务主体我们可以参考以下内容

    在Runbook中运行Restart AzureRmWebApp命令

    $azureAplicationId ="Application Id"
    $azureTenantId= "tenant Id"
    $azurePassword = ConvertTo-SecureString "password" -AsPlainText -Force
    $psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
    Add-AzureRmAccount -Credential $psCred -TenantId $azureTenantId  -ServicePrincipal 
    Restart-AzureRmWebApp -ResourceGroupName "ResourceGroup" -Name "WebApp Name" 
    

    重新启动AzureWeb
    这是一个经典的cmdlet。你的Azure Power Shell版本是什么
    Get Module-listavable-Name Azure-Refresh
    该命令甚至不在Azure Powershell中运行;它返回:runbook作业尝试了3次,但每次都失败。此处可以找到runbook作业失败的常见原因:在runbook中,您需要导入模块
    AzureRM.Websites
    ,导入模块AzureRM.Websites导致:导入模块:未加载指定模块“AzureRM.Websites”,因为在任何模块目录中都找不到有效的模块文件。您好,您只需要将模块导入到您的自动化帐户,然后就可以使用cmdlet。无需在您的runbook中使用
    导入模块AzureRm.Websites
    。这些命令(登录AzureRmAccount和重新启动AzureRmWebApp)在runbook中都不可用。我已更新了如何为自动化帐户添加模块的答案。
     Login-AzureRmAccount
     $sp = New-AzureRmADServicePrincipal -DisplayName exampleapp -Password "password"
     Sleep 20
     New-AzureRmRoleAssignment -RoleDefinitionName Contributor -ServicePrincipalName $sp.ApplicationId
    
    $azureAplicationId ="Application Id"
    $azureTenantId= "tenant Id"
    $azurePassword = ConvertTo-SecureString "password" -AsPlainText -Force
    $psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
    Add-AzureRmAccount -Credential $psCred -TenantId $azureTenantId  -ServicePrincipal 
    Restart-AzureRmWebApp -ResourceGroupName "ResourceGroup" -Name "WebApp Name"