This is a little PowerShell script that finds and exports a list of users not logged in, in a number of days, from your Active Directory.

This is the content of the script.

Just copy and paste it into your own PowerShell Script, or use the script attached to this tip.

You can run this from a workstation on which you are logged in to the Active Directory. You don’t need to be Domain Admin to run this report.

Extract the files to a local folder, not to the desktop.

Software you need:

Download the Quest ActiveRoles Management Shell for Active Directory from http://www.quest.com/activeroles-server/

#This script allows you to export a list of users not logged in the last 90 days. You can change the days as you wish.
#By N. Poulsen 2012

#Run this script from a workstation logged in to the Active Directory which you want to pull the date from.
#Place and run it from a local folder (not desktop).

#First thing to do is to download and install the Quest ActiveRoles Management Shell for Active Directory from "http://www.quest.com/activeroles-server/".
#Just run the "ActiveRolesManagmentShell_x86.msi" file and you're good to go.

#Before running this script be sure to run this command in a commandprompt or using the script, RemoteSigned.bat, which will do this for you.
#Command to run: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command "&{set-executionpolicy RemoteSigned -Force}"

#You need to make changes to this obtion, to get it working for your own environment:
#    $DIR='novell.com/users/cool' 
#Change it to match your directory

#Add the Quest Active Roles
echo "Installing Quest ActiveRoles Management Shell for Active Directory"
Add-PSSnapin Quest.ActiveRoles.ADManagement

Start-Sleep -s 5

#Clear screen
cls

#Set the date variable. Set's it to the day of today
$Date=get-date
echo "Today is $Date"
echo ""

#Set the Days variable. Specify how many days the users haven't logged in.
$Days=90
echo "Days users not logged in = $Days"
echo ""

#Set the directory source variable. Specify your search directory from the Active Directory.
$DIR='novell.com/users/cool'
echo "Search directory = $DIR"
echo ""

#The Get-QADUser cmdlet now sersch through the directory for users not logged in the last 90 days and exports it to a csv file called users90.csv. 
#The file will be palced in the folder you run this script from. The users logonname and displayname will be posted in the file.

echo "Exporting list of users not logged in the last $Days days"
echo "Please wait, this could take some time to complete"
echo ""

Get-QADUser -SearchRoot $DIR -sizeLimit 0 | where {
    $_.lastlogontimestamp -and
    (($Date-$_.lastlogontimestamp).days -gt $Days)
    } | Select-Object logonName, DisplayName | export-csv users90.csv

function Wait-KeyPress($prompt='Export complete press any key') {	
    Write-Host $prompt 		

    do {		
            Start-Sleep -milliseconds 100
            } until ($Host.UI.RawUI.KeyAvailable)	
            $Host.UI.RawUI.FlushInputBuffer()
       }
       Wait-KeyPress

All information should be in the script, otherwise please let me know.

0 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 5 (0 votes, average: 0.00 out of 5)
You need to be a registered member to rate this post.
Loading...Loading...

Disclaimer: As with everything else at NetIQ Cool Solutions, this content is definitely not supported by NetIQ, so Customer Support will not be able to help you if it has any adverse effect on your environment.  It just worked for at least one person, and perhaps it will be useful for you too.  Be sure to test in a non-production environment.

Leave a Reply

No Comments
nop1983
By: nop1983
Feb 1, 2012
1:50 pm
Reads:
2,228
Score:
Unrated