Value of custom atttribute depending existences.

Welcome Forums General PowerShell Q&A Value of custom atttribute depending existences.

Viewing 5 reply threads
  • Author
    Posts
    • #230950
      Participant
      Topics: 5
      Replies: 6
      Points: 72
      Rank: Member

      hi there 🙂

      Get-ADUser -Filter * -Properties * -searchbase “ou=res migratie,ou=divisies,dc=network,dc=local” | % {
      New-Object PSObject -Property @{
      UserName = $_.DisplayName
      EmployeeID = $_.EmployeeID
      UPN = $_.UserPrincipalName
      PrimarySMTP= $_.EmailAddress
      RecipientType = $(If (get-mailbox -identity $_.userprincpalname) {( (get-mailbox $_.userprincpalname).RecipientType) } Else { “Empty” })
      LitigationHoldEnabled = get-mailbox -identity $_.userprincpalname
      CustomAttribute15 = $_.extensionAttribute15
      Groups = ($_.memberof | Get-ADGroup | Select -ExpandProperty Name) -join “,”
      }
      } | Select UserName,EmployeeID,UPN,PrimarySMTP,RecipientType,CustomAttribute15,Groups | Export-Csv C:\temp\ADreport.csv -NTI

       

      Hi

       

      In the red sentence I try to fill attribute Receipttype with value what is dependent of the existence of the mailboxobject.

      I got the error message :

      Cannot process argument transformation on parameter ‘Identity’. Cannot convert the “System.Collections.ArrayList” value of type “System.Collections.ArrayList” to type “Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter”.
      + CategoryInfo : InvalidData: (:) [Get-Mailbox], ParameterBindin…mationException
      + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-Mailbox
      + PSComputerName : outlook.office365.com

       

      I tried a simple line what you see in blue. But unfortunately that gives the same error message.

      It sas something about converting, but with my knowledge I say “dumb thing what conevertion” 🙂

      So guys what do I here wrong?

      So purpose is to put a value in a customobject if a value of object (n this case mailbox) exists.

       

       

    • #231007
      Participant
      Topics: 3
      Replies: 431
      Points: 1,533
      Helping Hand
      Rank: Community Hero

      Is the typo for userprincipalname also present in your code?

      RecipientType = $(If (get-mailbox -identity $_.userprincpalname) {( (get-mailbox $_.userprincpalname).RecipientType) } Else { “Empty” })
      LitigationHoldEnabled = get-mailbox -identity $_.userprincpalname
      

      $_.userprincIpalname

    • #231037
      Participant
      Topics: 12
      Replies: 1652
      Points: 2,707
      Helping Hand
      Rank: Community Hero

      There are multiple things that could use improvement

      • Only return properties you need – Using Properties * returns ALL properties, so you’re returning like 90 properties and using 6. This takes longer and takes up much more memory.
      • Avoid unnecessary GETs – If Get-Mailbox lookup fails, it would be NULL, which is empty. When you find an object by Id, it will cause a failure. The error you posted basically is saying the value you are passing is an array and not an identifier for a mailbox. if you are doing it in a loop, it will cause an error. Even in the code below, it’s doing 2 GETs on a mailbox, which could taking more time, but you can give it a try as the calculated expression will not report an error. Test with a couple of accounts first then do the full query
      • Parse over another GET – The group code you posted is doing a GET on the group. All you need is the name, which is contained in the DistinguishedName, so you can just parse it rather than another lookup
      $results = Get-ADUser -Filter * -Properties DisplayName,EmployeeId,UserPrincipalName,EmailAddress,extensionAttribute15 -searchbase “ou=res migratie,ou=divisies,dc=network,dc=local” | 
                 Select-Object @{Name='UserName';Expression={$_.DisplayName}},
                               EmployeeId,
                               @{Name='UPN';Expression={$_.UserPrincipalName}},
                               @{Name='PrimarySMTP';Expression={$_.EmailAddress}},
                               @{Name='RecipientType';Expression={Get-Mailbox -Identity $_.userprincpalname | Select -ExpandProperty RecipientType}},
                               @{Name='LitigationHoldEnabled';Expression={Get-Mailbox -Identity $_.userprincpalname | Select -ExpandProperty LitigationHoldEnabled}},
                               @{Name='CustomAttribute15';Expression={$_.extensionAttribute15}},
                               @{Name='Groups';Expression={$_.memberof | foreach{($_ -split ',')[0].Replace('CN=','')}}}
      
      • This reply was modified 1 month, 2 weeks ago by Rob Simmers.
    • #231052
      Participant
      Topics: 5
      Replies: 6
      Points: 72
      Rank: Member

      Doug!!!!,

      Im a shamed brother, very deeeeep

      I’ve made a appointment with the opticien…….

      Hey site master give this champ 100000000 points and me the same but starting with a “-”

      Thanks and take care of your self’s

       

       

       

    • #231058
      Participant
      Topics: 5
      Replies: 6
      Points: 72
      Rank: Member

      Hey Rob bro,

      The same what I said to Doug.

      I was watching and watching as cow looking at passing train but didnt sas the typo where Doug referred to.

      Thanks friend for you help and will follow your advices.

      Wishing you the best.

       

    • #231235
      Participant
      Topics: 3
      Replies: 431
      Points: 1,533
      Helping Hand
      Rank: Community Hero

      Don’t be ashamed! It happens to us all. Usually just me explaining it to another person leads to me discovering something I overlooked for days or weeks. It’s helpful to have someone just to be a second pair of eyes.. or an entire forum. Cheers!

Viewing 5 reply threads
  • You must be logged in to reply to this topic.