Home
- Details
- Written by: Senka
- Category: Power Shell
- Hits: 1235
Import-Module ActiveDirectory
$month3 = (Get-Date).AddMonths(-3)
$month1 = (Get-Date).AddMonths(-1)
$emailattachment1 = "C:\tasks\users_created_last_3month\users_last_3_month.csv"
$emailattachment2 = "C:\tasks\users_created_last_3month\users_last_1_month.csv"
$users3 = Get-ADUser -filter * -property * | ?{$_.Created -gt $month3} | select name,samaccountname,created,mail,@{Name="Disabled"; Exp={$_.useraccountcontrol -band 2}}|?{$_.Disabled -eq 0} | select name,samaccountname,created,mail | Export-Csv $emailattachment1 -Delimiter ";" -NoTypeInformation -Encoding Default
$users1 = Get-ADUser -filter * -property * | ?{$_.Created -gt $month1} | select name,samaccountname,created,mail,@{Name="Disabled"; Exp={$_.useraccountcontrol -band 2}}|?{$_.Disabled -eq 0} | select name,samaccountname,created,mail | Export-Csv $emailattachment2 -Delimiter ";" -NoTypeInformation -Encoding Default
- Details
- Written by: Senka
- Category: Power Shell
- Hits: 1452
Import-Module ActiveDirectory
$date = (Get-Date).AddDays(-90)
$Managers = Get-ADUser -Filter {((lastlogontimestamp -lt $date) -or (lastlogontimestamp -notlike '*')) -and (whencreated -lt $date) -and ((PasswordLastSet -lt $date) -or (PasswordLastSet -notlike '*')) -and (PasswordNeverExpires -eq 'False')} -property * | Select SamAccountName,Name,CanonicalName, EmailAddress,PasswordLastSet,WhenCreated,PasswordExpired,PasswordNeverExpires, ProfilePath,Department,Title,Manager,@{Name="Disabled"; Exp={$_.useraccountcontrol -band 2}} |?{($_.Disabled -eq 0) -and ($_.PasswordExpired -eq 'True')} | select Manager | sort-object Manager -Unique