Joseph Daly
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.
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
Cheers, D
ASKER
@{L="Count";E={(get-qaduse
Can you explain what is going on here? Trying to learn powershell better as well as solving this problem.