Scripting Need

Ask your PowerShell-related questions, including questions on cmdlet development!
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.
This topic is 9 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
mdthompson
Posts: 4
Last visit: Fri Dec 05, 2014 7:09 am

Scripting Need

Post by mdthompson »

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
User avatar
SAPIEN Support Forums
Posts: 945
Last visit: Thu Oct 22, 2015 1:10 pm

Scripting Need

Post by SAPIEN Support Forums »

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: If you asked in the wrong forum, just copy your question to the right forum.

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
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Scripting Need

Post by jvierra »

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.
User avatar
mdthompson
Posts: 4
Last visit: Fri Dec 05, 2014 7:09 am

Re: Scripting Need

Post by mdthompson »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Scripting Need

Post by jvierra »

What is the question? Are you asking how to delete a computer? You have to be clear.
User avatar
mdthompson
Posts: 4
Last visit: Fri Dec 05, 2014 7:09 am

Re: Scripting Need

Post by mdthompson »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Scripting Need

Post by jvierra »

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.
User avatar
mdthompson
Posts: 4
Last visit: Fri Dec 05, 2014 7:09 am

Re: Scripting Need

Post by mdthompson »

jvierra and everyone else thank you for your help.
This topic is 9 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked