azure - 如何修复 "add-member : Cannot add a member with the name "“因为具有该名称的成员已存在”

标签 azure powershell csv azure-logic-apps azure-powershell

我需要列出 LogicApp 服务上的多个 FTP 连接并将此列表导出到 csv 文件中。此导出用于查看 SSL 协议(protocol)连接是否激活。我的脚本生成此错误。

add-member :无法添加名为“FTP”的成员,因为具有该名称的成员已存在。无论如何,要覆盖该成员,请将 Force 参数添加到您的命令中。

LogicApp FTP 连接: https://learn.microsoft.com/en-us/azure/connectors/connectors-create-api-ftp

我需要在 Excel 上以这种格式添加这些 FTP 连接:

format need

            $LogicApp_temp = $null
            $LogicApp_obj = @()
            $LogicApp_temp = new-object PSObject

            $FTPAll = Get-AzResource -ResourceGroupName $RG -ResourceType Microsoft.Web/connections

            foreach ( $FTPAlls in $FTPAll ) {

            $FTPName = $FTPAlls.name

            $FTPName1 = Get-AzResource -ResourceGroupName $RG -ResourceType Microsoft.Web/connections -Name $FTPName 

            foreach ($FTPName2 in $FTPName1) {

            $FTPcheckType = $FTPName2.Properties.api.name

            if ( $FTPcheckType -eq  "ftp") {

            $FTPSSL1 = $FTPName1.Properties.parameterValues.isSSL

            }

            else {

            }
                $LogicApp_temp | add-member -MemberType NoteProperty -Name "FTP" -Value "$FTPName2.Properties.displayName $FTPSSL1"
            }

            }
            $LogicApp_obj += $LogicApp_temp
            Write-Output "LogicApp Name : $Name Ressource Group : $RG OK"

            # CSV Exports : 
            $LogicApp_obj | Export-Csv $csvPath -Append -NoTypeInformation

提前感谢您的帮助

最佳答案

由于PSObject属性只能一次设置一个值,如果使用-Force,它会覆盖之前的值。

如果您想获取像您提供的格式那样的 .csv 文件,我们可以先附加每个字符串,例如 joyftp True

我的工作示例:

$RG = "<resource group name>"  

$LogicApp_obj = @()
$value = ""

$FTPAll = Get-AzResource -ResourceGroupName $RG -ResourceType Microsoft.Web/connections

foreach ( $FTPAlls in $FTPAll ) {

$FTPName = $FTPAlls.name

$FTPName1 = Get-AzResource -ResourceGroupName $RG -ResourceType Microsoft.Web/connections -Name $FTPName 

foreach ($FTPName2 in $FTPName1) {

$FTPcheckType = $FTPName2.Properties.api.name
$displayname = $FTPName2.Properties.displayName
$LogicApp_temp = New-Object -TypeName PSObject

if ( $FTPcheckType -eq  "ftp") {


$FTPSSL1 = $FTPName1.Properties.parameterValues.isSSL

$value += "$displayname $FTPSSL1 | "
$LogicApp_temp | add-member -MemberType NoteProperty -Name "FTP" -Value "$value" -Force 

}

}

}

Write-Output "LogicApp Name : $Name Ressource Group : $RG OK"

# CSV Exports : 
$LogicApp_temp | Export-Csv -Path "C:\Users\joyw\Desktop\ftp.csv" -NoTypeInformation

.csv 文件:

enter image description here

关于azure - 如何修复 "add-member : Cannot add a member with the name "“因为具有该名称的成员已存在”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57149064/

相关文章:

powershell - 无法将此字符串转换为Powershell中的Date对象

powershell - EntityReference中的DynamicsCRM QueryExpression条件

php - 从不同的表中选择多行 mysqli 以合并并导出为 CSV

php - auto_detect_line_endings - 有副作用吗?

ssl - 在本地运行启用 SSL 的 Azure 网站

azure - 无法使用 Azure DevOps 管道中设置的输出变量

c# - 在 azure blob 存储中就地创建 zip 文件

PowerShell - 双循环可能吗?

shell - 从命令行对 .csv 进行排序

Azure - 阻止订阅所有者修改特定资源组?