I have a script that will pull all the computer names off our network that have not logged in for over 90 days but I cannot figure out how to set the script to then dump the computer accounts into a designated OU so I can just then delete them all at once. Any help would be awesome and thank you.
Matt Thompson
Scripting Need
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- SAPIEN Support Forums
- Posts: 945
- Last visit: Thu Oct 22, 2015 1:10 pm
Scripting Need
This is an automated post. A real person will respond soon.
Thank you for posting, mdthompson.
Here are some hints to help you get an accurate and complete answer to your question.
Ask in the best forum:
Anticipate follow-up questions!
Did you remember to include the following?
*** Make sure you do not post any licensing information ***
Thank you for posting, mdthompson.
Here are some hints to help you get an accurate and complete answer to your question.
Ask in the best forum:
- - Scripting question? For questions about Windows PowerShell or other scripting languages, use Scripting Answers.
- Software question? For questions about PowerShell Studio, PrimalScript, or other SAPIEN products, use Product Support Forums for Registered Customers.
- Trial question? For questions about trial versions of any SAPIEN product, use Trial Software Questions.
Anticipate follow-up questions!
Did you remember to include the following?
- 1. Product, version and build
2. 32 or 64 bit product
3. Operating system, e.g. Windows 7 64 bit.
4. Attach a screenshot, if applicable
5. Attach logs, crash reports, etc., in a ZIP file
*** Make sure you do not post any licensing information ***
Re: Scripting Need
What you are asking is very unclear. What does "dump" mean. Are you trying to move the objects? Use Move-AdObject.
You do not have to move an object to delete it. Just delete it. In 2008R2 and later it will remember its home incase you want to undelete it. If you move it, it will be harder to restore.
You do not have to move an object to delete it. Just delete it. In 2008R2 and later it will remember its home incase you want to undelete it. If you move it, it will be harder to restore.
- mdthompson
- Posts: 4
- Last visit: Fri Dec 05, 2014 7:09 am
Re: Scripting Need
This is the current script that I have been using.
# Gets time stamps for all computers in the domain that have NOT logged in since after specified date
#import-module activedirectory
$domain = “Domain name”
$DaysInactive = 90
$time = (Get-Date).Adddays(-($DaysInactive))
# Get all AD computers with lastLogonTimestamp less than our time
Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -Properties LastLogonTimeStamp |
# Output hostname and lastLogonTimestamp into CSV
select-object Name,@{Name=”Stamp”; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}} | export-csv OLD_Compu
# Gets time stamps for all computers in the domain that have NOT logged in since after specified date
#import-module activedirectory
$domain = “Domain name”
$DaysInactive = 90
$time = (Get-Date).Adddays(-($DaysInactive))
# Get all AD computers with lastLogonTimestamp less than our time
Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -Properties LastLogonTimeStamp |
# Output hostname and lastLogonTimestamp into CSV
select-object Name,@{Name=”Stamp”; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}} | export-csv OLD_Compu
- mdthompson
- Posts: 4
- Last visit: Fri Dec 05, 2014 7:09 am
Re: Scripting Need
Sorry if I was not clear. I am wanting to move the objects that it finds that have not logged onto the network in over 90 days to an OU for deleting. I would like to view what it found before it gets deleted.
Thanks, Matt
Thanks, Matt
Re: Scripting Need
To view what a CmdLet finds you can use the -WhatIf to see what would happen.
YOu dcan also jyust get sale computer with the stale computer getter built into WIndows.
Search-ADAccount -AccountInactive -TimeSpan 90 -ComputersOnly
It gets 90 days old computers.
YOu dcan also jyust get sale computer with the stale computer getter built into WIndows.
Search-ADAccount -AccountInactive -TimeSpan 90 -ComputersOnly
It gets 90 days old computers.
- mdthompson
- Posts: 4
- Last visit: Fri Dec 05, 2014 7:09 am