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


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

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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?
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.
siber1Author Commented:
fantastic, thanks much becraig, exactly what I was looking for.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.