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

    • I am still running Windows Vista. It is my favorite release of Windows.
    • True... they used the same core, but 7 worked out of the box. Vista made Me a superhero in comparison. See.. apps may have had issues running with Me because the changes were trash compared to 98SE. But I only installed Me one time and it ran, crashed.. .ran, maybe crashed some more. I made a living off of having customers reinstall Vista because it became unstable fast. Some may call 7, Vista SP3... but the final product doesn't compare to the original Vista core when they launched it. Even today, you're going to hear some that say they're still running 7, or will always have 7. Not Vista.
    • Oh man! I can't wait! 😁
    • slowness that result in unproductive, when something was easy fast one click now its basically 2 or 3 clicks and more mouse movement not the end of the world sure but forcing changes for the sake of it for no good reason its one reason why people dont like 11.
    • WhatsApp for Android expands chat themes with 18 new colors by Paul Hill The WhatsApp Beta for Android has just been updated to version 2.25.19.2 (via WABetaInfo) bringing with it 18 new color options, expanding the selection from 20 to 38 colors. This update brings the Android app up to parity with the iOS version, which got this beta update at the start of the month. The expansion of colors will give users greater personalization options for their WhatsApp chats. You can pick the new colors individually per chat or from the settings for every chat, complementing the existing support for various custom backgrounds. How the new chat themes work To set the new colors for individual chats, just open the chat you want to theme, press the three dot menu in the top right and go to themes and change the chat color. To change the theme color across the whole of the app, just go to settings and then select chats and change the chat theme. The new colors are compatible with both light and dark modes and affect the message bubbles. Unlike Messenger where theme changes can be seen by your contact, theme changes in WhatsApp are only visible to the user who applies it. User reception and future outlook Most people running WhatsApp are using the stable version, so you won’t see these new theme colors yet, we will have to wait a bit longer for that. Even if you’re on the beta, the feature may not be available yet as it’s being rolled out. While not a massive change, lots of people like to theme their WhatsApp messages so this change will be welcomed by those that do that. The messaging app scene is very competitive, so this will help Meta retain users on WhatsApp by boosting satisfaction. If you have had a chance to try out the new themes, let us know in the comments what you think!
  • Recent Achievements

    • Explorer
      Legend20 went up a rank
      Explorer
    • One Month Later
      jezzzy earned a badge
      One Month Later
    • First Post
      CSpera earned a badge
      First Post
    • One Month Later
      MIR JOHNNY BLAZE earned a badge
      One Month Later
    • Apprentice
      Wireless wookie went up a rank
      Apprentice
  • Popular Contributors

    1. 1
      +primortal
      617
    2. 2
      ATLien_0
      278
    3. 3
      +FloatingFatMan
      179
    4. 4
      Michael Scrip
      150
    5. 5
      Steven P.
      115
  • Tell a friend

    Love Neowin? Tell a friend!