How to format the calculated property column to remove specific string pattern?

Welcome Forums General PowerShell Q&A How to format the calculated property column to remove specific string pattern?

Viewing 1 reply thread
  • Author
    Posts
    • #224097
      Participant
      Topics: 21
      Replies: 20
      Points: 191
      Rank: Participant

      Hi All,

      I need to format the below script result, especially in the License (s) column to not show the company name.

      $Office365VanityDomain = ‘CorpFinanceLtd’

      Get-MsolUser -All -EnabledFilter EnabledOnly |
      Where {$_.IsLicensed -eq $true } |
      Select DisplayName,UsageLocation,Licenses, @{Label = ‘License(s)’;
      Expression = {
      ($_.Licenses | ForEach-Object { ($_.AccountSkuId | Where-Object { $_.AccountSkuId -like $Office365VanityDomain }) -replace ‘$Office365VanityDomain:’ } ) -join ‘;’
      }
      },SignInName,UserPrincipalName,@{n=”ProxyAddresses”;e={$_.ProxyAddresses}} | ft -AutoSize

      The default Licenses column shows the license information like:
      {CorpFinanceLtd:MCOPSTNC, CorpFinanceLtd:ENTERPRISEPREMIUM, CorpFinanceLtd:EMSPREMIUM, CorpFinanceLtd:RIGHTSMANAGEMENT_ADHOC…}

      So how do I remove the CorpFinanceLtd: prefix part, so it makes more meaningful result?

      Thank you in advance.

    • #224100
      Participant
      Topics: 4
      Replies: 2231
      Points: 5,414
      Helping Hand
      Rank: Community MVP

      IT, when you post code or error messages or sample data or console output format it as code, please.
      In the “Text” view you can use the code tags “PRE“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.
      Thanks in advance.

      When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to you help making their work twice or more.

      https://stackoverflow.com/questions/61516829/need-some-help-in-formatting-the-out-gridview-display-using-calculated-property

      Thanks

      You should remove the single quotes you have around the variable $Office365VanityDomain.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.