Just having an issue getting the password last set attribute in a list view.
That column is empty
#######################
## Find Locked Users ##
#######################
function Invoke-FLU{
$list1.visible = $false
$list2.visible = $true
$lbl2.visible = $false
HideUnusedItems
$columnnames = "Name","Expires","Password last set"
$list2.Columns[0].text = "Name"
$list2.Columns[0].width = 140
$list2.Columns[1].text = "Expires"
$list2.Columns[1].width = 70
$list2.Columns[2].text = "Password last set"
$list2.Columns[2].width = 380
$List2.items.Clear()
$lusers = Get-QADUser -searchroot "OU=x,dc=x,dc=x" -locked -IncludedProperties PasswordLastSet
$columnproperties = "displayName","AccountExpires","PasswordLastSet"
foreach($luser in $lusers){
$item = new-object System.Windows.Forms.ListViewItem([string]$luser.displayName)
if ($luser.accountExpires -ne $null){
$item.SubItems.Add(($luser.accountExpires | Get-Date -format "dd/MM/yyyy"))
}
else{
$item.forecolor = "Red"
$item.SubItems.Add(("No Expiry"))
}
$item.SubItems.Add($luser.PasswordLastSet)
$item.Tag = $luser
$list2.Items.Add($item) > $null
}
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic")
$yesno = [Microsoft.VisualBasic.Interaction]::MsgBox("Do you wish to unlock a domain account?",'YesNoCancel,Question', "Account Unlock")
if ($yesno -eq 6) {$btn15.Visible = $true}
elseif ($yesno -eq 7) {FormUnlock}
$stBar1.text = "Locked domain accounts on " + $userdomain + " (" + $lusers.count + ")"
if(test-path $lfile){(get-date -uformat "%Y-%m-%d-%H:%M") + "," + $user + "," + $userdomain + "," + "Locked accounts," | out-file -filepath $lfile -append}
} # End function Invoke-FLU
Thanks
David
First off I’d suggest testing that you are actually getting data back. Your syntax look right but just to be sure test
Get-QADUser -searchroot “OU=x,dc=x,dc=x” -locked -IncludedProperties PasswordLastSet | ft displayname, accountexpires, PasswordLastSet
Assuming you get data back my other suggestion would be to cast the date in PasswordLastSet to a string and see if that shows in your list
Thats great, thanks for you help. Must have been looking at it too long!
$item.SubItems.Add([string]$luser.PasswordLastSet)
This is one of those things that you remember because you’ve tripped over it before. No prizes for guessing how I found out about it…
Will do.
Now having issues with a 3rd column, description heading and data is all blank.
Also Get-QADUser -searchroot “OU=x,dc=x,dc=x” -locked -IncludedProperties PasswordLastSet | ft displayname, accountexpires, PasswordLastSet formats the date in UK dd/mm/yyyy, but below it comes out in US mm/dd/yyyy and if i try to format it, if the date is above 12 its blank.
Any ideas?
#######################
## Find Locked Users ##
#######################
function Invoke-FLU{
$list1.visible = $false
$list2.visible = $true
$lbl2.visible = $false
HideUnusedItems
$columnnames = "Name","Expires","PW last set","Description"
$list2.Columns[0].text = "Name"
$list2.Columns[0].width = 140
$list2.Columns[1].text = "Expires"
$list2.Columns[1].width = 70
$list2.Columns[2].text = "Password last set"
$list2.Columns[2].width = 120
$list2.Columns[3].text = "Description"
$list2.Columns[3].width = 260
$List2.items.Clear()
$lusers = Get-QADUser -searchroot "OU=x,dc=x,dc=x" -locked -IncludedProperties PasswordLastSet
$columnproperties = "displayName","AccountExpires","PasswordLastSet","description"
foreach($luser in $lusers){
$item = new-object System.Windows.Forms.ListViewItem([string]$luser.displayName)
if ($luser.accountExpires -ne $null){
$item.SubItems.Add(($luser.accountExpires | Get-Date -format "dd/MM/yyyy"))
}
else{
$item.forecolor = "Red"
$item.SubItems.Add(("No Expiry"))
}
if ([string]$luser.PasswordLastSet){# -ne $null){
#$item.SubItems.Add([string]$luser.PasswordLastSet)# | Get-Date -format "dd/MM/yyyy HH:mm:ss"))
$item.SubItems.Add(([string]$luser.PasswordLastSet | Get-Date -format "%d/%m/%Y %H:%M"))
}
else{
$item.forecolor = "Red"
$item.SubItems.Add(("Password not set"))
}
$item.SubItems.Add([string]$luser.description)
$item.Tag = $luser
$list2.Items.Add($item) > $null
}
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic")
$yesno = [Microsoft.VisualBasic.Interaction]::MsgBox("Do you wish to unlock a domain account?",'YesNoCancel,Question', "Account Unlock")
if ($yesno -eq 6) {$btn15.Visible = $true}
elseif ($yesno -eq 7) {FormUnlock}
$stBar1.text = "Locked domain accounts on " + $userdomain + " (" + $lusers.count + ")"
if(test-path $lfile){(get-date -uformat "%Y-%m-%d-%H:%M") + "," + $user + "," + $userdomain + "," + "Locked accounts," | out-file -filepath $lfile -append}
} # End function Invoke-FLU
Managed to resolve the column issue. Still having issues with the date formatting on passwordlastset
All sorted. Ta
$item.SubItems.Add(($luser.PasswordLastSet | Get-Date -format “dd/MM/yyyy HH:mm:ss”))