Accounts that have not been logged into for more than 90 days

Hi Folks,
Good Day.
Can anyone help me to update below powershel script?
below script find in my domain all the AD users accounts that have not been logged into for more than 90 days and export the report to .csv file. in addition what I want:
1. OU=Others, Sales --> exclude this OUs
2. Disable all the user based on 90 days export report .csv file 
import-module activedirectory 
$domain = "test.com" 
$DaysInactive = 90 
$time = (Get-Date).Adddays(-($DaysInactive))
$timer = (Get-Date -Format yyyy-mm-dd)
# Get all AD User with lastLogonTimestamp less than our time and set to enable
Get-ADUser -Filter {LastLogonTimeStamp -lt $time -and enabled -eq $true} -Properties LastLogonTimeStamp |
# Output Name and lastLogonTimestamp into CSV
select-object givenname,Name,@{Name="Stamp"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp).ToString('dd-MM-yyyy_hh:mm:ss')}} | Export-Csv c:\temp\90DaysInactive-$(Get-Date -format dd-MM-yyyy).csv –NoTypeInformation
Many thanks for advance Help:

Hi Anna,
Good Day.
Many thanks for your responce.
with your help i can manage to exclude the OUs as wellas can get the .csv report via mail.
Now i want to disable all the user based on 90 days export report .csv file.
could you help me on this please? the report will come everyday like below:
filename=90DaysInactive-dd-mm-yyyy.csv
sample output:
Given name User Name
Last LogOn
Test User1 user1
03-10-2006_05:30:59
Test User2 user2
02-10-2006_12:00:34
import-module activedirectory 
$domain = "test.com" 
$DaysInactive = 1 
$time = (Get-Date).Adddays(-($DaysInactive))
$timer = (Get-Date -Format yyyy-mm-dd)
$FileName="c:\temp\90DaysInactive-$(Get-Date -format dd-MM-yyyy).csv"
$from = "[email protected]"
$to = "[email protected]"
$smtpHost = "smtpservername"
$Subject = "90 Days Inactive Accounts"
$body = "90 Days Inactive Accounts report"
# Get all AD User with lastLogonTimestamp less than our time and set to enable
Get-ADUser -Filter {LastLogonTimeStamp -lt $time -and enabled -eq $true} -Properties LastLogonTimeStamp | where {($_.distinguishedname -notlike "*OU=HR*") -and ($_.distinguishedname -notlike "*OU=OT*")} | 
# Output Name and lastLogonTimestamp into CSV
select-object givenname,Name,@{Name="Last Logon"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp).ToString('dd-MM-yyyy_hh:mm:ss')}} | Export-Csv c:\temp\90DaysInactive-$(Get-Date -format dd-MM-yyyy).csv -NoTypeInformation
Send-MailMessage -From $from -To $to -Subject $subject -cc $cc -SmtpServer $smtpHost -Attachments $FileName -Body $body -BodyAsHtml
Thanks for your advance help.

