PDQ.com mobilePDQ.com desktop
Support

User Profile Size

Jordan HammondJordan Hammond
·

PDQ PowerShell Scanner is here, and the answer to the question “Can I pull this data” is most likely yes! Instead of just telling you it is awesome, we figured it would be best to show you some ideas. We have these up in GitHub; I can’t talk about how much I like these enough. Hopefully, they will give you some ideas on other information you can gather. If it does, please submit a pull request following the guidelines. We would love to build this out to something epic. In this blog, we will go over tracking user profile size.

User Profile Size

This one is a quick script. It uses Get-Childitem and Measure-Object commands to get your results. First, grab all directories in the “C:\Users” directory.

$UserFolders = Get-ChildItem -Path "C:\Users" -Force -Directory

Each of those goes into a foreach loop where you run a recursive Get-Childitem that you pipe into Measure-Object. We are forcing the data we get from this to be an integer because that format makes reports built to show up correctly.

[UInt64]$FolderSize = ( Get-Childitem -Path $Folder.FullName -Force -Recurse | Measure-Object -Property "Length" -Sum ).Sum

And finally, you put your results into a pscustom object so you can format your output into a readable format. This will ensure that the results that get put into Inventory look exactly how you would want.

Putting It all Together

Let’s take a look at the complete script. We highly recommend that if you are going to use it you get it from GIT and follow the steps in there so your scanner will remain up to date if changes are made.

$ErrorActionPreference = "SilentlyContinue"

$UserFolders = Get-ChildItem -Path "C:\Users" -Force -Directory

ForEach ( $Folder in $UserFolders ) {

    [UInt64]$FolderSize = ( Get-Childitem -Path $Folder.FullName -Force -Recurse | Measure-Object -Property "Length" -Sum ).Sum
    
    [PSCustomObject]@{
        FolderName    = $Folder.BaseName
        FolderPath    = $Folder.FullName
        Size          = $FolderSize
    }

}

Conclusion

This is a short script, and it highlights that it does not take much to pull in some real value. Hopefully, this will get your creative juices going and help you get started on building your perfect scanner. If you have been wondering how you are going to track specific data, well, now you know. Get started already!

This blog post is part of our PowerShell Scanner series.

Ready to put the PowerShell scanner through its paces?

Take our 14-day Free Trial. Feel the power of the PowerShell scanner.
Start a Trial

Don't miss the next post!

Using PowerShell to Install Printers

When installing printers, we will need to do the four things; Add Driver to the Store, Install the Driver, Create Printer Port, and Install the Printer