Result Get-Aduser and Net user in one table

Welcome Forums General PowerShell Q&A Result Get-Aduser and Net user in one table

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

 
Participant
3 months ago.

  • Author
    Posts
  • #111373

    Participant
    Points: 0
    Rank: Member

    Hi!

    I'm pretty new to Powershell but I already noticed that it has made my work faster and easier to find some simple information. Right now i'm figuring out how to combine result from Get-Aduser and Net user together into one Format List.

    The reason I want this is because the net user command gives me a lot of information I don't need. Except for the PasswordExpirationDate. With Get-ADUser, I can't get that specific information.

    This is what I got so far.

    Get-ADUser username -Properties | fl DisplayName, SamAccountName, LastLogonDate, PasswordExpired, PasswordExpires, PasswordLastSet, AccountExpirationDate, Mobile, telephoneNumber, extensionAttribute1

    The command is working fine, but I can't find the solution to add the ExpirationDate of the password into that format list.

    Could someone help me? Any improvement suggestions are also welcome, just trying to learn the language 🙂

  • #111380

    Participant
    Points: 315
    Helping Hand
    Rank: Contributor

    You have a couple of small problems, first there is no 'standard' property "PasswordExpires", it's "PasswordNeverExpires". It's best to define the properties you want returned from Active Directory, like so:

    Get-ADUser -Identity USERNAME -Properties DisplayName, SamAccountName, LastLogonDate, PasswordExpired, PasswordNeverExpires, PasswordLastSet, AccountExpirationDate, Mobile, telephoneNumber, extensionAttribute1
    

    Be careful with Format-* commands because they stop the pipeline. You cannot do Get-AdUser ... | Format-List ... | Export-CSV ...

    There are some free e-books above including Powershell Gotchas that are great beginner resources

  • #111383

    Participant
    Points: 861
    Helping Hand
    Rank: Major Contributor

    Great, PowerShell makes our life easier and it will surprise you in each and every moment with its capabilities on the go.

    Here you are using two APIs

    • PowerShell cmdlet (Get-ADUser)
    • net.exe (native executable)

    PowerShell cmdlet returns objects and net use returns text and you need a combined result.
    At a high level, you can use PSCustomObjects and in many other ways. Here I'll show another method using calculate properties.

    Get-ADUser -Identity username -properties * | Select-Object -Property DisplayName, LastLogonDate, PasswordExpired, PasswordLastSet, AccountExpirationDate, Mobile, telephoneNumber, extensionAttribute1, @{E={((net user username /domain|Select-String -Pattern 'Password expires') -split 'Password expires')[-1].Trim() };L='PasswordExpires'}
    

    For learning PowerShell, You can always start with
    https://www.manning.com/books/learn-windows-powershell-in-a-month-of-lunches-second-edition
    https://mva.microsoft.com/liveevents/powershell-jumpstart

  • #111419

    Participant
    Points: 0
    Rank: Member

    Thank you both for your replies. I got it working with the solution kvprasoon gave me, but I learned from both of you!

    The PSCostomObject is a little hard, but I will read the article.

    Thank you both again!

The topic ‘Result Get-Aduser and Net user in one table’ is closed to new replies.