Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Quest Powershell logon script count command

Avatar of Joseph Daly
Joseph DalyFlag for United States of America asked on
Active DirectoryScripting LanguagesPowershell
5 Comments1 Solution1661 ViewsLast Modified:
We recently aquired another company and as part of the domain migration we also migrated their user logon scripts to our netlogon folder. They operated a lot messier than I like and have loads of logon scripts. What I would like to do is figure out which logon scripts are not being used by anyone and delete them.

Using the quest cmdlets I have figured out a way to count the number of users assigned each batch file.

get-qaduser -logonscript scriptname.bat | measure-object | select-object count

This does work and returns the number of users with the login script. However as I said there are lots of scripts in the folder. I have a list of them as a CSV and I would like a way to script this to return something similar to below.

logonscript name        number of users

So Im still pretty new at powershell but what I was thinking was something along the lines of this

import-csv c:\file.csv | foreach {get-qaduser -logonscript $_.Name}

This appears to work as I can see it echoing the user names from each logonscript and then pausing as it moved to the next one. A few problems though

1. When this command is running there is no way to differentiate when one group is finished and the next started it just outputs a long list of names
2. I dont really need the names as much as the count of users assigned each logonscript. I know I can use the measure-object command to get this but just cant seem to get it right.

Ideally I would like an output file similar to below.
Logonscript              Count
file1.bat                 3
file2.bat                 29
file3.bat                 65
Avatar of dicconb
dicconbFlag of United Kingdom of Great Britain and Northern Ireland image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answers