From 14e748ad1eb296de9d5da33671f8c20f82a26ca6 Mon Sep 17 00:00:00 2001 From: Frank Bischof Date: Wed, 23 Nov 2022 11:16:59 +0100 Subject: [PATCH] Alias where to where-object --- lock_inactive_accounts.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lock_inactive_accounts.ps1 b/lock_inactive_accounts.ps1 index 6b17d8e..e666059 100644 --- a/lock_inactive_accounts.ps1 +++ b/lock_inactive_accounts.ps1 @@ -3,7 +3,7 @@ ## Disable account if not used for X days $90Days = (get-date).adddays(-90) -$users = Get-ADUser -properties * -filter {((lastlogondate -notlike "*" -OR lastlogondate -le $90Days) -AND (enabled -eq $True))} | where CanonicalName -Like "*NamedAccounts*" | select-object SAMaccountname +$users = Get-ADUser -properties * -filter {((lastlogondate -notlike "*" -OR lastlogondate -le $90Days) -AND (enabled -eq $True))} | Where-Object CanonicalName -Like "*NamedAccounts*" | select-object SAMaccountname foreach ($user in $users) { write-host Disabling account $user.SAMaccountname @@ -13,7 +13,7 @@ foreach ($user in $users) ## Delete account if disabled for X months. $6Months = (get-date).AddMonths(-6) -$users = Get-ADUser -properties * -filter {((modifyTimeStamp -le $6Months) -AND (enabled -eq $False))} | where CanonicalName -Like "*NamedAccounts*" | select-object SAMaccountname +$users = Get-ADUser -properties * -filter {((modifyTimeStamp -le $6Months) -AND (enabled -eq $False))} | Where-Object CanonicalName -Like "*NamedAccounts*" | select-object SAMaccountname foreach ($user in $users) { write-host Deleting account $user.SAMaccountname