Skip to main content

Powershell: Get-ADUser

# Users last logon more than 180 days

PS C:\Windows\system32>Import-Module ActiveDirectory

PS C:\Windows\system32>$today = Get-Date -Format yyyyMMdd

PS C:\Windows\system32>$date = (Get-Date).AddDays(-180)

PS C:\Windows\system32> Get-ADUser -Filter {LastLogonDate -lt $date} -Properties * | Select Name,SamAccountName,Office,LastLogonDate | Sort-Object Office | Export-Csv -Path C:\Audit\last-logon-180-days-$today.csv -NoTypeInformation


Popular posts from this blog

Apache Airflow: Notes

Apache Airflow is used to programmatically author, schedule and monitor workflows.

Fedora Workstation: Install snapd

[tuyen@g73jh ~]$ sudo dnf -y install snapd Last metadata expiration check: 0:20:17 ago on Tue 01 Oct 2019 11:31:30 AM +07. Dependencies resolved. ================================================================================ Package Architecture Version Repository Size ================================================================================ Installing: snapd x86_64 2.41-1.fc30 updates 17 M Installing dependencies: snap-confine x86_64 2.41-1.fc30 updates 2.8 M snapd-glib x86_64 1.49-1.fc30 updates 133 k snapd-selinux noarch 2.41-1.fc30 updates 234 k Installing weak dependencies: gnome-software-snap x86_64 3.32.4-2.fc30 updates 86 k Transaction Summary ================================================================================ Install 5 Packages Total download size...

[Powershell]: Get-Date and commonly used date format

Get-Date and commonly used date format in powershell PS C:\Users\Administrator> get-date Thursday, June 25, 2015 9:42:24 AM PS C:\Users\Administrator> $today = get-date PS C:\Users\Administrator> echo $today Thursday, June 25, 2015 9:43:21 AM PS C:\Users\Administrator> $todayshort = get-date -format yyMMdd PS C:\Users\Administrator> echo $todayshort 150625 PS C:\Users\Administrator> $todaylong = get-date -format yyyyMMdd PS C:\Users\Administrator> echo $todaylong 20150625 PS C:\Users\Administrator>