• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 78
  • Last Modified:

how can i add logic to this script to exit if results are zero?

hello,

I'm working on a script, but need it to exit of the results are empty. the script look for users that are a member of a security group, and checks if their pwd is expiring in the next 60 days, id like to add logic so that if the results of the query below are empty, for the script to exit.  thx in advance.

Get-QADUser -MemberOf ABCsecuritygroup -PasswordNotChangedFor 120 | Where PasswordNeverExpires -eq $False | Select-Object email -Unique | Export-Csv $Logfile -NoTypeInformation

Open in new window

0
siber1
Asked:
siber1
  • 2
  • 2
1 Solution
 
becraigCommented:
You could assign a variable to the query and do an if / else statement something like below:

No tested but I am expecting you just want the concept so you can learn while figuring it out ?

$resset = Get-QADUser -MemberOf ABCsecuritygroup -PasswordNotChangedFor 120 | Where PasswordNeverExpires -eq $False

if ($resset.count -gt 0) 
{
#do some action
}
else {exit}

Open in new window

0
 
siber1Author Commented:
thanks becraig. works perfectly.
one last question, the action I'm running after your check is:

Get-QADUser -MemberOf ABCsecuritygroup -PasswordNotChangedFor 120 | Where PasswordNeverExpires -e 

Open in new window


how can I select the last time the password was changed for the users in that group so I can export out to a file?
0
 
becraigCommented:
Get-QADUser -MemberOf ABCsecuritygroup -PasswordNotChangedFor 120 | Where PasswordNeverExpires -e |ft  Displayname,PasswordLastSet

Open in new window


Something like the above, I am in an airport and cannot test.
0
 
siber1Author Commented:
fantastic, thanks much becraig, exactly what I was looking for.

cheers!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now