Skip to content

Instantly share code, notes, and snippets.

@mcenirm
Last active June 24, 2018 19:19
Show Gist options
  • Save mcenirm/bed276c8d316a7c805cbbeea07394f66 to your computer and use it in GitHub Desktop.
Save mcenirm/bed276c8d316a7c805cbbeea07394f66 to your computer and use it in GitHub Desktop.
Assorted Powershell scriptlets to remember...

A collection of assorted Powershell scriptlets that should be useful to remember.

$alias = 'jdoe'
$recipient = Get-Recipient $alias
$dn = $recipient.DistinguishedName
$filter = "Members -like ""$dn"""
Get-DistributionGroup -Filter $filter
<# Results:
Name DisplayName GroupType PrimarySmtpAddress
---- ----------- --------- ------------------
Staff Staff Universal, SecurityEnabled staff@example.com
WebTeam Web Team Universal webteam@example.com
#>
Import-Module ActiveDirectory
Search-ADAccount -LockedOut | %{ Get-ADUser $_.samaccountname -Properties * } | select samaccountname,lockedout,@{N='lockouttime'; E={[DateTime]::FromFileTime($_.lockouttime)}},@{N='lastlogon'; E={[DateTime]::FromFileTime($_.lastlogon)}}
<# Results:
samaccountname lockedout lockouttime lastlogon
-------------- --------- ----------- ---------
Guest True 6/4/2009 1:27:59 AM 12/31/1600 6:00:00 PM
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment