使用Powershell脚本获取Azure WebApp详细信息 [英] Powershell script to fetch Azure WebApp details

查看:136
本文介绍了使用Powershell脚本获取Azure WebApp详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to write powershell script which gets all webapps and few properties of each azure web app. Below is the script i tried but it's giving me Http20Enabled is not valid property error. I think somehow i'm using the wrong scope.

我需要在CSV文件的一行中获取该Web应用程序的 Webapp SiteConfig 的属性.

I need to get properties of Webapp and SiteConfig of that webapp in a single row in CSV file.

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"

已更新:

尝试过:

Get-AzureRMWebApp | ForEach-Object {
    $webapp = Get-AzureRMWebApp -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
    } 
}

发现错误-

无法将"System.Object []"转换为所需的"System.String"类型通过参数"ResourceGroupName".不支持指定的方法.

Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ResourceGroupName'. Specified method is not supported.

PS版本5.1.17763.771
AzureRM 5.7.0

PSVersion 5.1.17763.771
AzureRM 5.7.0

推荐答案

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

I think what you mean to do was assign $webapp to the output of the Get-AzureRMWebApp command. I am also not really sure how the Select-Object command is supposed to work at the end, but I am assuming you want to have an object to use later. So you can use the New-Object cmdlet and then pass in the values from the $webapp object as properties. You don't need to expand the siteconfig property, you can reference the properties directly with dot notation. This ran on my system and gave me the output below the snippet.

Get-AzureRMWebApp | ForEach-Object {
    $webapp = Get-AzureRMWebApp -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

第二个问题的答案

我直接复制并粘贴了您的问题,效果很好.您的AzureRM模块可以使用一些更新.

I copied and pasted straight from your question and it worked just fine. Your AzureRM module could use some updating.

PS C:\> $Results = Get-AzureRMWebApp | ForEach-Object {
>>     $webapp = Get-AzureRMWebApp -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
>>     }
>> }
PS C:\> $Results.count
15

PS C:\> Get-Module AzureRM

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     6.13.1     AzureRM

这篇关于使用Powershell脚本获取Azure WebApp详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