Skip to content

Instantly share code, notes, and snippets.

@jonathanelbailey
Last active October 6, 2015 17:15
Show Gist options
  • Save jonathanelbailey/b97c17e712284cae93e0 to your computer and use it in GitHub Desktop.
Save jonathanelbailey/b97c17e712284cae93e0 to your computer and use it in GitHub Desktop.
A small script that allows an administrator to get a list of all users who have not logged in to a terminal server.
# you must be logged in to the terminal server in question.
$session = New-PSSession -ComputerName $ComputerName # this must be the name of the DC whose session you must import.
Invoke-Command -ScriptBlock {Import-Module ActiveDirectory} -Session $session
Import-PSSession -Module activedirectory -Session $session
$ou = Get-ADOrganizationalUnit -Filter * -Properties * | where-object name -match "$OUName"
$users = Get-ADUser -Filter * -Properties * | Where-Object distinguishedname -Match $ou.distinguishedname
$users | Select-Object name -Property lastlogondate | Where-Object lastlogondate -ne $null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment