Last active
October 6, 2015 17:15
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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