Announcement

Collapse
No announcement yet.

Change existing Powershell script to include more returned objects.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Change existing Powershell script to include more returned objects.

    I have the following script which returns various items from Active Directory:

    $pSearchBase = "ou=MyOU2,OU=MyOU1,dc=mydomain,dc=com"
    $pOutputHeaders = "Name", "GivenName", "Surname", "EmployeeType", "ObjectClass", "UserPrincipalName", "Enabled", "DistinguishedName", "SamAccountName"
    Get-ADUser -Properties employeeType -Filter * -SearchBase $pSearchBase | Select-Object $pOutputHeaders | Export-Csv "GetUsersByProperty_Output.csv"

    What I'd like to do is return more objects than what are returned by the Get-ADUser commandlet, as an example, I want to return the Manager object properties as well.


    The other properties I want to return are:

    * Manager
    * Description
    * Employee Type
    * Location
    * City
    * Office
    * Country
    * region
    * Expiration Date
    * Last Logon Date
    * password does not expire

    Is this possible using my existing code?
    |
    +-- JDMils
    |
    +-- Regional Systems Engineer, DotNet programmer & Jack of all trades
    |

  • #2
    All of these appear to be attributes of the user, so it should be a question of finding the correct object names and amending your OutputHeaders list

    The exception might be the manager, where the Object GUID or SID will be stored, not the name
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Code:
      $pSearchBase = "ou=MyOU2,OU=MyOU1,dc=mydomain,dc=com"
      $pOutputHeaders = "Name", "GivenName", "Surname", "EmployeeType", "ObjectClass", "UserPrincipalName", "Enabled", "DistinguishedName", "SamAccountName"
      
      Get-ADUser -Properties * -Filter * -SearchBase $pSearchBase | Select-Object $pOutputHeaders | Export-Csv "GetUsersByProperty_Output.csv"
      This will tell Get-ADUser to get all the properties of the object. Your Select-Object then narrows what you get displayed.
      Run
      Code:
      Get-ADUser AUserName -Properties *
      and you will see all the properties you need the correct name for.
      Last edited by grunt; 14th November 2015, 14:06. Reason: spelling

      Comment


      • #4
        Code:
        $search = "ou=MyOU2,OU=MyOU1,dc=mydomain,dc=com"
        
        [email protected](
           "Name"
           "GivenName"
           "Surname"
           "EmployeeType"
           @{n="ObjectClass";e={(Get-Culture).TextInfo.ToTitleCase($_.ObjectClass)}}
           "UserPrincipalName"
           "Enabled"
           "DistinguishedName"
           "SamAccountName"
           @{n="ManagerName";e={(Get-ADUser -Identity $_.Manager -properties Name).Name}}
           "Description"
           "Location"
           "City"
           "Office"
           "Country"
           "c"
           @{n="Region";e={$_.co}}
           "countryCode"
           "LastLogonDate"
           @{n="ExpiryDate";e={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}
           "LockedOut"
           "pass*"
        )
        
        Get-ADUser -filter * -Properties *,"msDS-UserPasswordExpiryTimeComputed" -SearchBase $search | Select-Object $props | Export-Csv "GetUsersByProperty_Output.csv"  -notypeinfo -encoding "UTF8"

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment

        Working...
        X