Don’t do that #8: Get all properties instead of specific one

By | March 20, 2015

Don’t do that: The following command retrieves all the properties for a user although only the property “PasswordLastSet” is required:

Get-ADUser -Identity $user -Properties * | Select-Object -Property PasswordLastSet


Do that: It’s better and faster to retrieve only the property “PasswordLastSet” (we only need this one).

With very large queries, the difference between “-Properties *” and “-Properties PasswordLastSet” can make a significant difference.

(Get-ADUser -Identity $user -Properties PasswordLastSet).PasswordLastSet


previous-buttonnext-button

2 thoughts on “Don’t do that #8: Get all properties instead of specific one

  1. Pingback: Don't do that #9 : Use Write-Host for verbose messages - Powershell Guru

  2. Pingback: Don't do that #7 : Multiple lines to create variables with the same prefix - Powershell Guru

Leave a Reply

Your email address will not be published. Required fields are marked *