Link to home
Start Free TrialLog in
Avatar of Joseph Daly
Joseph DalyFlag for United States of America

asked on

Quest Powershell logon script count command

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dicconb
dicconb
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Joseph Daly

ASKER

I am not at work until tomorrow so cant really test. I kind of lose what your doing here

@{L="Count";E={(get-qaduser -logonscript $_.Name | measure-object).count}} |

Can you explain what is going on here? Trying to learn powershell better as well as solving this problem.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Chris, I couldn't have explained it better myself.

xxdcmast, if you want to find out more about calculated properties, I can recommend this guide:
http://www.microsoft.com/technet/scriptcenter/resources/pstips/apr08/pstip0425.mspx

Let us know if you have any more questions, and have fun learning more about Powershell.

Cheers,

D
Thanks for the quick accept!

Cheers, D