Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6363543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:03:05+00:00 2026-05-25T00:03:05+00:00

I have a powershell script which outputs all Exchange 2003 mailboxes by size. $computers

  • 0

I have a powershell script which outputs all Exchange 2003 mailboxes by size.

$computers = "vexch01","vexch02"
foreach ($computer in $computers) {
  Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer $computer | sort-object -desc Size | select-object MailboxDisplayName,StoreName,@{Name="Size/Mb";Expression={[math]::round(($_.Size / 1024),2)}}, MailboxGUID | Export-Csv -notype -Path $computer.csv 
}

Currently this outputs the MailboxGUID as a string type GUID (e.g. {21EC2020-3AEA-1069-A2DD-08002B30309D}). I want to look up users in AD by this, but AD stores them in octetBytes format.

I have found some powershell functions which will do the conversion but only when the curly braces are removed. The Guid.ToString method should supply this, but I can’t get it to work in the above.

However, if I could figure out how to do that, the Guid.ToByteArray method might get me even closer.

Has anyone cracked this?

Update: the answers so far helped me write a function that converts the mailboxguid into the correct format for searching via LDAP. However, I now cannot get this working in the script. This is my updated script:

function ConvertGuidToLdapSearchString(
    [parameter(mandatory=$true, position=0)]$Guid
)
{
    $guid_object = [System.Guid]$Guid
    ($guid_object.ToByteArray() | foreach { '\' + $_.ToString('x2') }) -join ''
}

# Gets data through WMI from specified Exchange mailbox servers
$servers = "vexch01","vexch02"
foreach ($server in $servers) {
  Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer $computer | sort-object -desc Size | select-object MailboxDisplayName,StoreName,@{Name="Size/Mb";Expression={[math]::round(($_.Size / 1024),2)}}, @{Name="LDAP Guid";Expression={ConvertGuidToLdapSearchString(MailboxGUID)}} | Export-Csv -notype -Path $server.csv 
}

I’m not sure why using the function in the select-object with @{Name="LDAP Guid";Expression={ConvertGuidToLdapSearchString(MailboxGUID)}} doesn’t work.

Is there another way of using this function in select-object that will give the string?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:03:06+00:00Added an answer on May 25, 2026 at 12:03 am

    In conjunction with Andy Schneider’s answer, you may find this function useful:

    function Convert-GuidToLdapSearchString(
        [parameter(mandatory=$true, position=0)][guid]$Guid
    )
    {
        ($Guid.ToByteArray() | foreach { '\' + $_.ToString('x2') }) -join ''
    }
    

    (I thought I had a more clever way to do this by adding a ScriptProperty to System.Guid, but I seem to have learned that you can’t effectively add members to structs.)

    I’m not sure I understand what you are trying to accomplish based on your comment, but I think you may have just left out a $_. Here is a somewhat contrived example that creates an object with a property that is a GUID, then uses select and Convert-GuidToLdapSearchString to convert the format. I hope it helps.

    $o = New-Object PSObject -Property @{ GUID = $([Guid]::NewGuid()) }
    $o
    $o | select @{ Name='SearchString'; Expression={ Convert-GuidToLdapSearchString $_.GUID } }
    

    This is not at all how I had imagined the function being used. I expected you would use it to create an LDAP search clause such as:

    $searchString = Convert-GuidToLdapSearchString '{9e76c48b-e764-4f0c-8857-77659108a41e}'
    $searcher = [adsisearcher]"(msExchMailboxGuid=$searchString)"
    $searcher.FindAll()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Batch file which will call a Powershell Script : BATCH FILE
i Have an arguments like the one below which i pass to powershell script
I have to stop a browser from a PowerShell script, which I do by
I have a PowerShell script for which I would like to redirect the output
I have a PowerShell script that calls a CmdLet which in turn reports its
I have created a couple of PowerShell scripts which configure computers used in a
I have a powershell script (below) which seems to work but prints an error
It is possible to access Exchange 2010 Addressbook from a PowerShell Script which is
Today I have just thrown together this PowerShell script which takes a tab-delimited text
I have a powershell script below which takes a config file and deletes files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.