'Export hashtable to csv from keys to value

Ok, I'm struggling with this one. I need to export this hash table to a csv.

$Sku = @{
        "AAD_BASIC"                              = "Azure Active Directory Basic"
        "RMS_S_ENTERPRISE"                       = "Azure Active Directory Rights Management"
        "AAD_PREMIUM"                            = "Azure Active Directory Premium P1"
        "AAD_PREMIUM_P2"                         = "Azure Active Directory Premium P2"
        "MFA_PREMIUM"                            = "Azure Multi-Factor Authentication"
        "RIGHTSMANAGEMENT"                       = "Azure Information Protcetion Plan 1"
        "O365_BUSINESS_ESSENTIALS"               = "Office 365 Business Essentials"
        "O365_BUSINESS_PREMIUM"                  = "Office 365 Business Premium"
        "ADALLOM_O365"                           = "Office 365 Cloud App Security"
        "ADALLOM_S_DISCOVERY"                    = "Unknown"

The above is a sample of the hash table You can find the site here: https://github.com/directorcia/Office365/blob/master/o365-skus.ps1

When I export it turns into a mess. I tried to convert it to a pscustom object. Because of how the table is setup, I have to call the basic . item. Is there a way to reference the .item instead of calling out each item. I've tried .name and .value, neither of them has worked.



Solution 1:[1]

A hash table can easily be converted into a PSCustomObject directly. PSCustomObject can be directly exported/converted to CSV.

$Sku = @{
        "AAD_BASIC"                              = "Azure Active Directory Basic"
        "RMS_S_ENTERPRISE"                       = "Azure Active Directory Rights Management"
        "AAD_PREMIUM"                            = "Azure Active Directory Premium P1"
        "AAD_PREMIUM_P2"                         = "Azure Active Directory Premium P2"
        "MFA_PREMIUM"                            = "Azure Multi-Factor Authentication"
        "RIGHTSMANAGEMENT"                       = "Azure Information Protcetion Plan 1"
        "O365_BUSINESS_ESSENTIALS"               = "Office 365 Business Essentials"
        "O365_BUSINESS_PREMIUM"                  = "Office 365 Business Premium"
        "ADALLOM_O365"                           = "Office 365 Cloud App Security"
        "ADALLOM_S_DISCOVERY"                    = "Unknown"
}

[PSCustomObject]$sku | ConvertTo-Csv -NoTypeInformation

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Doug Maurer