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

Welcome Forums General PowerShell Q&A Trying but failing to make simple script to get FirstName, LastName, State/Provi

This topic contains 7 replies, has 3 voices, and was last updated by

 
Participant
1 year, 7 months ago.

  • Author
    Posts
  • #68553

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 170
    Helping Hand
    Rank: 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

      Participant
      Points: 0
      Rank: Member

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

  • #68566

    Participant
    Points: 0
    Rank: Member

    If I run my original one the column just says:

    "Microsoft.ActiveDirectory.Management.ADPropertyValueCollection"

  • #68568

    Participant
    Points: 20
    Rank: Member
    Get-ADUser -Filter * -Properties EmailAddress | select givenName, surName, EmailAddress, St | Export-CSV "C:\Scripts\Email_Addresses.csv" -NoTypeInformation

    give that a go

    • #68569

      Participant
      Points: 0
      Rank: Member

      ST column is blank 🙁

  • #68572

    Participant
    Points: 20
    Rank: Member

    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

      Participant
      Points: 170
      Helping Hand
      Rank: 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 *

The topic ‘Trying but failing to make simple script to get FirstName, LastName, State/Provi’ is closed to new replies.