Wrote below script a while back but discovered that due to a process change phone numbers we need a delay on the accounts the script goes and gets. Currently it exports into CSV any new account created after 1 day. We need it so it gets new accounts but with a delay of 2 weeks, no earlier and no later. Like WhenCreated equals to 14 days, nothing before, nothing after.
Import-Module ActiveDirectory
$When = ((Get-Date).AddDays(-1)).Date
$OUArea = "OU=Accounts,DC=contoso,DC=uk"
$ExportPath= "\\Fileshare\share\Filename-$(get-date -f dd-MM-yyy).csv"
Get-ADUser -SearchBase $OUArea -Filter {whenCreated -ge $When} -properties givenName, sn, sAMAccountName, title, department, msRTCSIP-Line, mail, whenCreated |
Select-Object givenName, sn, sAMAccountName, title, department,@{n='msRTCSIP-Line';e={$_.'msRTCSIP-Line' -Replace('tel:'),''}}, mail, whenCreated |
Export-Csv -NoTypeInformation $ExportPath