Trying but failing to make simple script to get FirstName, LastName, State/Provi

Tagged: 

This topic contains 7 replies, has 3 voices, and was last updated by Profile photo of Olaf Soyk Olaf Soyk 2 months, 2 weeks ago.

  • Author
    Posts
  • #68553
    Profile photo of Mr E Briscoe
    Mr E Briscoe
    Participant

    Get-ADUser -Filter * -Properties EmailAddress | select givenName, surName, EmailAddress, State/Province | Export-CSV "C:\Scripts\Email_Addresses.csv"

    Doesn't seem to be working. I get the firstname, surname and email though.

  • #68559
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant

    If I'm not wrong the AD attribute name is only "state" not "state/province". So it should be something like this:

    Get-ADUser -Filter * -Properties EmailAddress | select givenName, surName, EmailAddress, State | Export-CSV "C:\Scripts\Email_Addresses.csv" -NoTypeInformation
    • #68565
      Profile photo of Mr E Briscoe
      Mr E Briscoe
      Participant

      I tried just state but it doesn't work. Column is just blank.

  • #68566
    Profile photo of Mr E Briscoe
    Mr E Briscoe
    Participant

    If I run my original one the column just says:

    "Microsoft.ActiveDirectory.Management.ADPropertyValueCollection"

  • #68568
    Profile photo of Mark Prior
    Mark Prior
    Participant
    Get-ADUser -Filter * -Properties EmailAddress | select givenName, surName, EmailAddress, St | Export-CSV "C:\Scripts\Email_Addresses.csv" -NoTypeInformation

    give that a go

  • #68572
    Profile photo of Mark Prior
    Mark Prior
    Participant

    ahh missed the first part after properties

    
    Get-ADUser -Filter * -Properties EmailAddress, st | select givenName, surName, EmailAddress, St | Export-CSV "C:\Scripts\Email_Addresses.csv" -NoTypeInformation
    
    
    
    
    PS C:\Users\mark.prior> Get-ADUser Elias.Manneh -Properties EmailAddress, st | select givenName, surName, EmailAddress, St
    
    givenName surName EmailAddress          St  
    --------- ------- ------------          --  
    Elias     Manneh  Elias.Manneh@blurb.com test
    
    • #68578
      Profile photo of Olaf Soyk
      Olaf Soyk
      Participant

      Mark is right. You have to "force" Get-ADUser to output the additional attribute State. So this works for me:

      Get-ADUser -Filter * -Properties EmailAddress,State | select givenName, surName, EmailAddress, State | Export-CSV "C:\Scripts\Email_Addresses.csv" -NoTypeInformation

      Next time to be able to help yourself you can try this and there you can see all the names of the possible attributes:

      Get-ADUser $env:USERNAME -Properties * | Select-Object -Property *

You must be logged in to reply to this topic.