Any powershell bods here?

Soldato
Joined
18 Oct 2002
Posts
6,372
Location
Bedfordshire
Hi...need a bit of help extracting some info from our AD with QADUser.

I want to compile a list of users which haven't logged on for 60 days which I have found a script for and it works perfectly...

$now=get-date
$daysSinceLastLogon=60

Get-QADUser -sizeLimit 0 | where {
$_.lastlogontimestamp -and
(($now-$_.lastlogontimestamp).days -gt $daysSinceLastLogon)
} | Select-Object Name,sAMAccountName,LastLogonTimeStamp, | export-csv test.csv

My problem is I want to filter out any disabled users with the UserAccountControl attribute, this should be quite an easy thing to do but my powershell is very poor and I am unsure of the syntax?

Many thanks
 
here is my VB script that does pretty much that

Code:
On Error Resume Next
sEnterDCs = "SERVER"
sObjects = Split(sEnterDCs, ",")
Set oDomain = GetObject("WinNT://" & sObjects(0))
oDomain.Filter = Array("User")
WScript.Echo "Showing last login times of accounts from: " & oDomain.Name & vbNewLine
For Each oDomainItem In oDomain
  sUsrLogin = oDomainItem.LastLogin

'WScript.Echo sUsrLogin
  If UBound(sObjects) >= 1 Then
    For ii = 1 To UBound(sObjects)
      Set oUsr = GetObject("WinNT://" & sObjects(ii) & "/" & oDomainItem.Name & ",user")
      If oUsr.LastLogin > sUsrLogin AND oDomainItem.accountdisabled = False Then sUsrLogin = oUsr.LastLogin
    Next
  End If 
  WScript.Echo "Username=" & Chr(34) & oDomainItem.Name & Chr(34) & " Time=" & Chr(34) & FormatDateTime(sUsrLogin) & Chr(34) & " Disabled=" & UCase(oDomainItem.accountdisabled)
Next

You'll need to use cscript to run it
 
Last edited:
Thank you howler, I have the information I need :)

I think with QADUser I could have used -disabled to get the disabled accounts but I really need to get on a powershell course/book and get up to speed.

Thanks again
 
Back
Top Bottom