Created
October 3, 2022 17:07
-
-
Save NicholasLeader/8af986cfa211892a5fdb5ee44d229762 to your computer and use it in GitHub Desktop.
PowerShell to look up details between 2 user accounts that are similarly named / contains same substring - using split & calculated property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Nicholas Leader | |
10.03.2022 | |
script to: | |
pull AD accounts with a preceding 'a-', that are enabled | |
using '-ResultPageSize 1000' to avoid an AD DC server side error message 'invalid enumeration context' | |
using 'split' to return the normal user AD samaccount name and return the associated 'company' value on the normal user account | |
#> | |
#date stamp in string | |
$DateStamp = get-date -Format MM.dd.yyyy.mm | |
get-aduser -filter {(samaccountname -like 'a-*') -and (enabled -eq "TRUE") } -properties company -ResultPageSize 1000 | | |
select-object name,samaccountname, enabled,@{ name = 'NONaCompany'; expression = {(get-aduser -properties company ((get-aduser $_).samaccountname -split( "-"))[1]).company }} | | |
export-csv -NoTypeInformation "a-report.$DateStamp.csv" | |
#example splitting of 'a-' account to return normal account | |
# ((get-aduser a-exampleUser).samaccountname -split( "-"))[1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment