Azure Powershell 脚本强制 FTPS Set-AzWebApp:无法将 'System.Object[]' 转换为参数所需的类型 'System.String'

Azure Powershell Script Force FTPS Set-AzWebApp : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter

我目前正在尝试 运行 Azure 中的一个脚本,该脚本将遍历我们所有的 Web 应用程序并打开 FTPS。

这是我目前拥有的

$Subscriptions = Get-AzSubscription
   foreach ($sub in $Subscriptions) {
       Get-AzSubscription -SubscriptionName $sub.Name | Set-AzContext
       $GetName = (Get-AzWebApp).Name
       $GetRG = (Get-AzWebApp).ResourceGroup
     Set-AzWebapp -Name $GetName -ResourceGroupName $GetRG -FtpsState FtpsOnly
       }

Set-AzWebApp: 无法将 'System.Object[]' 转换为参数 'Name' 所需的类型 'System.String'。指定的 不支持方法。

我目前收到此错误,我不理解为 .Name 和 .ResourceGroup,据我了解,它们已经是字符串。我是 Powershell 的新手,所以非常感谢任何帮助。谢谢大家!

您的示例调用 Az-WebApp 时没有参数,它获取订阅中的所有应用程序 - 这是一个集合 - 然后尝试获取该结果的名称,这就是导致错误的原因。

您需要遍历订阅中的每个应用以及遍历每个订阅,如:

   # Get all subscriptions and iterate them
   Get-AzSubscription | ForEach-Object {
       Set-AzContext -SubscriptionName $_.Name
       
       # Get all web apps in the subscription and iterate them
       Get-AzWebApp | ForEach-Object {
           Set-AzWebApp -Name $_.Name -ResourceGroupName $_.ResourceGroup -FtpsState FtpsOnly
       }

   }