Wednesday, May 13, 2015

Long time without, but quick update- sometimes, the old tools are still the best

I was trying to get a list of users currently logged in to machines on a remote network tonight, when it hit me that I could do it pretty easily with powershell- some quick google searches showed up telling me that, yes, in fact I could. Along with these hideously long, convoluted scripts.

Now don't get me wrong- I'm all for error checking out the yang, but do I really need 400 lines when one will do? And do I really need a specific module for getting my answer?

Turns out, no. I just needed the built in tools in windows. Specifically the ad extensions for powershell, and qwinsta. What's that, you've never heard of qwinsta? That's ok, I only learned of it back in the days of NT4, along with it's sibling rwinsta. Why such odd names? Well, in those days we were pretty limited (remember, 8.3 for most everything microsoft related), so qwinsta (or Query Windows Station) and rwinsta (Reset Windows Station) are used to do just that.

Now on to the meat-

Quick check of the network as follows:

Import-Module ActiveDirectory -PSSession $s
$complist = Get-ADComputer -filter *
foreach ( $comp in $complist) { echo $ ; qwinsta -Server $ }

And there ya go, every computer AD knows about gets scanned.