用于获取Azure WebApp详细信息的Powershell脚本

问题描述 投票:0回答:1

我正在尝试编写Powershell脚本,该脚本将获取所有Web应用程序以及每个Azure Web应用程序的少量属性。以下是我尝试的脚本,但它给了我Http20Enabled无效的属性错误。我认为我以某种方式使用了错误的范围。

我需要在CSV文件的单行中获取该Web应用程序的WebappSiteConfig的属性。

Get-AzureRmWebApp | ForEach-Object {
  ($webapp = $_) | Get-AzureRmWebApp -ResourceGroupName {$webapp.ResourceGroup} -Name {$webapp.Name} | select -ExpandProperty SiteConfig | Select-Object @{ 

    Http20Enabled = $_.Http20Enabled
    MinTlsVersion = $_.MinTlsVersion
    AlwaysOn = $_.AlwaysOn
    Cors = $_.Cors
    Owner = {$webapp.Tags.Owner}
    Name = {$webapp.Name}
    ResourceGroup = {$webapp.ResourceGroup}
    HttpsOnly = {$webapp.HttpsOnly}
    ClientAffinityEnabled = {$webapp.ClientAffinityEnabled}
  } 
}| Export-Csv "C:apps1\test.csv"

感谢您的任何帮助。

azure-web-app-service azure-powershell azure-app-service-plans
1个回答
0
投票

我认为您的意思是将$ webapp分配给Get-AzureRMWebApp命令的输出。我也不太确定Select-Object命令在最后应该如何工作,但是我假设您想拥有一个以后使用的对象。因此,您可以使用New-Object cmdlet,然后将$ webapp对象中的值作为属性传递。您无需扩展siteconfig属性,可以直接使用点符号引用这些属性。这在我的系统上运行,并在摘要下方提供了输出。

Get-AzWebApp | ForEach-Object {
    $webapp = $_ | Get-AzWebApp -ResourceGroupName $_.ResourceGroup -Name $_.Name 

    New-Object -TypeName psobject -property @{
      Http20Enabled = $webapp.siteconfig.Http20Enabled
      MinTlsVersion = $webapp.siteconfig.MinTlsVersion
      AlwaysOn = $webapp.siteconfig.AlwaysOn
      Cors = $webapp.siteconfig.Cors
      Owner = $webapp.Tags.Owner
      Name = $webapp.Name
      ResourceGroup = $webapp.ResourceGroup
      HttpsOnly = $webapp.HttpsOnly
      ClientAffinityEnabled = $webapp.ClientAffinityEnabled
    } 
}


MinTlsVersion         : 1.0
HttpsOnly             : False
Http20Enabled         : False
AlwaysOn              : False
Owner                 :
Name                  : WEBAPP-NAME2
ResourceGroup         : RG-NAME1
Cors                  :
ClientAffinityEnabled : True

MinTlsVersion         : 1.0
HttpsOnly             : False
Http20Enabled         : False
AlwaysOn              : False
Owner                 :
Name                  : WEBAPP-NAME2
ResourceGroup         : RG-NAME1
Cors                  :
ClientAffinityEnabled : True
© www.soinside.com 2019 - 2024. All rights reserved.