Similar Messages

  • How can I see in my address book all contaacts that have not been placed into groups?

    How can I see in my address book the contacts that have not been put into groups?

    The best way to do that is create a new "smart group" with the following:
    This way you can identify those without a group and drag them to one.
    Regards,
    Captfred

  • HT1848 Hi! I am new to i-phone and have a 3gs. I need to update software as itunes will not let me purchase without one. When I go to update it says that there are purchases that have not been downloaded into my library! Am totally confused! Help!!

    Hi!
    Am totally new to iphone and have a 3gs. Am trying to upodate software as in the itunes store it says that I need to to purchase. When I try to update a message says that there are purchases that hav not been down loaded to my library? As far as I know I haven't purchased anything from itunes as it would not let me until i upgraded! Totally confused would it be anything to do with purchases made on my computer through e-bay? Please help me someone as am terrified to upgrade until I know what this message means.
    Would really appreciate any help please.
    Many thanks
    p.s How do you know what operating system you are on?

    http://support.apple.com/kb/HT4972

  • List AD accounts that have not been used for months?

    Hello,
    I use oldcmp.exe to show me what computers have not been used for months and I can disable them, but I wish to do the same for users Active Directory accounts, is this possible?
    We use AD 2003
    Thanks

    sorry for slightly belated reply. I've used another version of this script that doesn't have the GUI interface on it, this will make it easier for you to run from a scheduled task.
    copy the code and make the relevant changes to the top section of the script as the comments explain. This will send and email with a link to the report generated.
    #Script designed to search AD for inactive user accounts, mark them as inactive and move them to a specific OU then disable them
    #Script can be run in the following formats
    # 1. Report only
    # 2. Report and move account
    # 3. Report, move and disable
    #Uses quest powershell tools which can be downloaded from http://www.quest.com/powershell/activeroles-server.aspx
    #Version 2.0
    #Added email functionality
    #Denis Cooper
    #Setup script Variables
    #Change the setting from True to false to alter the way the script runs (only one option can be true)
    $ReportOnly = "True" #Generates a CSV file showing all inactive user accounts
    $ReportandMove = "False" #Generates a CSV report, moves the users to a specific OU
    $ReportMoveDisable = "False" #Generates a CSV report, moves the users to specific OU, and sets the description
    #Set the period of inactivity in days
    $InactiveFor = "90"
    #Specify the OU to search for inactive users - us AD CN if searching enire AD
    $SourceOU = "OU=Users,DC=MyDomain,DC=Int"
    #Specify the destination OU to move inactive users to is using report and move or report move disable script options
    $DestinationOU = "OU=Inactive Users,DC=MyDomain,DC=Int"
    #Don't mark anyone with the the specified prefix in the description field to inactive - DND stands for Do Not Disable and is specified
    #in the users account description field for accounts which may not be used to login so will show as inactive but that you don't want to disable
    #must leave the * after the word for wildcard matching
    $DescriptionPrefix = "DND*"
    #Specify the description to set in the computer account on ReportMoveDisable option
    $Description = "Account disabled due to inactivity on $Today"
    #Specify the path to create the csv file (make sure the folder exists)
    $ReportFile = "\\server\share\InactiveUsersReport.csv"
    #Get todays date and store it in the $today variable
    $Today = Get-Date
    #Email Settings
    $SMTPServer = "smtp-server-name" #replace this with your internal smtp server
    $FromAddress = "[email protected]" #replace this with your from address
    $ToAddress = "[email protected]" #replace this with your TO address
    $CCAddress = "[email protected]" #replace this with your TO address
    $Subject = "This is your subject line" #replace this with the subject line for the email
    $MessageContent = "
    Hello,
    Please find a link to the latest report containing users that have been inactive for $inactivefor days
    $ReportFile
    Please take the appropriate action.
    Thanks you,
    IT
    #NO CHANGES BELOW THIS LINE
    Function SendEmail {
    $messageParameters = @{
    Subject = $subject
    Body = $messagecontent
    From = $fromaddress
    TO = $ToAddress
    CC = $CCAddress
    SmtpServer = $SMTPServer
    Send-MailMessage @messageParameters
    #Generates a report showing inactive users
    Function ReportOnly {
    $inactiveUsers | Export-Csv $ReportFile
    $count = $inactiveUsers.Count
    Write-Host -ForegroundColor White "$count inactive users were found and are being processed"
    SendEmail
    Invoke-Item $ReportFile
    #Generates report and moves accounts to desitnation OU
    Function ReportandMove {
    $inactiveUsers | Export-Csv $ReportFile
    $count = $inactiveUsers.Count
    Write-Host -ForegroundColor White "$count inactive users were found and are being processed"
    Invoke-Item $ReportFile
    $inactiveUsers | foreach {
    Move-QADObject $_ -NewParentContainer $DestinationOU
    #Generates report, moves accounts to destination OU, disables the account and sets the description
    Function ReportMoveDisable {
    $inactiveUsers | Export-Csv $ReportFile
    $count = $inactiveUsers.Count
    Write-Host -ForegroundColor White "$count inactive users were found and are being processed"
    Invoke-Item $ReportFile
    $inactiveUsers | foreach {
    Disable-QADUser $_
    Set-QADUser $_ -Description $Description
    Move-QADObject $_ -NewParentContainer $DestinationOU
    #Runs the script
    #Finds all inactive user accounts which are in an enabled state and store them in the variable $inactiveusers
    $inactiveUsers = Get-QADUser -SizeLimit 0 -SearchRoot $sourceOu -NotLoggedOnFor $InactiveFor -Enabled | Where-Object {$_.description -notlike $DescriptionPrefix}
    #Checks which script to run
    If (($ReportONly -eq "True") -and ($ReportandMove -eq "True" -or $ReportMoveDisable -eq "True")) {
    Write-Host -ForegroundColor RED "Only one run condition is allowed, please set only one run value to True and the others to false"
    Break
    If ($ReportONly -ne "True" -and $ReportandMove -ne "True" -and $ReportMoveDisable -ne "True") {
    Write-Host -ForegroundColor RED "No valid run condition was specified, please set only one run value to True and the others to false"
    Break
    If ($ReportONly -eq "True") {
    Write-Host -Foregroundcolor Green "Script running in report only mode."
    Write-Host -Foregroundcolor Green "Checking for accounts inactive for $inactivefor days in the OU $SourceOU"
    Write-Host -Foregroundcolor Green "The report will open automatically once complete, or you can find it here $ReportFile"
    ReportOnly
    If ($ReportandMove -eq "True") {
    Write-Host -Foregroundcolor Green "Script running in report and move mode."
    Write-Host -Foregroundcolor Green "Checking for accounts inactive for $inactivefor days in the OU $SourceOU"
    Write-Host -Foregroundcolor Green "The report will open automatically once complete, or you can find it here $ReportFile"
    Write-Host -ForegroundColor Green "Any inactive accounts will be moved to this OU $destinationOU"
    ReportAndMove
    If ($ReportMoveDisable -eq "True") {
    Write-Host -Foregroundcolor Green "Script running in report, move and disable mode."
    Write-Host -Foregroundcolor Green "Checking for accounts inactive for $inactivefor days in the OU $SourceOU"
    Write-Host -Foregroundcolor Green "The report will open automatically once complete, or you can find it here $ReportFile"
    Write-Host -ForegroundColor Green "Any inactive accounts will be moved to this OU $destinationOU and disabled and their description updated"
    ReportMoveDisable
    This link should help you create a scheduled task to run the script
    http://dmitrysotnikov.wordpress.com/2011/02/03/how-to-schedule-a-powershell-script/
    Regards,
    Denis Cooper
    MCITP EA - MCT
    Help keep the forums tidy, if this has helped please mark it as an answer
    My Blog
    LinkedIn:

  • HT1296 I already have an itunes account on my laptop but have been setup on a mac and have songs that have not been purchased from the itunes store, I cannot get the songs from my iPhone onto my itunes account on the mac. how can I do this?

    I already have an itunes account on my laptop but have been setup on a mac and have songs that have not been purchased from the itunes store, I cannot get the songs from my iPhone onto my itunes account on the mac. how can I do this?

    You copy them from your old computer or your backup copy of your old computer.
    The iphone is not a backup/storage device.

  • Question why has my balance on my itune account have totally disappeared when I have only been using it for less than a year? had still fair bit of money in it too. around $60

    Question why has my balance on my itune account have totally disappeared when I have only been using it for less than a year? had still fair bit of money in it too. around $60

    First, make sure you're logged into the iTunes Store using the account ID and password you set up, or used, when you redeemed your card/gift.  If you are, try signing out of the account and back in.
    If you're sure you are using the correct account and that you're signing in to the iTunes Store, and signing out and back in doesn't help, go to the Purchase History and review your purchases to make sure that you should indeed have a balance left. iTunes doesn't always refresh the balance it shows, so it's possible you spent the money and it just wasn't being reflected in the display. This display error can usually be corrected by logging out of the iTunes Store and then back in.
    If you confirm that you should have balance left but the iTunes Store isn't showing it correctly, send a message to the iTunes Store customer service department through the contact form you'll find by selecting the most applicable section of their Support page (select the Contact Support link and follow the instructions) and explain the problem to them.
    Good luck.

  • Whenever I try to open iPhoto, a message comes up saying that 148 photos have been found in the iPhoto Library that have not been imported. It asks me if I want to import them and I say NO but then it places them in a recovered photo folder. I keep deleti

    Whenever I try to open iPhoto, a message comes up saying that 148 photos have been found in the iPhoto Library that have not been imported. It asks me if I want to import them and I say NO but then it places them in a recovered photo folder. I keep deleting the empty recovered photo files but it just keeps asking me every time I go to open iPhoto! I'd love to just get rid of the "found" photos (I can't open them anyway!)
    How do I get rid of them so that I can just open iPhoto straight up without this?
    Linda

    Open your iPhoto Library package with the Finder.
    Click to view full size
    look for a folder titled Import or Importing and move it to the Desktop. Launch iPhoto to see if the message goes away.  If there is no message  check the contents of the Import folder to see if you want to keep any of those image files (usually they have not been imported into iPhoto). If you want to keep them then drag the folder into the open iPhoto window to import.
    OT

  • [svn] 2841: Fix bug loading untrusted applications that have not been sized .

    Revision: 2841
    Author: [email protected]
    Date: 2008-08-14 04:45:09 -0700 (Thu, 14 Aug 2008)
    Log Message:
    Fix bug loading untrusted applications that have not been sized.
    QE:YES
    Doc:
    Checkintests: YES
    Reviewer: Alex
    Bugs: SDK-16470
    SWFLoader:
    Fixed a security violation trying to access untrusted content. The problem happened in doScaleContent() when the loaded content had not been sized yet. The fall back is to check the class type of the content, but the SWFLoader did not have access to the content. The security violation was caught and the FlexLoader size is set when it shouldn't be. The problem is solved by checking access rights before accessing the content and not generating an exception.
    Ticket Links:
    http://bugs.adobe.com/jira/browse/SDK-16470
    Modified Paths:
    flex/sdk/branches/3.0.x/frameworks/projects/framework/src/mx/controls/SWFLoader.as

    Ignoring what is causing the errors for a moment, what would help is a way to get the application loader to restart from the point of error rather than going back to the beginning of the "Loading applications" step each time.
    I imagine this to be something of a big ask. Any other suggestions in a similar vein?
    Nick.

  • Query Help - PO's That Have Not Been Sent

    Is it possible to make a query for PO's that have not been sent? I tried a few things and couldn't get it to work.

    I think I understand what you mean let me try and answer that,
    Yes the order comes into SAP from our website then we have someone who then creates the PO based off the sales order. During that process the person who creates the PO then sends it via email in the messaging system to the vendor. My end game is to be able to run some type of query where we could see if that person has missed any.

  • Please Help... i lost my macbook and there are so many accounts that haven't been logged out yet. how can i block my old macbook? (block from everything)

    There are so many accounts that haven't been logged out yet. how can i block my old macbook? (block from everything like it cant be used at all again)

    It should be unnecessary to point out that leaving one's computer logged into anything that requires security is foolhardy. The reason there's a login process is so you will have the opportunity to log out and thereby secure your account. Failing to do so completely defeats the purpose and leaves you wide open to catastrophic consequences.

  • HT201210 I'm trying to update my iOS to 6.0, using iTunes (with my 4s connected via USB and WiFi is on also). I get a message that 'there are purchased items on my iPhone that have not been transferred to my iTunes library. Yet, I can't find those items!

    I'm trying to update my iOS to 6.0, using iTunes (with my 4s connected via USB and WiFi is on also). I get a message that 'there are purchased items on my iPhone that have not been transferred to my iTunes library. Yet, I can't find those items! Help!  There is not error message number just the text message. I've searched for an answer but have found nothing on "transfering items purchased to your iTunes library".

    Right click on your device icon on the left pane of iTunes and click on transfer pur....

  • There are purchased items on the iPhone "asingh's iPhone" that have not been transferred to your iTunes library. You should transfer these items to your iTunes library before updating this iPhone. Are you sure you want to continue?

    When I am trying to upgrade my iphone to IOS7.0.2 by connecting my my iphone and macbook, it shows "There are purchased items on the iPhone “asingh’s iPhone” that have not been transferred to your iTunes library. You should transfer these items to your iTunes library before updating this iPhone. Are you sure you want to continue? ".  I hit the same issue and lost a lot of apps from my iphone. Can someone help on how to resolve this issue? I can automatically upgrade my software on the iphone but how shall I resolve any future updates of "Apps"?

    I appreciate the answer, but what you describe is not entirely accurate.  First, to even see view, you have to enable the menu by clicking on the icon in the upper left.  View allows you to show the sidebar.
    Second, you will NOT see your devise listed in sidebar or anywhere else.  Instead, you have to click on "devise" from the sidebar menu, wait a minute, and then it will finally show up under "devise."   Or maybe it just takes a minute to show up whatever you do. 
    Third, right clicking on your devise will take you to a menu with "transfer my files" on it, but then iTunes will refuse to make the transfer.  Instead, it will tell you that <your apps> on your <devise> could not be transferred to iTunes "because you are not authorized for it on your computer."  Apple unhelpfully suggests going to store> authorize this computer.  There is a "store" menu item on the sidebar, but it has no "authorize this computer" sub-menu.  Instead, go to the horizontal menu at the upper left, and THERE you will find "store" and the "authorize this computer" sub-menu.  Now you can transfer your files, to who knows where.
    My iPhone 5 is my first Apple devise. So far my experience has been, to do A, which must be done right now, you must first do B.  To do B you must first do C, which is unexplained save in answers in user forums.  To do C you must first do D, which, after several hours of research and puzzle solving, can eventually be done.

  • Removing posts that have not been responded to

    hi all.
    i love the forums and am excited about the new redesign.
    another great example of why switching back to mac is working nicely for me.
    can i please ask if it is possible to multiple remove or otherwise conveniently remove posts that have not been responded to (0 responses)?
    i have a ton of these and I want to minimize the clicks and the time this will take to remove them.
    thanks.

    OK. But I'd like to get these off the unanswered posts section so they don't show up. It is sort of inconvenient.
    Is there a quickest way to do this?
    I answer my own post and click Correct Answer on the answer...?
    Thanks

  • Every time I open iPhoto a window opens telling me that there are 3 photos that have not been imported. Recovered folders are opened with no photos and I cannot find which photos have not been imported. Help please!

    Every time I open iPhoto a window opens telling me that there are 3 photos that have not been imported. This happens twice. When I answer yes then nothing happens and if I answer no then a recovered folder is opened with no photos in it. These recoverable folders keep opening with no photos in them. I cannot find which photos have not been imported. Can anyone assist please?

    Go to your Pictures Folder and find the iPhoto Library there. Right (or Control-) Click on the icon and select 'Show Package Contents'. A finder window will open with the Library exposed.
    Look there for a Folder called 'Import' or 'Importing'.
    Drag it to the Desktop. *Make no other changes*.
    Start iPhoto. Does that help?
    If it does then look inside that folder on your desktop. Does it contain anything you want? If not you can trash the folder.

  • How do I find all the purchased items on my iPhone? When I try to update the iPhone iOS while connected to my MacBook it says there are purchased items on the phone that have not been transferred to my iTunes library and that I should transfer them.

    How do I find all the purchased items on my iPhone? When I try to update the iPhone iOS while connected to my MacBook it says there are purchased items on the phone that have not been transferred to my iTunes library and that I should transfer them before updating.

    Thanks. This seems to have worked easily.

Maybe you are looking for

  • Hp wireless all-in-one 5520 printer stopped connecting to the internet

    my wireless hp photosmart 5520 all-in-one printer will print from my wireless laptop, but it no longer connects to the internet. I cannot download apps. i ran a wireless network test and everything is good, except for the internet (not connected) wha

  • HP Color Laserjet 8500dn Printer Supplies

    Hello, Does anyone know if HP has stopped production on the Color Laserjet 8500 supplies such as: C4149A Black Toner C4150A Cyan Toner C4151A Magenta Toner C4152A Yellow Toner C5153A Image Drum Kit C5154A Transfer Kit C4155A Fuser Kit I have searched

  • How to maintain UOm in more than one language?

    Hi experts, Can anyone guide me how to maintain a UOM in other log-in languages. I have maintained PCE= Piece in English, it appears also to be in the French and German language automatically. But when I raise a shopping cart in any other languages,

  • Harman-kardon speakers

    Is it possible to use my harman-kardon speakers with my new HP monitor?  The speakers do not have USB connectors,and, i cannot plug them into the tower.  (They plugged into previous monitor.)  Is there some sort of adapter I can purchase?  Simplistic

  • Compressing file without loosing size or quality

    Illustrator CS3 - AI 13.0 - need to compress a file or it's components to under 500K from a current 2.53 MB size and maintain full page viewing capabilities and quality. Will be placed on a real estate web site for broker/realtor viewing. Using a Del