Recommended Posts

So, I'm running into an interesting problem with the Get-ADComputer cmdlet. What I am trying to do is get a list of Computers objects that haven't logged in in more than 90 days. That part works fine, however when I attempt to filter out Cluster objects I'm running into an issue.

 

There are 219 total objects in the OU that I'm searching. Here is my basic command:

$Servers = Get-ADComputer -LDAPFilter '(name=*)' -SearchBase 'OU=Servers,DC=my,DC=domain,DC=com' -Properties * | Where-Object { $_.servicePrincipalNames -notlike '*MSClusterVirtualServer*' } | Where-Object { $_.LastLogonDate -lt (Get-Date).AddDays(-90) } | Sort-Object CN

 

The first Where-Object comparison does not evaluate correctly and all 219 objects are returned, however, if I try using -like it correctly identifies the Cluster objects and only 17 objects are returned. Does anyone know why -like evaluates correctly and -notlike doesn't?

wow 219...man i wish...

 

Try this...

import-module activedirectory 
$DaysInactive = 120 
$time = (Get-Date).Adddays(-($DaysInactive))
$DestinationOU = "OU=Disabled Computers,DC=mydomain,DC=com"

# Get all AD computers with lastLogonTimestamp less than inactive days
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 C:\script\OLD_Computer.csv -notypeinformation |

Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -Properties LastLogonTimeStamp |

Disable-ADAccount 


Get-ADComputer -Filter { (name -like "*") -and (enabled -eq $False)} -properties * | Move-ADObject -TargetPath $DestinationOU

Cluster objects should still check in to AD as they should be online and running, they should not show up in the 90 day filter...it is when they are offline completely for 90+ days there will be an issue, but more than what you think.  Look up the term "Microsoft Tombstoned" and see what is required to revive a tombstoned computer....this will not happen if a computer is on the network and communicating even if you never log into it.

 

Change your daysinactive to what you want, change the destinationOU to your own OU

  On 19/12/2017 at 15:45, sc302 said:

 Cluster objects should still check in to AD as they should be online and running, they should not show up in 90 days...it is when they are offline completely for 90+ days there will be an issue, but more than what you think.

Expand  
1
1

According to Technet, a cluster object only sets the LastLogonDate attribute when the Cluster comes online, therefore, if the cluster has been online for longer than 90 days the LastLogonDate attribute would reflect that. 

 

This was my source for that information: https://blogs.technet.microsoft.com/askds/2011/08/23/cluster-and-stale-computer-accounts/

 

I will check out Tombstoning as well, thanks for the suggestion. What I'm trying to do is just get a list of stale computer objects, not necessarily tombstoned ones. I was able to get the information I needed with the following code:

$Servers = Get-ADComputer -LDAPFilter '(name=*)' -SearchBase 'OU=Servers,DC=my,DC=domain,DC=com' -Properties * | Where-Object { $_.LastLogonDate -lt (Get-Date).AddDays(-90) }
$Clusters = Get-ADComputer -LDAPFilter '(name=*)' -SearchBase 'OU=Servers,DC=my,DC=domain,DC=com' -Properties * | Where-Object { $_.servicePrincipalNames -like 'MSClusterVirtualServer' }
$Array = @()

ForEach ($Server in $Servers) {
    If ($Clusters.Name -notcontains $Server.Name) {
        $Array += $Server
    }
}

 

Edited by Stokkolm

https://technet.microsoft.com/en-us/library/2007.09.tombstones.aspx

 

Recovering a tombstoned object is a bit of a process, however it is important to know.    It is also important to know that tombstoning occurs at 180 days after it has not communicated with AD.  AD forces a password change between all devices and itself periodically (every 30 days).  I would venture to believe that clusters would fall into that as well.  You could check up on that in a week or so to see if the time stamp changed (it should).

 

Instead of lastlogontime, you could use pwdLastSet  as stated here which would more accurately identify computers/clusters that are no longer online.

 

https://blogs.msdn.microsoft.com/clustering/2011/08/17/identifying-stale-cluster-computer-objects/

 

This topic is now closed to further replies.
  • Posts

    • AnyDesk 9.5.7 by Razvan Serea AnyDesk is a fast remote desktop system and enables users to access their data, images, videos and applications from anywhere and at any time, and also to share it with others. AnyDesk is the first remote desktop software that doesn't require you to think about what you can do. CAD, video editing or simply working comfortably with an office suite for hours are just a few examples. AnyDesk is designed for modern multi-core CPUs. Most of AnyDesk's image processing is done con­currently. This way, AnyDesk can utilize up to 90% of modern CPUs. AnyDesk works across multiple platforms and operating systems: Windows, Linux, Free BSD, Mac OS, iOS and Android. Just five megabytes - downloaded in a glimpse, sent via email, or fired up from your USB drive, AnyDesk will turn any desktop into your desktop in se­conds. No administrative privileges or installation needed. AnyDesk 9.5.7 changelog: Fixed Bugs Fixed deadlock when updating chat server Fixed crashes caused by exceptions in internal communication layer Fixed crash when opening new monitor in Session in a new window Fixed crash on shutdown Fixed bug that allowed naming Permission Profiles identical to predefined Profiles Fixed bug that could cause licensed remote clients to show up as free Fixed visual bug that caused Set-Password button to show up when Unattended Access was disabled Fixed bug that lead to selecting the wrong initial resolution for webcams New Features Added command line option --record-screen to start a Screen Recording Other Changes Improved visual consistency in some list views Download: AnyDesk 9.5.7 | macOS ~14.0 MB (Free for private use, paid upgrade available) Links: AnyDesk Home Page | Other platforms | Release History | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • WUT?! Tell us you've never built desktop software without telling us you've never built desktop software... The chromium rendering engine is the content-rendering engine for "chromium-based browsers," but that does NOT mean there's a full-on UI underneath that is somehow bloating these products. The bloat is from the additional UI components that the browser vendor (Vivaldi) is adding atop the base package. Most chromium browsers customize the default skin/theme of the overall package so there's absolutely zero added overhead; it's really just a different CSS-based theme pack. Vivaldi, however, adds more than just a different skin; they add built-in extensions (that are managed by other built-in extensions), add other customization modules, and all kinds of other bloat -- and these add-ons are EXACTLY where the resource-hogging stems from. The mere fact it's a chromium-based browser has no impact on the matter. Lastly, power users literally DO notice resource-intensive applications -- they'll even be familiar with tools and widgets that expose those measurements the way only a power-user would! General consumers, however, would simply remark that their rig is sluggish and probably outdated and blindly upgrade to whatever the salespeople are hawking at the local computer store. General consumers wouldn't even upgrade their existing computer cuz they wouldn't know how to!
    • Nope, they just removed the game from sales.
    • Welcome to Neowin! Please enjoy your stay!
    • WTF is this title? It reads like I'm having a stroke.
  • Recent Achievements

    • First Post
      Celilo earned a badge
      First Post
    • One Year In
      K.I.S.S. earned a badge
      One Year In
    • Week One Done
      solidox earned a badge
      Week One Done
    • Dedicated
      solidox earned a badge
      Dedicated
    • Week One Done
      Devesh Beri earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      445
    2. 2
      ATLien_0
      168
    3. 3
      +FloatingFatMan
      152
    4. 4
      Nick H.
      66
    5. 5
      macoman
      63
  • Tell a friend

    Love Neowin? Tell a friend!