SHOW:
|
|
- or go back to the newest paste.
1 | Get-ADUser -Filter {(mail -ne "null") -and (Enabled -eq "true")} -Properties Surname,GivenName,mail | Select-Object Name,Surname,GivenName,mail | Format-Table | |
2 | # Active AD User Accounts with an email address. | |
3 | ||
4 | ||
5 | - | Get-ADUser -Filter * -Properties * | Sort-Object -Property Name | ForEach-Object { |
5 | + | Get-ADUser -Filter * -Properties EmailAddress | where -Property EmailAddress -eq $null |
6 | - | $_ | Format-List -Property Name,SamAccountName,Description,EmailAddress,LastLogonDate,Manager,Title,Department,whenCreated,Enabled |
6 | + | # AD User accounts without an Email Address. |
7 | - | $_.MemberOf | Get-ADGroup | ForEach-Object {$_.Name} | Sort-Object |
7 | + | |
8 | ||
9 | Get-ADUser -Properties * -Filter {Enabled -eq 'True'} -SearchBase "OU=ExampleOU, DC=Domain, DC=com" | Select-Object @{Label = "Email";Expression = {$_.EmailAddress}}, @{Label = "First Name";Expression = {$_.GivenName}}, @{Label = "Last Name";Expression = {$_.Surname}}, @{Label = "Group";Expression = {($_.canonicalname -Split "/")[-2]}} | Export-Csv -Path users.csv -NoTypeInformation | |
10 | - | $alist = "Name`tAccountName`tDescription`tEmailAddress`tLastLogonDate`tManager`tTitle`tDepartment`tCompany`twhenCreated`tAcctEnabled`tGroups`n" |
10 | + | # CSV of all enabled users that are contained in the OU with Distinguished Name “OU=ExampleOU, DC=Domain, DC=com” |
11 | - | $userlist = Get-ADUser -Filter * -Properties * | Select-Object -Property Name,SamAccountName,Description,EmailAddress,LastLogonDate,Manager,Title,Department,Company,whenCreated,Enabled,MemberOf | Sort-Object -Property Name |
11 | + | |
12 | - | $userlist | ForEach-Object { |
12 | + | |
13 | - | $grps = $_.MemberOf | Get-ADGroup | ForEach-Object {$_.Name} | Sort-Object |
13 | + | |
14 | - | $arec = $_.Name,$_.SamAccountName,$_.Description,$_.EmailAddress,$_LastLogonDate,$_.Manager,$_.Title,$_.Department,$_.Company,$_.whenCreated,$_.Enabled |
14 | + | |
15 | - | $aline = ($arec -join "`t") + "`t" + ($grps -join "`t") + "`n" |
15 | + | |
16 | - | $alist += $aline |
16 | + | |
17 | - | } |
17 | + | |
18 | Get-ADUser -Filter * -Properties * | Sort-Object -Property Name | ForEach-Object { | |
19 | $_ | Format-List -Property Name,SamAccountName,Description,EmailAddress,LastLogonDate,Manager,Title,Department,whenCreated,Enabled | |
20 | $_.MemberOf | Get-ADGroup | ForEach-Object {$_.Name} | Sort-Object | |
21 | } | ConvertTo-CSV | |
22 | ||
23 | $alist = "Name`tAccountName`tDescription`tEmailAddress`tLastLogonDate`tManager`tTitle`tDepartment`tCompany`twhenCreated`tAcctEnabled`tGroups`n" | |
24 | $userlist = Get-ADUser -Filter * -Properties * | Select-Object -Property Name,SamAccountName,Description,EmailAddress,LastLogonDate,Manager,Title,Department,Company,whenCreated,Enabled,MemberOf | Sort-Object -Property Name | |
25 | $userlist | ForEach-Object { | |
26 | $grps = $_.MemberOf | Get-ADGroup | ForEach-Object {$_.Name} | Sort-Object | |
27 | $arec = $_.Name,$_.SamAccountName,$_.Description,$_.EmailAddress,$_LastLogonDate,$_.Manager,$_.Title,$_.Department,$_.Company,$_.whenCreated,$_.Enabled | |
28 | $aline = ($arec -join "`t") + "`t" + ($grps -join "`t") + "`n" | |
29 | $alist += $aline | |
30 | } | |
31 | $alist | Out-File D:TempADUsers.csv | |
32 | ||
33 | csvde -f test.csv | |
34 | ||
35 | csvde -f test.csv | |
36 | ||
37 | csvde -f test.csv -r objectClass=user | |
38 | ||
39 | csvde -f test.csv -r objectClass=user -l DN, sAMAccountName, department, memberOf |