Home > Active Directory, PowerShell > Find Current Workstations in PowerShell

Find Current Workstations in PowerShell

Recently while performing an Active Directory migration for a customer I needed to generate a list of workstations that were currently in use in the environment. Since the customer was extremely busy wrapped up in numerous other projects and I was in a time crunch, I decided to see what PowerShell could do for me. Some of the variables I needed for my list were:

  • Computer is running a client operating system
  • Computer account is enabled
  • Computer had been logged on in the past 3 months

Using those variables, I generated a nice command to find, sort, and output the information in an Excel file so the project could continue to move on at a decent pace without delay. The command I use to achieve this was:

Get-ADComputer -Properties * -Filter * | where {$_.OperatingSystem -notlike “*server*” -AND $_.lastlogondate -gt (get-date).addmonths(-3) -AND $_.enabled -eq “True”} | select -Property Name,OperatingSystem,Enabled,LastLogonDate | sort-object LastLogonDate -descending | Export-Csv c:\Lists\Workstations.csv -NoTypeInformation

Enjoy

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: