Enumerating Licensed Sharepoint Usage in Powershell
Counting licensed sharepoint users in a sharepoint farm has been a tricky business, due to the way Sharepoint does not delete users from its user list (this is by design). You probably don't want to be removing deleted users from your farm either, as it will change the document audit trail.
This means you need to
1. get a list of users from your sharepoint farm
2. cross-check this list of users against active users in your active directory
It gets even trickier when you need to count licenses in a multi-organization, multi-domain environment in an Active Directory forest.
Powershell to the rescue! Listed below is a simple script that I wrote up to do the following:
1. get all sharepoint applications in the farm
2. get all users in each application
3. cross-check each user against an Active Directory Global Catalog, and output the list of active users, department and company accompanying, to 1 CSV file, and the list of deleted users to another CSV file. Just copy the script to a server in your sharepoint farm and run under Sharepoint Management Shell.
From there it becomes a matter of removing duplicates and counting licenses consumed - something I prefer to do in Excel. Whereas this can also be done in powershell, I'll leave it for another day.
Cheers!
param ($logfile='.\active.csv', $logfile2='.\inactive.csv', $gc='globalcatalog:3268') import-module activedirectory New-Item $logfile -type file -force New-Item $logfile2 -type file -force $webs=Get-SPWebApplication ForEach ($web in $webs) { $url = $web.url $users=Get-SPUser -web $url -Limit ALL ForEach ($user in $users) { $name = $user.name $search = Get-ADUser -Properties Name,Company,Department -Server $gc -LDAPFilter "(name=$name)" $company= $search.company $department = $search.department IF ($search) {"$name,$company,$department" | Add-Content $logfile} ELSE {"$name" | Add-Content $logfile2} } }